Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 40

LAB 2:-

Q2:-
#include <iostream>
#include <string>
using namespace std;
void func(int *p, int size, int nsize)
{int i, *temp;
temp = new int[size];
for(i=0;i<size;i++)
{temp[i] = p[i];}
delete p;
p = new int [nsize];
for(i=0;i<nsize;i++)
{p[i] = 0;}
if(nsize>size)
{for(i=0;i<size;i++)
{p[i] = temp[i];}}
if(nsize<size)
{for(i=0;i<nsize;i++)
{p[i] = temp[i];}}
delete temp;
for(i=0;i<nsize;i++)
{cout<<p[i]<<" ";
}
cout<<endl;
delete p;
}
int main()
{int size, i, nsize;
int *p;
cout<<"Enter the size of the array:"<<endl;
cin>>size;
p = new int [size];
cout<<"Enter the values to store:"<<endl;
for(i=0;i<size;i++)
{cin>>p[i];}
cout<<"Enter new size of array:"<<endl;
cin>>nsize;
func(p,size,nsize);
system("pause");
return 0;}

Q3:-
int main()
{int *p, *q, size1, size2, i, *all, a, b, j, x, n=0;
cout<<"Enter the size of 1st array:"<<endl;
cin>>size1;
p = new int [size1];
cout<<"Enter the elements of the 1st array:"<<endl;
for(i=0;i<size1;i++)
{cin>>p[i];}
cout<<"Enter the size of 2nd array:"<<endl;
cin>>size2;
q = new int [size2];
cout<<"Enter the elements of the 2nd array:"<<endl;
for(i=0;i<size2;i++)
{cin>>q[i];}
cout<<"Array 1:"<<endl;
for(i=0;i<size1;i++)
{cout<<p[i]<<" ";
}
cout<<endl<<"Array 2:"<<endl;
for(i=0;i<size2;i++)
{cout<<q[i]<<" ";
}
a = size1 + size2;
all = new int [a];
for(i=0;i<size1;i++)
{all[i] = p[i];}
j = 0;
for(i=size1;i<a;i++)
{all[i] = q[j];
j++;}
cout<<endl<<"Merging Arrays:"<<endl;
for(i=0;i<a;i++)
{cout<<all[i]<<" ";
}
cout<<endl;
delete p;
delete q;
int f;
for(i=0;i<a;i++)
{x = all[i];
for(int j=i+1;j<a;j++)
{f = all[j];
if(f == x)
{all[j] = -1;}
else
{}
}}
for(i=0;i<a;i++)
{x = all[i];
if(x == -1)
{n = n+1;}
else
{}}
int *temp;
int w = a - n;
temp = new int [w];
j=0;
for(i=0;i<a;i++)
{x = all[i];
if(x != -1)
{temp[j] = x;
j++;
}
else
{}
}
cout<<"Final Array:"<<endl;
for(i=0;i<w;i++)
{cout<<temp[i]<<" ";
}
cout<<endl;
delete temp;
delete all;
system("pause");
return 0;}
LAB 3:-
Q1:-
#include <iostream>
using namespace std;
void AddColumns (int * &arr, int size)
{int i=size+1;
arr = new int [i];
}
void RowWiseInput(int *q, int size)
{int i,a = size - 1;
cout<<"Enter the Values for row "<<size<<endl;
for(i=0;i<size;i++)
{cin>>q[i];}
}
void RowWisePrint(int *c, int size)
{int i;
for(i=0;i<size;i++)
{cout<<c[i]<<" ";}
cout<<endl;
}
int main()
{int **arr,rows,i, a;
cout<<"Enter the number of rows:"<<endl;
cin>>rows
arr=new int*[rows];
for(i=0; i<rows; i++)
{AddColumns(arr[i],i);
}
for(i=0;i<rows;i++)
{a=i+1;
RowWiseInput(arr[i],a);}
cout<<endl<<"The array is as follows:"<<endl;
for(i=0;i<rows;i++)
{a=i+1;
RowWisePrint(arr[i],a);
}
for(i=0;i<rows;i++)
{delete [] arr[i];
}
system("pause");
return 0;}

Q3:-
#include <iostream>
using namespace std;
void RowWisePrint(char *c, int size)
{int i;
for(i=0;i<size;i++)
{cout<<c[i];}
cout<<endl;
}
void seating(char** &q, int row, int col)
{char a = 'a',in, out;
int r, c,i,j,cla;
while(a == 'a')
{cout<<"Book ticket (t)\nView seating plan (p)"<<endl;
cin>>in;
if(in == 't')
{cout<<endl<<"The seating plan is as follows:"<<endl;
for(i=0;i<row;i++)
{RowWisePrint(q[i],col);}
cout<<endl<<"First Class (1)\nBuisness Class (2)\nEconomy Class (3)"<<endl;
cin>>cla;
cout<<endl<<"First Class rows (0 - 2)\nBuisness Class rows (3 - 7)\nEconomy Class rows (8 -
"<<row<<")"<<endl;
cout<<"Enter the row:"<<endl;
cin>>r;
cout<<"Enter the column:"<<endl;
cin>>c;
if((cla == 1) && (r < 3) && (r >= 0))
{out = q[r][c];
if(out == 'X')
{cout<<"The seat is already booked"<<endl;}
else
{q[r][c] = 'X';
cout<<endl<<"Your seat has been booked"<<endl;}}
else if ((cla == 2) && (r < 8) && (r > 2))
{out = q[r][c];
if(out == 'X')
{cout<<"The seat is already booked"<<endl;}
else
{q[r][c] = 'X';
cout<<endl<<"Your seat has been booked"<<endl;}}
else if ((cla == 3) && (r > 7))
{out = q[r][c];
if(out == 'X')
{cout<<"The seat is already booked"<<endl;}
else
{q[r][c] = 'X';
cout<<endl<<"Your seat has been booked"<<endl;}}
else
{cout<<"Invalid"<<endl;}
}
else if(in == 'p')
{cout<<endl<<"The seating plan is as follows:"<<endl;
for(i=0;i<row;i++)
{RowWisePrint(q[i],col);}}
cout<<"To continue press a\nTo exit press e"<<endl;
cin>>a;}}
int main()
{int rows,i, a,col,j;
char **arr;
cout<<"Enter the number of rows:"<<endl;
cin>>rows;
cout<<"Enter the number of columns:"<<endl;
cin>>col;
arr=new char*[rows];
for(i=0; i<rows; i++)
{arr[i] = new char [col];
}

for(i=0;i<rows;i++)
{for(j=0;j<col;j++)
{arr[i][j] = '*';}}
seating(arr,rows,col);
cout<<endl<<"The seating plan is as follows:"<<endl;
for(i=0;i<rows;i++)
{RowWisePrint(arr[i],col);
}
cout<<endl<<"Have a nice journey"<<endl;
for(i=0;i<rows;i++)
{delete [] arr[i];
}
system("pause");
return 0;}

POSTLAB 3:-

#include <iostream>
using namespace std;
int main()
{int **org, **tran, r, c, i, j, f, h;
cout<<"Enter the number of rows:"<<endl;
cin>>r;
cout<<"Enter the number of columns:"<<endl;
cin>>c;
org = new int*[r];
for(i=0;i<r;i++)
{org[i] = new int [c];
}
cout<<"Enter the values of matrix:"<<endl;
for(i=0;i<r;i++)
{for(j=0;j<c;j++)
{cin>>org[i][j];}
}
cout<<"Original matrix:"<<endl;
for(i=0;i<r;i++)
{for(j=0;j<c;j++)
{cout<<org[i][j]<<" ";}
cout<<endl;}
tran = new int*[c];
for(i=0;i<c;i++)
{tran[i] = new int [r];
}
for(i=0;i<c;i++)
{for(j=0;j<r;j++)
{tran[i][j] = org[j][i];}
}
cout<<endl<<"Transposed Matrix:"<<endl;
for(i=0;i<c;i++)
{for(j=0;j<r;j++)
{cout<<tran[i][j]<<" ";}
cout<<endl;
}
for(i=0;i<r;i++)
{delete[] org[i];}
for(i=0;i<c;i++)
{delete[] tran[i];}
system("pause");
return 0;}

