0% found this document useful (0 votes)
50 views8 pages

Ahmad Shafeeq Bsse-Fa20-043 (Program No 1)

The document contains code for 8 different C++ programs. Program 1 defines a Phone structure with area code, exchange, and number fields and demonstrates input and output of phone numbers. Program 2 defines a Date structure and demonstrates input and output of dates. Program 3 defines a Max function to compare two integers and output the larger. Program 5 defines multiple power functions that can calculate powers of different data types.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views8 pages

Ahmad Shafeeq Bsse-Fa20-043 (Program No 1)

The document contains code for 8 different C++ programs. Program 1 defines a Phone structure with area code, exchange, and number fields and demonstrates input and output of phone numbers. Program 2 defines a Date structure and demonstrates input and output of dates. Program 3 defines a Max function to compare two integers and output the larger. Program 5 defines multiple power functions that can calculate powers of different data types.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Ahmad shafeeq

Bsse-fa20-043

(Program no 1) :

#include<iostream>
using namespace std;
struct Phone{
int area_code;
int exchange;
int number;
};
int main()
{
Phone P1,P2;
P1.area_code=92;
P1.exchange=311;
P1.number=3601131;
cout<<"Enter your area code : ";
cin>>P2.area_code;
cout<<"Enter your exchange : ";
cin>>P2.exchange;
cout<<"Enter your number: ";
cin>>P2.number;
cout<<"My number is ("<<P1.area_code<<")"<<P1.exchange<<"-"<<P1.number<<endl;
cout<<"Your number is ("<<P2.area_code<<")"<<P2.exchange<<"-"<<P2.number;
return 0;
}

(Program no 2 ) :

#include<iostream>
using namespace std;

struct date{
int month, day, year;
};

int main(){
char temp;
date date1;
cout << "Enter date (MM/DD/YYYY): ";
cin >> date1.month >> temp >> date1.day >> temp >> date1.year;
cout << endl << "Date is " << date1.month << "/" << date1.day << "/" << date1.year << endl;
return 0;
}

(Program no 3) :

#include<iostream>
using namespace std;
int Max(int a,int b){
if(a>b)
{
cout<<a<<" is Greater";
}
else
cout<<b<<" is Greater";
};

int main(){
int a,b;
cout<<"Enter First Value : ";
cin>>a;
cout<<"Enter Second Value : ";
cin>>b;
Max(a,b);
return 0;
}

(Program no 5):

#include<iostream>
using namespace std;
double power(double n,int p=2);
int power(int a, int b=2);
long power(long c , int d=2);
float power(float e,int f=2);
int main()
{
double n;
int p;
cout<<"`````````````````````````\n";
cout<<"enter an double value:\n";
cin>>n;
cout<<"enter an integer value as power:\n";
cin>>p;
power(n,p);
int a,b;
cout<<"enter an integer value:\n";
cin>>a;
cout<<"enter an integer value as power:\n";
cin>>b;
power(a,b);
long c;
int d;
cout<<"enter an long value:\n";
cin>>c;
cout<<"enter an integer value as power:\n";
cin>>d;
power(c,d);
float e;
int f;
cout<<"enter an float value:\n";
cin>>e;
cout<<"enter an integer value as power:\n";
cin>>f;
power(e,f);
return 0;
}
double power(double a,int b)
{
double j=1;
for(int i=1;i<=b;i++)
{

j=j*a;
}
cout<<"result is:\n"<<j<<"\n";
cout<<"------------------------\n"<<"continue.......\n";
}
int power(int a,int b)
{
double j=1;
for(int i=1;i<=b;i++)
{

j=j*a;
}
cout<<"result is:\n"<<j<<"\n";
cout<<"------------------------\n"<<"continue......\n";
}
long power(long a,int b)
{
double j=1;
for(int i=1;i<=b;i++)
{

j=j*a;
}
cout<<"result is:\n"<<j<<"\n";
cout<<"------------------------\n"<<"continue..... \n";
}
float power(float a,int b)
{
double j=1;
for(int i=1;i<=b;i++)
{

j=j*a;
}
cout<<"result is:\n"<<j<<"\n";
cout<<"------------------------\n"<<"end of program:\n@@@@@@@@@@@@\n";
}

