============================cricket program=============================
#include<iostream>
using namespace std;
class cricket
{
string playercode;
string playerfname;
string playerlname;
int totalmatches;
int totalrun;
int notout;
static int avgtotal;
static int avgruns;
static float avgall;
float avg;
public:
cricket();
void display();
void average();
void averageall();
void displayavg();
};
int cricket :: avgtotal=0;
int cricket :: avgruns=0;
float cricket :: avgall=0;
cricket :: cricket(void)
{
cout<<"enter player details \n";
cout<<"enter player code";
cin>>playercode;
cout<<"enter player first name";
cin>>playerfname;
cout<<"enter player last name";
cin>>playerlname;
cout<<"enter total matches played";
cin>>totalmatches;
cout<<"total runs of player";
cin>>totalrun;
cout<<"number of times not out";
cin>>notout;
}
void cricket :: display()
{
cout<<"\nplayers details are"<<endl;
cout<<playercode<<endl;
cout<<playerfname<<endl;
cout<<playerlname<<endl;
cout<<totalmatches<<endl;
cout<<totalrun<<endl;
cout<<notout<<endl;
}
void cricket :: average()
{
cout<<"\naverage runs of player"<<playerfname<<" "<<playerlname<<endl;
avg=totalrun/totalmatches;
cout<<avg;
}
void cricket :: averageall()
{
avgtotal=totalmatches+avgtotal;
avgruns=totalrun+avgruns;
avgall=avgruns/avgtotal;
}
void cricket :: displayavg()
{
cout<<"\n total matches of all players"<<avgtotal<<endl;
cout<<"\n total runs of all players"<<avgruns<<endl;
cout<<"\n average runs of all players"<<avgall<<endl;
}
int main()
{
int i,j;
cout<<"enter number of players";
cin>>i;
cricket c[i];
//to display player details and average of runs for every single player
for(j=0;j<i;j++)
{
c[j].display();
c[j].average();
}
//to average of runs for all the players
for(j=0;j<i;j++)
{
c[j].averageall();
}
c[j].displayavg();
//to sort all the players behalf of runs
return 0;
}
#include<iostream>
using namespace std;
class crikte
{
public:
float avg_singlplay;
char p_name[20];
int total_match_play,p_code, total_run, num_notout, match_play;
int count = 0;
void read_player_details()
{
cout << "\nEnter PlayerName,PlayerCode,Total Runs ,Number of Not Outs, and Number of Matches Played : ";
cin >> p_name >> p_code >> total_run >> num_notout>>match_play;
}
void display_avg(int playercode)
{
if (p_code == playercode)
{
avg_singlplay = total_run / float(match_play - num_notout);
cout << "\n" << p_name << "\t\t\t" << total_run << "\t\t\t" << avg_singlplay;
}
}
int display_avg(int number,crikte a)
{
avg_singlplay = 0;
if (count <= number)
{
avg_singlplay += a.total_run / float(a.match_play - a.num_notout);
count++;
return avg_singlplay;
}
}
};
void display_sorted_list_accto_total_runs(int number,crikte a[10])
{
for (int i = 0; i < number-1; i++)
{
crikte cri;
if (a[i].total_run > a[i + 1].total_run)
{
cri = a[i];
a[i] = a[i + 1];
a[i + 1] = cri;
}
}
for (int i = 0; i < number; i++)
{
cout << "\n" << a[i].total_run;
}
}
int main()
{
crikte a[10];
int choose, number,pl_code;
float avg=0;
do
{
cout << "\n1.Enter Player Details";
cout << "\n2.Display Average Runs of a Single Player";
cout << "\n3.Display Average of all Players";
cout << "\n4.Display List of Players";
cout << "\n5.Exit";
cout << "\n enter a number: ";
cin >> choose;
switch (choose)
{
case 1:cout << "\nFor How many Players You Want To Enter Details : ";
cin >> number;
for (int i = 0; i < number; i++)
{
a[i].read_player_details();
}
break;
case 2:
cout << "Enter a Player Code For Which You Want To Display Average Runs : ";
cin>>pl_code;
cout << "\nPlayerName\t\tTotalRunsScored\t\tAverageRuns";
for (int i = 0; i < number; i++)
{
a[i].display_avg(pl_code);
}
break;
case 3:
for (int i = 0; i < number; i++)
{
avg+=a[i].display_avg(number,a[i]);
}
avg /= number;
cout << "Average of All Team is : " << avg;
break;
case 4:display_sorted_list_accto_total_runs(number,a);
break;
default:break;
}
} while (choose != 5);
}
============================bank account program======================================
#include<iostream>
using namespace std;
class bank
{
string cust_name;
long int account_no;
string acc_type;
float balance;
public:
//constructor
bank()
{
//intial opening balance is 500
balance=500;
}
//function to deposit money
void deposit()
{
float bal;
cout<<"enter amount to be deposited";
cin>>bal;
balance=balance+bal;
cout<<"\n now balance is "<<balance;
}
//function to withdraw amount if balance is grater than 500
float withdraw()
{
float with;
cout<<"your account balance is"<<endl;
cout<<balance<<"Rs."<<endl;
cout<<"enter amount to withdraw";
cin>>with;
if(balance>500)
{
balance=balance-with;
cout<<"balance after withdraw"<<endl;
cout<<balance;
}
else
cout<<"balance is less than 500";
return balance;
}
//function to input account details from user
void account_details()
{
cout<<"enter customer name";
cin>>cust_name;
cout<<"enter account number";
cin>>account_no;
cout<<"enter account type";
cin>>acc_type;
cout<<"enter balance";
cin>>balance;
}
//function to display content
void display_details()
{
cout<<"customer name"<<cust_name<<endl;
cout<<"account number"<<account_no<<endl;
cout<<"account type"<<acc_type<<endl;
cout<<"balance is"<<balance<<endl;
}
};
int main()
{
bank b1;
int i;
b1.account_details();
b1.display_details();
cout<<"1. to deposit money to bank account"<<endl;
cout<<"2. to withdraw money from bank account"<<endl;
cout<<"0. to cancel"<<endl;
cin>>i;
switch (i)
{
case 1:
b1.deposit();
break;
case 2:
b1.withdraw();
break;
case 0:
cout<<"operation cancel";
break;
default:
cout<<"enter wrong input";
break;
}
return 0;
}
==============================================complex addition=============================================
#include <iostream>
using namespace std;
class Complex
{
public:
int real, imagnary;
Complex add(int real_no, Complex s1)
{
Complex sum;
sum.real = real_no + s1.real;
sum.imagnary = s1.imagnary;
return sum;
}
Complex add(Complex s1, Complex s2)
{
Complex sum;
sum.real = s2.real + s1.real;
sum.imagnary = s1.imagnary+s2.imagnary;
return sum;
}
};
int main()
{
Complex a,b,ans,c;
int no;
cout << "\nEnter a Real Number : ";
cin >> no;
cout << "\nEnter a Complex Number (a+bi) : ";
cin >> a.real >> a.imagnary;
ans = a.add(no, a);
cout << "\nAddition of Real Number and a Imagenary Number is : " << ans.real << " + " << ans.imagnary<<"i";
cout << "\nEnter Two Complex Number (a+bi) Real Part and Imaginary Part : ";
cin >> b.real >> b.imagnary>>c.real>>c.imagnary;
ans = ans.add(b, c);
cout << "\nAddition of two Complex Number is : "<<ans.real<<"+"<<ans.imagnary<<"i";
return 0;
}
===========================flight program=======================================
//program to create flight class
//name-goutam jain
//reg no 220970040
//date-12-10-2022
#include<iostream>
using namespace std;
//create flight class
class flight
{
int fnumber;//flight number
string desti; //destination
float dista; //distance
float fuel;
float calculate_fuel(float d)
{
float f;
if(d>=1000)
{
f=500;
}
if(d>1000&&d<=2000)
{
f=1100;
}
if (d>2000)
{
f=2200;
}
return f;
}
public:
//constructor
flight()
{
dista=500;
}
//enter the information for flight in information function
void information_entry(flight f)
{
cout<<"enter flight number";
cin>>fnumber;
cout<<"enter desitnation";
cin>>desti;
cout<<"enter distance";
cin>>dista;
fuel=calculate_fuel(dista);
}
//function for display information of flight class
void display_info(flight f)
{
cout<<"flight details are\n";
cout<<fnumber<<"\t"<<desti<<endl;
cout<<dista<<"\n";
cout<<"fuel in liters"<<fuel<<endl;
}
};
int main()
{
flight f1;
f1.information_entry(f1);
f1.display_info(f1);
return 0;
}
/******************************************************************************
ReplyDeleteOnline C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include
using namespace std;
class bank
{
string cust_name;
long int account_no;
string acc_type;
float balance;
public:
//constructor
bank()
{
//intial opening balance is 500
balance=500;
}
//function to deposit money
void deposit()
{
float bal;
cout<<"enter amount to be deposited";
cin>>bal;
balance=balance+bal;
cout<<"\n now balance is "<>with;
if(balance>500)
{
balance=balance-with;
cout<<"balance after withdraw"<>cust_name;
cout<<"enter account number";
cin>>account_no;
cout<<"enter account type";
cin>>acc_type;
cout<<"enter balance";
cin>>balance;
}
//function to display content
void display_details()
{
cout<<"customer name"<>i;
switch (i)
{
case 1:cout<<"Enter For Which Object You Want To Deposit Amount (For Object 1 Presss 1) or (For Object 2 Presss 2)";
cin>>j;
if(j==1)
b1.deposit();
else
b2.deposit();
break;
case 2:cout<<"Enter For Which Object You Want To Deposit Amount (For Object 1 Presss 1) or (For Object 2 Presss 2)";
cin>>j;
if(j==1)
b1.withdraw();
else
b2.withdraw();
break;
case 3:cout<<"Enter For Which Object You Want To Deposit Amount (For Object 1 Presss 1) or (For Object 2 Presss 2)";
cin>>j;
if(j==1)
b1.display_details();
else
b2.display_details();
break;
default:
break;
}
}while(i!=4);
return 0;
}