LAB 4:-
Q1:-
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct item
{string name;
double price;};
void getData(ifstream &in, item beta[])
{int i=0;
while(!in.eof())
{in>>beta[i].name>>beta[i].price;
i++;}
}
void showMenu(item beta[], string *p, double *q, int& size)
{int i=0, num;
char a='m', b;
for(i=0;i<6;i++)
{cout<<i+1<<". "<<beta[i].name<<" $"<<beta[i].price<<endl;}
cout<<"Select the item by entering the number of the item (one at a time)"<<endl;
for(i=0;i<size;i++)
{cout<<"Enter item number:"<<endl;
cin>>num;
num = num-1;
p[i] = beta[num].name;
q[i]= beta[num].price;}}
void printCheck(string *p, double *q, int size)
{int i=0;
double bill, fbill = 0, tax ;
cout<<endl<<"Your Check is as follows:"<<endl<<endl;
for(i=0;i<size;i++)
{bill = q[i];
fbill = fbill + bill;
cout<<p[i]<<" $"<<q[i]<<endl;}
tax = fbill * 0.05;
fbill = fbill + tax;
cout<<endl<<"Tax = $"<<tax<<endl<<"Total= $"<<fbill<<endl<<endl;
}
int main()
{int a,b,i=0, size;
double *q;
string *p;
item beta[6];
ifstream in;
in.open("exercise1.txt");
getData(in, beta);
for(i=0;i<6;i++)
{cout<<i+1<<". "<<beta[i].name<<" $"<<beta[i].price<<endl;}
cout<<"Enter the number of items you want to buy:"<<endl;
cin>>size;
p = new string[size];
q = new double[size];
showMenu(beta,p,q,size);
printCheck(p,q,size);
in.close();
system("pause");
return 0;}