(Program 5):

#include <iostream>
using namespace std;

class toll_plaza
{ private:
int tcars;
int pcars;
int ncars;
double money;
public:
toll_plaza()
{
tcars=0;
ncars=0;
pcars;
money=0;
}
void payingcar()
{
tcars++;
pcars++;
money=money+100;
cout<<"Entered"<<endl;
}
void nopayCar()
{
tcars++;
ncars++;
cout<<"Entered"<<endl;
}
void display1()
{
cout<<"Total no of cars are : "<<tcars<<endl;
cout<<"Total Money : "<<money<<endl;
}
void display2()
{
cout<<"Amount of Paying Cars = "<<pcars<<endl;
}
void display3()
{
cout<<"Amount of Non Paying Cars = "<<ncars<<endl;
}
};
int main()
{
toll_plaza T;
int a;
while(a!=3)
{
cout<<"Press 1 to Enter Paying Car "<<endl;
cout<<"Press 2 to Enter not paying Car "<<endl;
cout<<"Press 3 to display total and Exit"<<endl;
cout<<"Press 4 to display Paying Car "<<endl;
cout<<"Press 5 to display No Paying Car "<<endl;
cin>>a;
if(a==1)
{
T.payingcar();
}
else if(a==2)
{
T.nopayCar();
}
else if(a==3)
{
T.display1();
}
else if(a==4)
{
T.display2();
}
else if(a==5)
{
T.display3();
}
else
{
cout<<"Invalid Try Again";
}
}
return 0;
}

(Program no 6):

#include<iostream>
using namespace std;
class Counter_Object
{
private:
static int s;
int n;
int total;
public:
Counter_Object()
{
static int s;
n=++s;
}
void show()
{
cout<<"I am Oject "<<n<<"\n";
}
void Total()
{
total=n;
cout<<"Total = "<<n;
}
};
int Counter_Object :: s=0;
int main()
{
Counter_Object x[3];
for(int i=0;i<3;i++)
{
x[i].show();
};
x[3].Total();
return 0;
}

Program no 7:

#include<iostream>
using namespace std;
class Counter_Object
{
private:
static int s;
int n;
int total;
public:
Counter_Object()
{
static int s;
n=++s;
}
void show()
{
cout<<"I am Oject "<<n<<"\n";
}
void Total()
{
total=n;
cout<<"Total = "<<n;
}
};
int Counter_Object :: s=0;
int main()
{
Counter_Object x[3];
for(int i=0;i<3;i++)
{
x[i].show();
};
x[3].Total();
return 0;
}

(Program no 8):

#include<iostream>
using namespace std;
class Publication
{
public:
string title;
float price;
void getdata()
{
cout<<"Enter Book Title : ";
getline(cin,title);
cout<<"Enter Book Price : ";
cin>>price;
}
void putdata()
{
cout<<"Book Title = "<<title<<endl;
cout<<"Book Price = "<<price<<endl;
}
};
class Book:public Publication
{
public:
int count;
void getdata()
{
cout<<"Enter Total Number of Pages : ";
cin>>count;
}
void putdata()
{
cout<<"Number of Pages of The Book = "<<count<<endl;
}
};
class Tape:public Publication
{
public:
float time;
void getdata()
{
cout<<"Enter Total Duration of Audiocassette in minutes : ";
cin>>time;
}
void putdata()
{
cout<<"Total Duration of Audiocassette in minutes = "<<time<<endl;
}
};
int main()
{
Publication P;
Tape T;
Book B;
P.getdata();
B.getdata();
T.getdata();
P.putdata();
B.putdata();
T.putdata();
return 0;
}

You might also like