Q2:-
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
struct Author
{int id, bcode[3], bprice[3];
string fname, lname, bname[3], edition[3];
};
void readData(ifstream &in, Author beta[3])
{int i,j;
for(i=0;i<3;i++)
{in>>beta[i].id>>beta[i].fname>>beta[i].lname;
for(j=0;j<3;j++)
{in>>beta[i].bcode[j]>>beta[i].bname[j]>>beta[i].bprice[j]>>beta[i].edition[j];}
}}
void print(Author beta[3])
{int i,j;
cout<<"The record is as follows:"<<endl<<endl;
for(i=0;i<3;i++)
{cout<<beta[i].id<<" "<<beta[i].fname<<" "<<beta[i].lname<<endl;
for(j=0;j<3;j++)
{cout<<setw(22)<<beta[i].bcode[j]<<" "<<beta[i].bname[j]<<" $"<<beta[i].bprice[j]<<"
"<<beta[i].edition[j]<<endl;}
cout<<endl;}}
void DisplaySpecificRecord(Author beta[])
{int aid,i,j,a;
cout<<"Enter the ID of the author you want to view details of"<<endl;
cin>>aid;
for(i=0;i<3;i++)
{a = beta[i].id;
if(a == aid)
{j = i;}}
cout<<endl<<"The details of desired author are as follows:"<<endl<<endl;
cout<<beta[j].id<<" "<<beta[j].fname<<" "<<beta[j].lname<<endl;
for(i=0;i<3;i++)
{cout<<setw(22)<<beta[j].bcode[i]<<" "<<beta[j].bname[i]<<" $"<<beta[j].bprice[i]<<"
"<<beta[j].edition[i]<<endl;
}}
int main()
{int i;
Author beta[3];
ifstream in;
in.open("exercise2.txt");
readData(in,beta);
print(beta);
DisplaySpecificRecord(beta);
in.close();
system("pause");
return 0;}

POSTLAB 4:-
#include <iostream>
using namespace std;
struct TicTacToe
{int alpha[3][3];
};
void DisplayTable(TicTacToe beta)
{int i, j, temp;
for(i=0;i<3;i++)
{for(j=0;j<3;j++)
{temp = beta.alpha[i][j];
if(temp == -1)
{cout<<"X"<<" ";}
else if(temp == -2)
{cout<<"Y"<<" ";}
else
{cout<<temp<<" ";}
}
cout<<endl;}
}
int WinCheck(TicTacToe beta)
{int i, j, t1, t2, t3, t4, t5, t6, t7, t8, t9, win;
t1 = beta.alpha[0][0];
t2 = beta.alpha[0][1];
t3 = beta.alpha[0][2];
t4 = beta.alpha[1][0];
t5 = beta.alpha[1][1];
t6 = beta.alpha[1][2];
t7 = beta.alpha[2][0];
t8 = beta.alpha[2][1];
t9 = beta.alpha[2][2];
if((t1 == -1) && (t2 == -1) && (t3 == -1))
{win = 1;
return win;}
else if((t4 == -1) && (t5 == -1) && (t6 == -1))
{win = 1;
return win;}
else if((t7 == -1) && (t8 == -1) && (t9 == -1))
{win = 1;
return win;}
else if((t1 == -1) && (t4 == -1) && (t7 == -1))
{win = 1;
return win;}
else if((t2 == -1) && (t5 == -1) && (t8 == -1))
{win = 1;
return win;}
else if((t3 == -1) && (t6 == -1) && (t9 == -1))
{win = 1;
return win;}
else if((t1 == -1) && (t5 == -1) && (t9 == -1))
{win = 1;
return win;}
else if((t3 == -1) && (t5 == -1) && (t7 == -1))
{win = 1;
return win;}
else if((t1 == -2) && (t2 == -2) && (t3 == -2))
{win = 2;
return win;}
else if((t4 == -2) && (t5 == -2) && (t6 == -2))
{win = 2;
return win;}
else if((t7 == -2) && (t8 == -2) && (t9 == -2))
{win = 2;
return win;}
else if((t1 == -2) && (t4 == -2) && (t7 == -2))
{win = 2;
return win;}
else if((t2 == -2) && (t5 == -2) && (t8 == -2))
{win = 2;
return win;}
else if((t3 == -2) && (t6 == -2) && (t9 == -2))
{win = 2;
return win;}
else if((t1 == -2) && (t5 == -2) && (t9 == -2))
{win = 2;
return win;}
else if((t3 == -2) && (t5 == -2) && (t7 == -2))
{win = 2;
return win;}
else
{win = 0;
return win;}}
void PlayGame(TicTacToe &beta)
{int i, j, temp, win, b;
char a;
cout<<"Player 1 = ' X '"<<endl;
cout<<"Player 2 = ' Y '"<<endl;
cout<<endl<<"Rules: To select the box, press the number of the box to place the move. \nGood
Luck!\nP.S try not to make an invalid move. :'-("<<endl;
for(i=0;i<5;i++)
{cout<<endl<<"Player 1's turn:"<<endl<<endl;
DisplayTable(beta);
a = 'm';
while (a == 'm')
{cin>>temp;
for(int c=0;c<3;c++)
{for(int k=0;k<3;k++)
{b = beta.alpha[c][k];
if(b == temp)
{beta.alpha[c][k] = -1;
c=4;k=4;a = 'k';}
if ((c == 2) && (k == 2) && (b != temp))
{cout<<"Move is invalid. Please make a valid move."<<endl;}
}}}
win = WinCheck(beta);
if(win == 1)
{cout<<"Player 1 is the winner!! :-)"<<endl;
DisplayTable(beta);
i=6;}
else if(win == 2)
{cout<<"Player 2 is the winner!! :-)"<<endl;
DisplayTable(beta);
i=6;}
if(i<4)
{cout<<endl<<"Player 2's turn:"<<endl<<endl;
DisplayTable(beta);
a = 'm';
while (a =='m')
{cin>>temp;
for(int c=0;c<3;c++)
{for(int k=0;k<3;k++)
{b = beta.alpha[c][k];
if(b == temp)
{beta.alpha[c][k] = -2;
c=4;k=4;a = 'k';}
if ((c == 2) && (k == 2) && (b != temp))
{cout<<"Move is invalid. Please make a valid move."<<endl;}
}}}
win = WinCheck(beta);
if(win == 1)
{cout<<"Player 1 is the winner!! :-)"<<endl;
DisplayTable(beta);
i=6;}
else if(win == 2)
{cout<<"Player 2 is the winner!! :-)"<<endl;
DisplayTable(beta);
i=6;}}}
if ((i == 5) && (i != 6))
{cout<<endl<<"Game Draw. Try Hard next time!! :D"<<endl;
DisplayTable(beta);
}}
int main()
{int i, j,f=1;
TicTacToe beta;
for(i=0;i<3;i++)
{for(j=0;j<3;j++)
{beta.alpha[i][j] = f;
f++;}}
PlayGame(beta);
cout<<endl;
DisplayTable(beta);
system("pause");
return 0;}

LAB 5:-

POSTLAB 5:-

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
struct bookList
{int edition, price;
string bookcode, bookname, subject;
};
struct Author
{int id;
string fname, lname;
bookList ok[3];
};
void readfunction(ifstream &in, Author yo[])
{int i=0, j=0;
while(!in.eof())
{in>>yo[i].id>>yo[i].fname>>yo[i].lname;
in>>yo[i].ok[j].bookcode>>yo[i].ok[j].bookname>>yo[i].ok[j].subject>>yo[i].ok[j].price>>yo[i].ok[j].e
dition;
j++;
in>>yo[i].ok[j].bookcode>>yo[i].ok[j].bookname>>yo[i].ok[j].subject>>yo[i].ok[j].price>>yo[i].ok[j].e
dition;
j++;
in>>yo[i].ok[j].bookcode>>yo[i].ok[j].bookname>>yo[i].ok[j].subject>>yo[i].ok[j].price>>yo[i].ok[j].e
dition;
j++;
i++;
j=0;}
}
void printdata(Author yo[])
{int i, j;
for(i=0;i<3;i++)
{cout<<endl<<yo[i].id<<endl<<yo[i].fname<<" "<<yo[i].lname<<endl;
for(j=0;j<3;j++)
{cout<<yo[i].ok[j].bookcode<<" "<<yo[i].ok[j].bookname<<" "<<yo[i].ok[j].subject<<"
Rs."<<yo[i].ok[j].price<<" "<<yo[i].ok[j].edition<<"th"<<endl;
}}
}
int main()
{Author yo[3];
ifstream in;
in.open("postlabinput.txt");
readfunction(in,yo);
printdata(yo);
in.close();
system("pause");
return 0;}

POSTLAB 5 INPUT:-

19586

Bill Moris

101 abcdef Programming 1000 10

101 abcdef Programming 1000 10

101 abcdef Programming 1000 10

19586

Bill Moris

101 abcdef Programming 1000 10

101 abcdef Programming 1000 10

101 abcdef Programming 1000 10

19586

Bill Moris

101 abcdef Programming 1000 10

101 abcdef Programming 1000 10

101 abcdef Programming 1000 10

Q1:-
#include <iostream>
#include <string>
using namespace std;
struct facultyMember
{int IDnumber;
string Firstname, Lastname, Designation;
};
struct University
{string name,address;
facultyMember op[3];};
void newrecord(facultyMember &fm)
{cout<<"Enter the First Name of Employee:"<<endl;
cin>> fm.Firstname;
cout<<"Enter the Last Name of Employee:"<<endl;
cin>> fm.Lastname;
cout<<"Enter the ID number of Employee:"<<endl;
cin>> fm.IDnumber;
cout<<"Enter the Designation of Employee:"<<endl;
cin>> fm.Designation;
}
void printdetails(facultyMember fm)
{cout<<endl<<"The details of employee are:\nID number =
"<<fm.IDnumber<<endl<<fm.Firstname<<"
"<<fm.Lastname<<endl<<fm.Designation<<endl<<endl;
}
void sortid(facultyMember fm[ ], int size)
{facultyMember a;
int i, j;
for(i=0;i<size;i++)
{for(j=size-1;j>i;j--)
{if(fm[j].IDnumber < fm[j-1].IDnumber)
{a=fm[j];
fm[j]=fm[j-1];
fm[j-1]=a;}
}}}
int main()
{facultyMember fm[3];
int i, j;
University myUni;
myUni.name="Fast University";
myUni.address="B1 Block Faisal Town";
for(i=0;i<3;i++)
{cout<<i+1<<endl;
newrecord(fm[i]);}
for(i=0;i<3;i++)
{cout<<i+1;
printdetails(fm[i]);}
sortid(fm,3);
cout<<"The sorted Values are:"<<endl;
for(i=0;i<3;i++)
{cout<<i+1;
printdetails(fm[i]);}
for(i=0;i<3;i++)
{myUni.op[i] = fm[i];}
for(i=0;i<3;i++)
{cout<<i+1;
cout<<myUni.name<<endl<<myUni.address;
printdetails(myUni.op[i]);}
system("pause");
return 0;
}

LAB 6:-
Q1:-
#include <iostream>
#include <string>
using namespace std ;
class DateType
{
private:
int day, month, year;
string mon;

public:
void setDate (int, int, int);
void display ();
void incDay ();
void incMonth ();
void incYear ();
bool isEqual (DateType);
void increment (int);
};
void DateType :: setDate (int d, int m, int y)
{
day = d;
month = m;
year = y;
}
void DateType :: display ()
{
if (month == 1)
mon = "Jan";
else if (month == 2)
mon = "Feb";
else if (month == 3)
mon = "Mar";
else if (month == 4)
mon = "Apr";
else if (month == 5)
mon = "May";
else if (month == 6)
mon = "Jun";
else if (month == 7)
mon = "Jul";
else if (month == 8)
mon = "Aug";
else if (month == 9)
mon = "Sep";
else if (month == 10)
mon = "Oct";
else if (month == 11)
mon = "Nov";
else if (month == 12)
mon = "Dec";
cout<<"Date is : "<<day<<"-"<<mon<<"-"<<year<<endl;
}

void DateType :: incDay ()


{
if (month == 4 || month == 6 || month == 9 || month == 11)
{
if (day == 30)
{
day = 1;
month++;
}
else
day++;
}
else if (month == 1 |month == 7 || month == 8 || month == 10 || month == 12)
{
if (day == 31)
{
day = 1;
if (month == 12)
{
month = 1;
year++;
}
else
month++;
}
else
day++;
}
else
{
if (day == 28)
{
day = 1;
month++;
}
else
day++;
}
}
void DateType :: incMonth ()
{
if (month == 12)
{
month = 1;
year++;
}
else
month++;
}
void DateType :: incYear ()
{
year++;
}

bool DateType :: isEqual (DateType obj)


{
if (day == obj.day && month == obj.month && year == obj.year)
return 1;
else
return 0;
}
void DateType :: increment (int a)
{
for (int i=0; i<a; i++)
{
incDay ();
}
}

int main()
{
DateType D;
DateType C;
int d,y,m;
cout<<"Enter date"<<endl;
cin>>d>>m>>y;
cout<<endl;
D.setDate(d,m,y);
D.display();
cout<<endl;
cout<<"********************"<<endl;
d=31,
m=9;
y=1995;
cout<<"Set date:"<<d<<"-"<<m<<"-"<<y<<endl;
D.setDate(d,m,y);
cout<<endl;
D.display();
cout<<endl;
cout<<"********************"<<endl;
d=28, m=2, y=1998;
cout<<"Set date:"<<d<<"-"<<m<<"-"<<y<<endl;
D.setDate(28,2,1998);
D.display();
cout<<endl;
cout<<"********************"<<endl;
cout<<"AFTER INCREMENTING BY 1 DAY"<<endl;
D.incDay();
D.display();
cout<<endl;
cout<<"********************"<<endl;
cout<<"If "<<endl;
D.setDate(30,11,2007);
D.display();
cout<<endl;
cout<<"AFTER INCREMENTING BY 1 MONTH"<<endl;
D.incMonth();
D.display();
cout<<endl;
cout<<"********************"<<endl;
cout<<"AFTER INCREMENTING BY 1 YEAR"<<endl;
D.incYear();
D.display();
cout<<endl;
cout<<"********************"<<endl;

C.setDate(12,3,1999);
cout<<"New object created:"<<endl;
cout<<"DATE1 : "<<endl;
C.display();
cout<<"DATE2 : "<<endl;
D.display();
cout<<endl;
if (D.isEqual(C))
cout<<"Dates are Equal\n";
else
cout<<"Dates are Not Equal\n\n";
cout<<"********************************"<<endl;
cout<<"If ";
D.display();
cout<<endl;
cout<<"Date after 9 days will be"<<endl;
D.increment(9);
D.display();

return 0;
}

Q2:-
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class dateType
{private:
int day, mon, year;
string month;
public:
void setdate(int, int, int);
int getday();
int getmonth();
int getyear();
void printdate();
void incday();
void incmonth();
void incyear();
void equal(dateType);
void incbyday(int);
};
int dateType::getday()
{return day;}
int dateType::getmonth()
{return mon;}
int dateType::getyear()
{return year;}
void dateType::equal(dateType a)
{if ((day == a.day) && (mon == a.mon) && (year == a.year))
{cout<<"The dates are equal"<<endl;}
else
{cout<<"The dates are not equal"<<endl;}
}
void dateType::setdate(int a, int b, int c)
{
if((((a>0) && (a<32) && (c>0) && (b>0) && (b<13)) && ((b == 1) || (b == 3) || (b == 5) || (b == 7) ||
(b == 8) || (b == 10) || (b == 12))) || (((a > 0) && (a<31) && (c>0) && (b>0) && (b<13)) && ((b ==
4) || (b == 6) || (b == 9) || (b == 11))) || ((a>0) && (a<29) && (b == 2) && (c>0)))
{day = a;
mon = b;
year = c;
if(mon == 1)
{month = "January";}
else if(mon == 2)
{month = "Feburary";}
else if(mon == 3)
{month = "March";}
else if(mon == 4)
{month = "April";}
else if(mon == 5)
{month = "May";}
else if(mon == 6)
{month = "June";}
else if(mon == 7)
{month = "July";}
else if(mon == 8)
{month = "August";}
else if(mon == 9)
{month = "September";}
else if(mon == 10)
{month = "October";}
else if(mon == 11)
{month = "November";}
else if(mon == 12)
{month = "December";}}
else
{cout<<"Date is invalid";}
}
void dateType::incyear()
{year = year + 1;
}
void dateType::incmonth()
{int a;
a = mon + 1;
if(a > 12)
{mon = 1;
year = year + 1;}
else
{mon = a;}
if(mon == 1)
{month = "January";}
else if(mon == 2)
{month = "Feburary";}
else if(mon == 3)
{month = "March";}
else if(mon == 4)
{month = "April";}
else if(mon == 5)
{month = "May";}
else if(mon == 6)
{month = "June";}
else if(mon == 7)
{month = "July";}
else if(mon == 8)
{month = "August";}
else if(mon == 9)
{month = "September";}
else if(mon == 10)
{month = "October";}
else if(mon == 11)
{month = "November";}
else if(mon == 12)
{month = "December";}
}

void dateType::incday()
{int a;
a = day;
if((a==31) && ((mon == 1) || (mon == 3) || (mon == 5) || (mon == 7) || (mon == 8) || (mon == 10)))
{day = 1;
mon = mon + 1;
}
else if((a == 28) && (mon == 2))
{day = 1;
mon = mon + 1;}
else if((a == 30) && ((mon == 4) || (mon == 6) || (mon == 9) || (mon == 11)))
{day = 1;
mon = mon + 1;}
else if((a == 31) && (mon == 12))
{day = 1;
mon = mon + 1;
year = year + 1;}
else
{day = day + 1;}}
void dateType::incbyday(int a)
{int i;
int e;
e = day;
for(i=0;i<a;i++)
{e = day;
if((e==31) && ((mon == 1) || (mon == 3) || (mon == 5) || (mon == 7) || (mon == 8) || (mon == 10)))
{day = 1;
mon = mon + 1;}
else if((e == 28) && (mon == 2))
{day = 1;
mon = mon + 1;}
else if((e == 30) && ((mon == 4) || (mon == 6) || (mon == 9) || (mon == 11)))
{day = 1;
mon = mon + 1;}
else if((e == 31) && (mon == 12))
{day = 1;
mon = 1;
year = year + 1;}
else
{day = day + 1;}
}}
void dateType::printdate()
{if(mon == 1)
{month = "January";}
else if(mon == 2)
{month = "Feburary";}
else if(mon == 3)
{month = "March";}
else if(mon == 4)
{month = "April";}
else if(mon == 5)
{month = "May";}
else if(mon == 6)
{month = "June";}
else if(mon == 7)
{month = "July";}
else if(mon == 8)
{month = "August";}
else if(mon == 9)
{month = "September";}
else if(mon == 10)
{month = "October";}
else if(mon == 11)
{month = "November";}
else if(mon == 12)
{month = "December";}
cout<<endl<<day<<"-"<<month<<"-"<<year<<endl;}
void main()
{
dateType D;
dateType C;
int d,y,m;
cout<<"Enter date"<<endl;
cin>>d>>m>>y;
cout<<endl;
D.setdate(d,m,y);
D.printdate();
cout<<endl;
D.incbyday(31);
D.printdate();
for (int i=0;i<15;i++)
D.incmonth();
D.printdate();
cout<<"********************"<<endl;
d=31;
m=9;
y=1995;
cout<<"Set date:"<<d<<"-"<<m<<"-"<<y<<endl;
D.setdate(d,m,y);
cout<<endl;
D.printdate();
cout<<endl;
cout<<"********************"<<endl;
d=28; m=2; y=1998;
cout<<"Set date:"<<d<<"-"<<m<<"-"<<y<<endl;
D.setdate(28,2,1998);
D.printdate();
cout<<endl;
cout<<"********************"<<endl;
cout<<"AFTER INCREMENTING BY 1 DAY"<<endl;
D.incday();
D.printdate();
cout<<endl;
cout<<"********************"<<endl;
cout<<"If "<<endl;
D.setdate(30,11,2007);
D.printdate();
cout<<endl;
cout<<"AFTER INCREMENTING BY 1 MONTH"<<endl;
D.incmonth();
D.printdate();
cout<<endl;
cout<<"********************"<<endl;
cout<<"AFTER INCREMENTING BY 1 YEAR"<<endl;
D.incyear();
D.printdate();
cout<<endl;
cout<<"********************"<<endl;
C.setdate(12,3,1999);
cout<<"New object created:"<<endl;
cout<<"DATE1:"<<endl;
C.printdate();
cout<<"DATE2:"<<endl;
D.printdate();
cout<<endl;
D.equal(C);
cout<<"********************************"<<endl;
cout<<"If ";
D.printdate();
cout<<endl;
cout<<"Date after 9 days will be"<<endl;
D.incbyday(9);
D.printdate();
system("pause");
}

POSTLAB 6:-
//#include <iostream>
//#include <string>
//#include <fstream>
//using namespace std;
//class Rational
//{private:
//int a, b;
//public:
//Rational(int, int);
//Rational();
//void add(Rational, Rational);
//void mul(Rational, Rational);
//void div(Rational, Rational);
//void print();
//};
//Rational::Rational(int x, int y)
//{int i, j, l, q, w = -1;
//if((x>y) || (x == y))
//{l = x;
//for(i=l;i>0;i--)
//{q = x % i;
//if(i <= y)
//{w = y % i;}
//if((q == 0) && (w == 0))
//{x = x / i;
//y = y / i;
//i = 0;}}}
//else if(y>x)
//{l = y;
//for(i=l;i>0;i--)
//{q = y % i;
//if(i <= x)
//{w = x % i;}
//if((q == 0) && (w == 0))
//{x = x / i;
//y = y / i;
//i = 0;}}}
//a = x;
//b = y;
//}
//Rational::Rational()
//{a = 1;
//b = 1;}
//void Rational::add(Rational r, Rational t)
//{cout<<"Adding Rational Numbers"<<endl;
//int x, y, i, j, l, q, w = -1;
//x = (r.a*t.b) + (r.b*t.a);
//y = (r.b*t.b);
//if((x>y) || (x == y))
//{l = x;
//for(i=l;i>0;i--)
//{q = x % i;
//if(i <= y)
//{w = y % i;}
//if((q == 0) && (w == 0))
//{x = x / i;
//y = y / i;
//i = 0;}}}
//else if(y>x)
//{l = y;
//for(i=l;i>0;i--)
//{q = y % i;
//if(i <= x)
//{w = x % i;}
//if((q == 0) && (w == 0))
//{x = x / i;
//y = y / i;
//i = 0;}}}
//a = x;
//b = y;
//}
//void Rational::mul(Rational r, Rational t)
//{cout<<"Multipying Rational Numbers"<<endl;
//int x, y, i, j, l, q, w = -1;
//x = (r.a*t.a);
//y = (r.b*t.b);
//if((x>y) || (x == y))
//{l = x;
//for(i=l;i>0;i--)
//{q = x % i;
//if(i <= y)
//{w = y % i;}
//if((q == 0) && (w == 0))
//{x = x / i;
//y = y / i;
//i = 0;}}}
//else if(y>x)
//{l = y;
//for(i=l;i>0;i--)
//{q = y % i;
//if(i <= x)
//{w = x % i;}
//if((q == 0) && (w == 0))
//{x = x / i;
//y = y / i;
//i = 0;}}}
//a = x;
//b = y;}
//void Rational::div(Rational r, Rational t)
//{cout<<"Dividing Rational Numbers"<<endl;
//int x, y, i, j, l, q, w = -1;
//x = (r.a*t.b);
//y = (r.b*t.a);
//if((x>y) || (x == y))
//{l = x;
//for(i=l;i>0;i--)
//{q = x % i;
//if(i <= y)
//{w = y % i;}
//if((q == 0) && (w == 0))
//{x = x / i;
//y = y / i;
//i = 0;}}}
//else if(y>x)
//{l = y;
//for(i=l;i>0;i--)
//{q = y % i;
//if(i <= x)
//{w = x % i;}
//if((q == 0) && (w == 0))
//{x = x / i;
//y = y / i;
//i = 0;}}}
//a = x;
//b = y;}
//void Rational::print()
//{cout<<"Rational Number = "<<a<<"/"<<b<<endl;
//}
//int main()
//{Rational a(2,4);
//a.print();
//Rational b(3,21);
//b.print();
//cout<<"*******************************************"<<endl;
//Rational c;
//c.add(a,b);
//c.print();
//cout<<"*******************************************"<<endl;
//c.mul(a,b);
//c.print();
//cout<<"*******************************************"<<endl;
//c.div(a,b);
//c.print();
//cout<<"*******************************************"<<endl;
//system("pause");
//return 0;}

LAB 7:-
HEADER:-
#ifndef COMPLEXNO_H
#define COMPLEXNO_H
class complexno
{
private:
double real;
double imag;
public:
void setdata(double,double);
void print( );
void add(complexno,complexno);
void sub(complexno,complexno);
void mul(complexno,complexno);
void div(complexno,complexno);
};
#endif

MAIN:-

#include "header.h"
#include<iostream>
using namespace std;
void main()
{
complexno n1,n2,n3;
n1.setdata(3,4);
n1.print();
n2.setdata(5,6);
n2.print();
cout<<"Addition : ";
n3.add(n1,n2);
n3.print();
cout<<"Subtraction : ";
n3.sub(n1,n2);
n3.print();
cout<<"Multiplicaion : ";
n3.mul(n1,n2);
n3.print();
cout<<"Division : ";
n3.div(n1,n2);
n3.print();
system("pause");
}

Q1:-
#include "header.h"
#include<iostream>
using namespace std;
void complexno::setdata(double r,double i)
{
real=r;
imag=i;
}
void complexno::add(complexno n1,complexno n2)
{
real=n1.real+n2.real;
imag=n1.imag+n2.imag;
}
void complexno::print( )
{
cout<<"real part"<<" "<<real<<" "<<"+" <<" "<<"imaginary part "<<" "<<imag<<endl;
}
void complexno::sub(complexno n1,complexno n2)
{
real=n1.real-n2.real;
imag=n1.imag-n2.imag;
}
void complexno::mul(complexno n1,complexno n2)
{
real= ((n1.real*n2.real)-(n1.imag*n2.imag));
imag=(n1.real*n2.imag)+(n1.imag*n2.real);
}
void complexno::div(complexno n1,complexno n2)
{
real=((n1.real*n2.real)+ (n1.imag*n2.imag))/ ((n2.real*n2.real) + (n2.imag*n2.imag));
imag= ((n1.imag*n2.real) - (n1.real*n2.imag))/ ((n2.real*n2.real) + (n2.imag*n2.imag));
}

LAB 8:-
Q1:-
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class student
{friend void percentage(int, student &);
friend void grade(student &);
private:
char *name;
char grade;
int rollno, subjects;
double *marks;
double per;
public:
void setdata(char[], int, int, double[]);
void print();
};
void student::setdata(char a[],int sub, int b, double c[])
{name = a;
subjects = sub;
marks = new double[sub];
for(int i=0;i<sub;i++)
{marks[i] = c[i];
cout<<marks[i]<<endl;}
rollno = b;}
void percentage(int sub, student & b)
{int total;
double marktotal = 0;
total = sub * 100;
for(int i=0;i<sub;i++)
{marktotal = marktotal + b.marks[i];}
b.per = (marktotal / total) * 100;
}
void grade(student & b)
{if(b.per >= 90)
{b.grade = 'A+';}
else if((b.per >= 80) && (b.per < 90))
{b.grade = 'A';}
else if((b.per >= 70) && (b.per < 80))
{b.grade = 'B';}
else if((b.per >= 60) && (b.per < 70))
{b.grade = 'C';}
else if((b.per >= 50) && (b.per < 60))
{b.grade = 'D';}
else if((b.per >= 0) && (b.per < 50))
{b.grade = 'F';}
}
void student::print()
{cout<<name<<endl<<rollno<<endl<<"Marks:"<<endl;
for(int i=0;i<subjects;i++)
{cout<<marks[i]<<endl;}
cout<<"Percentage: "<<per<<endl;
cout<<"Grade: "<<grade<<endl;
}
int main()
{char a[20];
int subs, rolls;
double mark[6];
cin.getline(a,20);
for(int i=0;i<6;i++)
{mark[i] = 86.0 + i;}
subs = 6;
rolls = 14472;
student lop;
lop.setdata(a,subs,rolls,mark);
percentage(subs,lop);
grade(lop);
lop.print();
system ("pause");
return 0;}
Q2:-
//#include <iostream>
//#include <string>
//using namespace std;
//class DM
//{friend class DB;
//private:
//double metres, centi;
//public:
//DM(double, double);
//void setdata(double, double);
//friend void addition(DM &,DB &);
//void print();
//};
//class DB
//{friend class DM;
//private:
//double feet, inches;
//public:
//DB(double, double);
//void setdata(double, double);
//friend void addition(DM &,DB &);
//};
//DM::DM(double a, double b)
//{metres = a;
//centi = b;}
//DB::DB(double a, double b)
//{feet = a;
//inches = b;}
//void DM::setdata(double a, double b)
//{metres = a;
//centi = b;}
//void DB::setdata(double a, double b)
//{feet = a;
//inches = b;}
//void addition(DM & a, DB & b)
//{double q, w, o, p, l, k, f;
//int i;
//q = 0.3048 * b.feet;
//p = a.metres + q;
//i = p;
//f = (i - p) * -1;
//o = f * 100;
//a.metres = i;
//w = (2.54 * b.inches) + a.centi;
//if(w<100)
//{a.centi = a.centi + w;}
//else
//{l = w/100.0;
//i = l;
//l = (i - l) * -1;
//a.metres = a.metres + i;
//a.centi =l + o;}
//}
//void DM::print()
//{cout<<metres<<" metres"<<endl<<centi<<" centimetres"<<endl;}
//int main()
//{DM a(2,50);
//DB b(10000,500);
//addition(a,b);
//a.print();
//system ("pause");
//return 0;}

POSTLAB 8:-
//#include <iostream>
//#include <fstream>
//#include<stdlib.h>
//#include<time.h>
//using namespace std;
//class integers
//{
//friend void large(integers);
//friend void small(integers);
//friend void repeat(integers);
//friend void sort(integers &);
//private:
// int a[10];
//public:
// integers();
// ~integers();
//};
//integers::integers()
//{int i;
//srand(time(NULL));
//for(i=0;i<10;i++)
//{a[i] = rand() % 20 + 10;}
//cout<<"Integers :"<<endl;
//for(i=0;i<10;i++)
//{cout<<a[i]<<endl;}
//}
//integers::~integers()
//{int i;
//for(i=0;i<10;i++)
//{a[i] = 0;}
//}
//void large(integers q)
//{int la = 0, i, o;
//for(i=0;i<10;i++)
//{o = q.a[i];
//if(o > la)
//{la = o;}
//else
//{la = la;}}
//cout<<"Largest Integer: "<<la<<endl;
//}
//void small(integers q)
//{int sa = 100, i, o;
//for(i=0;i<10;i++)
//{o = q.a[i];
//if(o < sa)
//{sa = o;}
//else
//{sa = sa;}}
//cout<<"Smallest Integer: "<<sa<<endl;
//}
//void repeat(integers q)
//{int i, r, o, p[10] = {0}, j, k, f, rem;
//cout<<"Repeated Values:"<<endl;
//for(i=0;i<10;i++)
//{r = q.a[i];
//for(j=i+1;j<10;j++)
//{o = q.a[j];
//if((r == o) && (o != 0))
//{for(k=0;k<10;k++)
//{f = p[k];
//if(f == r)
//{rem = f;}
//else
//{rem = rem;}}
//if(r != rem)
//{cout<<r<<endl;}
//}}}}
//void sort(integers & q)
//{int i,j,p;
//for(i=0;i<10;i++)
//for(j=10-1 ; j > i; j--)
//{if(q.a[j] < q.a[j-1])
//{p=q.a[j];
//q.a[j]=q.a[j-1];
//q.a[j-1]=p;
//}}}
//int main()
//{integers a;
//small(a);
//large(a);
//repeat(a);
//system("pause");
//return 0;}

LAB 9:-
Q1:-
#include <iostream>
#include <string>
using namespace std;

class PointType
{
private:
int x;
int y;
public:
PointType();
PointType(int, int);
void print();
int checkquad();
void setdata(int, int);
int getx();
int gety();
};
PointType::PointType()
{x=0;
y=0;}
PointType::PointType(int a, int b)
{x = a;
y = b;}
int PointType::getx()
{return x;}
int PointType::gety()
{return y;}
void PointType::print()
{cout<<"x-coordinate = "<<x<<endl;
cout<<"y-coordinate = "<<y<<endl;}
int PointType::checkquad()
{int p;
if((x>0)&&(y>0))
{p = 1;}
else if((x<0)&&(y>0))
{p = 2;}
else if((x<0)&&(y<0))
{p = 3;}
else if((x>0)&&(y>0))
{p = 4;}
return p;
}
void PointType::setdata(int a, int b)
{x=a;
y=b;}
class CircleType
{
double radius;
char * color;
PointType center;
public:
CircleType();
CircleType(int, int, double, char*);
void print();
double calc_area();
double circum();
void setparam(int, int, double, char*);
};
CircleType::CircleType()
{radius = 0;
color = "White";
center.setdata(0,0);}
CircleType::CircleType(int a, int b, double r, char* p)
{radius = r;
color = p;
center.setdata(a, b);}
void CircleType::setparam(int a, int b, double r, char* p)
{radius = r;
color = p;
center.setdata(a, b);}
void CircleType::print()
{cout<<"Radius = "<<radius<<endl;
cout<<"Colour = "<<color<<endl;
center.print();
}
double CircleType::calc_area()
{double a, d;
d = radius * radius;
a = 3.14 * d;
return a;
}
double CircleType::circum()
{int c;
c = (2 * 3.14) * radius;
return c;
}
int main()
{
CircleType C(21,2,3.5,"blue");
cout<<"\n************************\n"<<endl;
C.print();
cout<<"\n************************\n"<<endl;
cout<<" Area of circle is "<<C.calc_area();
cout<<"\n\n************************\n\n"<<endl;

PointType P(-20,3);
int p=P.checkquad();
P.print();
switch (p)
{
case 0:
cout<<"Point lies at center"<<endl;
break;
case 1:
cout<<"Point lies in I quadrant"<<endl;
break;
case 2:
cout<<"Point lies in II quadrant"<<endl;
break;
case 3:
cout<<"Point lies in III quadrant"<<endl;
break;
case 4:
cout<<"Point lies in IV quadrant"<<endl;
break;
default:
cout<<"INVALID";
break;
}
int x;
int y;
double r;
char col[9];
CircleType circ(2,5,4.89,"purple");
cout<<"\n\n***********************\n\n";
circ.print();
cout<<"\n Enter radius \n";
cin>>r;
cout<<"\n Enter the coordinates where the center lies \n";
cin>>x>>y;
cout<<"\n Enter color \n";
cin>>col;
circ.setparam(x,y,r,col);
cout<<"\n\n***********************\n\n";
circ.print();
cout<<"\n\n***********************\n\n";
system("pause");
return 0;
}

POSTLAB 9:-
//#include <iostream>
//#include <string>
//using namespace std;
//class course
//{
// int courseNumber;
// int creditHours;
//public:
// void setCourse (int x,int y){courseNumber = x; creditHours = y;}
// void printcourse(){cout<<"Course Number = "<<courseNumber<<endl<<"Credit Hours =
"<<creditHours<<endl;}
//};
//class section
//{
// int secNumber;
// course c; //composition
//public:
// void setSection (int,int,int);
// void printSection(){c.printcourse();cout<<"Section Number = "<<secNumber<<endl;}
//};
//void section::setSection(int a, int b, int d)
//{c.setCourse(a,b);
//secNumber = d;}
//int main()
//{section p[7];
//int i, j;
//for (i=0;i<7;i++)
//{p[i].setSection(117,3,i+1);}
//for (i=0;i<7;i++)
//{cout<<"*****************************************"<<endl;
//p[i].printSection();
//cout<<"*****************************************"<<endl;}
//system("pause");
//return 0;}

LAB 10:-
Q1:-
#include <iostream>
#include <string>
using namespace std;
class Product
{private:
int discount, price;
public:
Product(){price = 0;discount = 0;}
void setDiscount(int a){discount = a;}
void setPrice(int a){price = a;}
int getDiscount(){return discount;}
int getPrice(){return price;}
};
class Book :public Product
{private:
string name, author;
public:
Book(){name = "Unknown"; author = "Unknown";}
Book(int a, int b, string c, string d){name = d;author = c;setPrice(a); setDiscount(b);}
double SalePrice(){double fp;int p, d; p = getPrice(); d = getDiscount(); fp = p - ((p*d) / 100);
return fp;}
};
class Electronics :public Product
{private:
string name;
public:
void setName(string a){name = a;}
string getName(){return name;}
};
class MP3player :public Electronics
{private:
string color;
int capacity;
public:
MP3player(int a,int b,string c,string d,int f){color = d; capacity= f;
setPrice(a);setDiscount(b);setName(c);}
int getCapacity(){return capacity;}
double SalePrice(){double fp;int p, d; p = getPrice(); d = getDiscount(); fp = p - ((p*d) / 100);
return fp;}
};
class TV :public Electronics
{private:
int size;
public:
TV(int a, int b, string c, int d){size = d;setPrice(a);
setDiscount(b);
setName(c);}
double SalePrice(){double fp;
int p, d;
p = getPrice();
d = getDiscount();
fp = p - ((p*d) / 100);
return fp;}
};
void main(){
int choice1=0,choice2=0,capacity,size;
double price,discount;
string manufacturer,color,author,name;
cout<<"\n*************WELCOME TO ONLINE SHOP******************\n";
cout<<"\nPress 1 for Electronics."<<"\nPress 2 for Books\n";
cin>>choice1;
if (choice1==1){
cout<<"\nPress 1 for MP3Players."<<"\nPress 2 for TV\n";
cin>>choice2;
if (choice2==1){
cout<<"\nSet Attributes\n";
cout<<"Price: ";
cin>>price;
cout<<"\nDiscount in %: ";
cin>>discount;
cout<<"\nManufacturer: ";
cin>>manufacturer;
cout<<"\nColor: ";
cin>>color;
cout<<"\nCapacity in GB: ";
cin>>capacity;
MP3player m1(price,discount,manufacturer,color,capacity);
if (m1.getCapacity()==1)
m1.setDiscount(10);
else
m1.setDiscount(50);
cout<<m1.SalePrice();
}
else if (choice2==2) {
cout<<"\nSet Attributes\n";
cout<<"Price: ";
cin>>price;
cout<<"\nDiscount in %: ";
cin>>discount;
cout<<"\nManufacturer: ";
cin>>manufacturer;
cout<<"\nSize: ";
cin>>size;
TV t1(price,discount,manufacturer,size);
cout<<t1.SalePrice();
}
else
cout<<"\nInvalid value... try again later";
}
else if (choice1==2) {
cout<<"\nSet Attributes\n";
cout<<"Price: ";
cin>>price;
cout<<"\nDiscount in %: ";
cin>>discount;
cout<<"\nAuthor: ";
cin>>author;
cout<<"\nName: ";
cin>>name;
Book b1(price, discount, author,name);
cout<<b1.SalePrice();
}
else
cout<<"\nInvalid value... try again later";

system("pause");
}

POSTLAB 10(A):-

//#include <iostream>
//#include <string>
//using namespace std;
//class pointType
//{private:
// int x,y;
//public:
// pointType(){x=0;y=0;}
// pointType(int a, int b){x=a;y=b;}
// void setpointType(int a, int b){x=a;y=b;}
// void setx(int a){x = a;}
// void sety(int a){y = a;}
// int getx(){return x;}
// int gety(){return y;}
// void printpointType(){cout<<"x-coordinate = "<<x<<endl<<"y-coordinate = "<<y<<endl;}
//};
//int main()
//{pointType a(1,3);
//pointType b;
//int x, y;
//cout<<"Enter x-coordinate for point 2:"<<endl;
//cin>>x;
//cout<<"Enter y-coordinate for point 2:"<<endl;
//cin>>y;
//b.setpointType(x,y);
//cout<<"****************************************"<<endl;
//cout<<"Point 1:"<<endl;
//a.printpointType();
//cout<<"****************************************"<<endl;
//cout<<"Point 2:"<<endl;
//b.printpointType();
//cout<<"****************************************"<<endl;
//system("pause");
//return 0;}

POSTLAB 10(B):-
//#include<iostream>
//#include<string>
//using namespace std;
//class pointType
//{private:
// int x,y;
//public:
// pointType(){x=0;y=0;}
// pointType(int a, int b){x=a;y=b;}
// void setpointType(int a, int b){x=a;y=b;}
// void setx(int a){x = a;}
// void sety(int a){y = a;}
// int getx(){return x;}
// int gety(){return y;}
// void printpointType(){cout<<"x-coordinate = "<<x<<endl<<"y-coordinate = "<<y<<endl;}
//};
//class circleType
//{private:
// int radius;
// pointType z;
//public:
// circleType(){radius = 0;z.setpointType(0,0);}
// circleType(int a, int b, int c){radius = a;z.setpointType(b,c);}
// void setcircleType(int a, int b, int c){radius = a;z.setpointType(b,c);}
// void setradius(int a){radius = a;}
// void setpoint(int a, int b){z.setpointType(a,b);}
// int getradius(){return radius;}
// void printcirleType(){cout<<"Circle Radius = "<<radius<<endl<<"Centre point =
("<<z.getx()<<","<<z.gety()<<")"<<endl;}
// void calcArea(){double p = 3.14 * (radius * radius);cout<<"Area of Circle = "<<p<<endl;}
// void calccircum(){double p = 3.14 * 2 * (radius);cout<<"Circumference of Circle =
"<<p<<endl;}
//};
//int main()
//{circleType p;
//int r, x, y;
//cout<<"Enter radius:"<<endl;
//cin>>r;
//cout<<"Enter centre:"<<endl;
//cin>>x>>y;
//p.setcircleType(r,x,y);
//p.printcirleType();
//p.calcArea();
//p.calccircum();
//system("pause");
//return 0;}
POSTLAB 10(C):-
#include<iostream>
#include<string>
using namespace std;
class pointType
{private:
int x,y;
public:
pointType(){x=0;y=0;}
pointType(int a, int b){x=a;y=b;}
void setpointType(int a, int b){x=a;y=b;}
void setx(int a){x = a;}
void sety(int a){y = a;}
int getx(){return x;}
int gety(){return y;}
void printpointType(){cout<<"x-coordinate = "<<x<<endl<<"y-coordinate = "<<y<<endl;}
};
class circleType
{private:
int radius;
pointType z;
public:
circleType(){radius = 0;z.setpointType(0,0);}
circleType(int a, int b, int c){radius = a;z.setpointType(b,c);}
void setcircleType(int a, int b, int c){radius = a;z.setpointType(b,c);}
void setradius(int a){radius = a;}
void setpoint(int a, int b){z.setpointType(a,b);}
int getradius(){return radius;}
int getcx(){return z.getx();}
int getcy(){return z.gety();}
void printcirleType(){cout<<"Circle Radius = "<<radius<<endl<<"Centre point =
("<<z.getx()<<","<<z.gety()<<")"<<endl;}
void calcArea(){double p = 3.14 * (radius * radius);cout<<"Area of Circle = "<<p<<endl;}
void calccircum(){double p = 3.14 * 2 * (radius);cout<<"Circumference of Circle =
"<<p<<endl;}
};
class cylinderType
{private:
int height;
circleType z;
public:
cylinderType(){height = 0;z.setcircleType(0,0,0);}
cylinderType(int a, int b, int c, int d){height = d;z.setcircleType(a,b,c);}
void setcylinderType(int a, int b, int c, int d){height = d;z.setcircleType(a,b,c);}
void setradius(int a){z.setradius(a);}
void setpoint(int a, int b){z.setpoint(a,b);}
int getradius(){return z.getradius();}
void printcylinderType(){cout<<"Base Radius = "<<z.getradius()<<endl<<"Centre point of
Base = ("<<z.getcx()<<","<<z.getcy()<<")"<<endl;}
void calcbaseArea(){double p = 3.14 * (z.getradius() * z.getradius());cout<<"Surface Area =
"<<p<<endl;}
void calcbasecircum(){double p = 3.14 * 2 * (z.getradius());cout<<"Circumference of Base =
"<<p<<endl;}
void calcvolume(){double b = 3.14 * (z.getradius()*z.getradius()); double l = b *
height;cout<<"Volume of cylinder = "<<l<<endl;}
};
int main()
{cylinderType p;
int r, x, y, h;
cout<<"Enter radius:"<<endl;
cin>>r;
cout<<"Enter centre:"<<endl;
cin>>x>>y;
cout<<"Enter height:"<<endl;
cin>>h;
p.setcylinderType(r,x,y,h);
p.printcylinderType();
p.calcvolume();
system("pause");
return 0;}

LAB 11:-
Q1:-
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
class Employee
{private:
int basicSalary;
int id;
public:
Employee(){basicSalary = 0; id = 0;}
Employee(int a, int b){basicSalary = b; id = a;}
void setEmployee(int a, int b){basicSalary = b; id = a;}
int getsalary(){return basicSalary;}
int getid(){return id;}
virtual double calculateSalary(){return basicSalary;}
void printEmp(){cout<<"ID = "<<id<<endl<<"Basic Salary = "<<basicSalary<<endl;}
};
class CommissionedEmployee : public Employee
{private:
int salea, rate;
public:
CommissionedEmployee(int a, int b, int c, int d){setEmployee(a,b);rate = c; salea = d;}
double calculateSalary(){int p = getsalary(); double total =(salea * (rate / 100)) + p;return
total;}
};
class HourlyEmployee : public Employee
{private:
int extra, payhour;
public:
HourlyEmployee(){extra = 0;payhour = 0; setEmployee(0,0);}
HourlyEmployee(int a, int b, int c, int d){setEmployee(a,b);payhour = c; extra = d;}
double calculateSalary(){int p = getsalary(); double total =(extra * payhour) + p;return total;}
void PrintEmployee(){printEmp();cout<<"Extra Hours = "<<extra<<endl<<"Pay per Hour =
"<<payhour<<endl;}
};
class RegularEmployee : public Employee
{private:
int extra;
public:
RegularEmployee(int a, int b, int c){setEmployee(a,b);extra = c;}
double calculateSalary(){int p = getsalary(); double total =extra + p;return total;}
};
int main()
{
CommissionedEmployee E1(25, 5000, 1000, 10);
// CASE 1 - derived Class Pointer pointing to Derived class object
CommissionedEmployee * ptr;
ptr = &E1;
cout<<" Commissioned Employee salary:"<<ptr->calculateSalary();
cout<<endl;
// CASE 2 - Base Class Pointer pointing to Derived class object
Employee * eptr;
eptr = &E1;
cout<<" Commissioned Employee salary:"<<eptr->calculateSalary();
cout<<endl;
CommissionedEmployee E2 (25, 5000, 1000, 10);
CommissionedEmployee E3 (26, 5000, 2000, 10);
HourlyEmployee H1(27, 5000, 10, 100 );
HourlyEmployee H2(28, 5000, 5, 100 );
RegularEmployee R1(29, 5000, 1000 );
RegularEmployee R2(29, 5000, 2000 );
Employee * list [6];
list[0] = & E2;
list[1] = & E3;
list[2] = & H1;
list[3] = & H2;
list[4] = & R1;
list[5] = & R2;
for(int i = 0 ; i < 6; i++)
{
cout<<"Employee "<<i<<" salary is :"<<list[i]->calculateSalary();
cout<<endl;
}
////Create file here named employee.dat for reading/writing employee //data
// ifstream myFile ("employee.dat", ios::in | ios::binary);
// ifstream myFile ("employee.dat", ios::out | ios::binary);
// cout<< "Writing Employee data to file \n";
// for(int i = 0 ; i < 6; i++)
// {
// list[i]->WriteEmployeeData();
// }
// HourlyEmployee hEmp[2];
// ReadHourlyEmployeeData(hEmp, 2);
////Display Hourly Employee data read from file
// for(int i = 0 ; i < 2; i++)
// {
// hEmp[i].PrintEmployee();
//
// }
system("pause");
return 0;
}

POSTLAB 11:-
//#include <iostream>
//#include <string>
//using namespace std;
//class Shape
//{protected:
// double Area;
//public:
// Shape(){Area = 0;}
// virtual void Display(){cout<<"Area = "<<Area<<"m^2"<<endl;}
// virtual void Calculate_Area() = 0;
//};
//class Rectangle:public Shape
//{private:
// int len, wid;
//public:
// Rectangle(){len = 0; wid = 0;}
// Rectangle(int a, int b){len = a; wid = b;}
// void Display(){cout<<"Area of Rectangle = "<<Area<<"m^2"<<endl;}
// void Calculate_Area(){Area = len * wid;}
//};
//class Circle:public Shape
//{private:
// int rad;
//public:
// Circle(){rad = 0;}
// Circle(int a){rad = a;}
// void Display(){cout<<"Area of Circle = "<<Area<<"m^2"<<endl;}
// void Calculate_Area(){Area = 3.14 * (rad * rad);}
//};
//int main()
//{
//Shape *p;
//Circle C1(5);
//Rectangle R1(4,6);
//p=&C1;
//p->Calculate_Area();
//p->Display();
//p=&R1;
//p->Calculate_Area();
//p->Display();
//system("pause");
//return 0;
//}

LAB 12:-

Q1:-

#include <iostream>
#include <string>
using namespace std;
class comp
{private:
double real, imag;
public:
void setpara(double a, double b){real = a; imag = b;}
comp operator +(comp);
comp operator -(comp);
comp operator *(comp);
comp operator /(comp);
void operator =(comp);
bool operator ==(comp);
void show(){cout<<"Complex Number = "<<real<<"+"<<imag<<"i"<<endl;}
};
comp comp::operator+(comp a)
{comp one;
one.real = real + a.real;
one.imag = imag + a.imag;
return one;
}
comp comp::operator-(comp a)
{comp one;
one.real = real - a.real;
one.imag = imag - a.imag;
return one;
}
comp comp::operator*(comp a)
{comp one;
one.real = (real*a.real) - (imag*a.imag);
one.imag = (real*a.imag) + (a.real*imag);
return one;
}
comp comp::operator/(comp a)
{comp one;
one.real = ((real*a.real) + (imag*a.imag)) / ((imag*imag) + (a.imag*a.imag));
one.imag = ((imag*a.real) - (real*a.imag)) / ((imag*imag) + (a.imag*a.imag));
return one;
}
void comp::operator=(comp a)
{comp one;
real = a.real;
imag = a.imag;
}
bool comp::operator==(comp a)
{
if((real == a.real)&&(imag == a.imag))
{return 1;}
else
{return 0;}
}
void main()
{
comp n1,n2,n3;
n1.setpara(2,3);
n2.setpara(1,4);
n3=n1;
n3.show();
comp n90 = n1+n2;
n90.show();
n3=n1*n2;
n3.show();
n3=n1-n2;
n3.show();
n3=n1/n2;
n3.show();
if(n1==n2)
cout<<"Both no have same real and imag part "<<endl;
else
cout<<"Unequal !!!"<<endl;

system("pause");}

Q2:-
#include <iostream>
#include <string>
using namespace std;
class PhoneNumber
{friend ostream & operator<<(ostream &, PhoneNumber);
friend istream & operator>>(istream &, PhoneNumber &);
private:
string lname, fname, phone;
public:
PhoneNumber(string a,string b,string c){lname = b, fname = a; phone = c;}
PhoneNumber(){lname = "Unknown", fname = "Unknown"; phone = "Unknown";}
void setdata(string a,string b,string c){lname = b, fname = a; phone = c;}
};
ostream & operator << (ostream &out, PhoneNumber a){out<<"Name = "<<a.fname<<"
"<<a.lname<<endl<<"Phone Number = "<<a.phone<<endl; return out;}
istream & operator >>(istream & in, PhoneNumber& a){in>>a.fname>>a.lname>>a.phone; return
in;}
int main()
{PhoneNumber a("Arsal","Siddiq","0332-4923659");
cout<<a;
cout<<"***************************************************************"<<endl;
PhoneNumber b[3];
cout<<"Enter the Values for First Object (First Name, Last Name, Phone Number):"<<endl;
cin>>b[0];
cout<<"***************************************************************"<<endl;
cout<<"Enter the Values for Second Object (First Name, Last Name, Phone Number):"<<endl;
cin>>b[1];
cout<<"***************************************************************"<<endl;
cout<<"Enter the Values for Third Object (First Name, Last Name, Phone Number):"<<endl;
cin>>b[2];
cout<<"***************************************************************"<<endl;
cout<<"First Object:"<<endl;
cout<<b[0];
cout<<"***************************************************************"<<endl;
cout<<"Second Object:"<<endl;
cout<<b[1];
cout<<"***************************************************************"<<endl;
cout<<"Third Object:"<<endl;
cout<<b[2];
cout<<"***************************************************************"<<endl;
system("pause");
return 0;}

POSTLAB 12:-
#include <iostream>
#include <string>
using namespace std;
class Rational
{friend ostream & operator <<(ostream &, Rational);
friend istream & operator >>(istream &, Rational &);
private:
double num, den;
public:
Rational(){num = 0; den = 0;}
Rational(double a, double b){num = a; den = b;}
void Reduce();
Rational operator +(Rational a)
{Rational b;b.num = num*a.den + a.num*den; b.den = den * a.den;return b;}
Rational operator -(Rational a)
{Rational b; b.num = num*a.den - a.num*den; b.den = den * a.den; return b;}
Rational operator *(Rational a)
{Rational b; b.num = num * a.num; b.den = den * a.den; return b;}
Rational operator /(Rational a)
{Rational b; b.num = num * a.den; b.den = den * a.num; return b;}
bool operator >(Rational a){double x, y; x = num / den; y = a.num / a. den; if(x>y){return
true;} else {return false;}}
bool operator <(Rational a){double x, y; x = num / den; y = a.num / a. den; if(x<y){return
true;} else {return false;}}
bool operator >=(Rational a){double x, y; x = num / den; y = a.num / a. den; if(x>=y){return
true;} else {return false;}}
bool operator <=(Rational a){double x, y; x = num / den; y = a.num / a. den; if(x<=y){return
true;} else {return false;}}
bool operator ==(Rational a){double x, y; x = num / den; y = a.num / a. den; if(x==y){return
true;} else {return false;}}
bool operator !=(Rational a){double x, y; x = num / den; y = a.num / a. den; if(x!=y){return
true;} else {return false;}}
};
ostream & operator <<(ostream & out, Rational a)
{out<<"Rational Number = "<<a.num<<"/"<<a.den<<endl;
}
istream & operator >>(istream & in, Rational & a)
{in>>a.num>>a.den;
}
void Rational::Reduce()
{int i, j, l, q, w = -1;
if((num>den) || (num == den))
{l = num;
for(i=l;i>0;i--)
{q = num % i;
if(i <= den)
{w = den % i;}
if((q == 0) && (w == 0))
{num = num / i;
den = den / i;
i = 0;}}}
else if(den>num)
{l = den;
for(i=l;i>0;i--)
{q = den % i;
if(i <= num)
{w = num % i;}
if((q == 0) && (w == 0))
{num = num / i;
den = den / i;
i = 0;}}}
}
int main()
{
system("pasue");
return 0;}

You might also like