You are on page 1of 21

Practical 1

#include <iostream>
using namespace std;
int main()
{
cout<<"Hello world!";
cout<<endl<<"output of Sayed Amaan Ali";
return 0;
}

Practical 2
#include <iostream>
using namespace std;
int main()
{
int len, bre, area;
cout<<"Enter the length of the rectangle : ";
cin>>len;
cout<<endl<<"Enter the breadth of the rectangle : ";
cin>>bre;
area = len*bre;
cout<<endl<<"Area of the rectangle : "<<area;
cout<<endl<<"output of Sayed Amaan Ali";
return 0;
}
Practical 3
#include <iostream>
using namespace std;
int main()
{
float s,pb,rate,t;
cout<<"Enter the principle balance : ";
cin>>pb;
cout<<endl<<"Enter the Rate(percent) : ";
cin>>rate;
cout<<endl<<"Enter the time period (years) : ";
cin>>t;
s=(pb*rate*t)/100;
cout<<endl<<"Simple interest is "<<s;
cout<<endl<<"output of Sayed Amaan Ali";
return 0;
}

Practical 4
#include <iostream>
using namespace std;
int main()
{
int math,phy,chem,cpp,eng;
int sum,Max;
float per;
cout<<endl<<"Enter maths marks : ";
cin>>math;
cout<<endl<<"Enter physics marks : ";
cin>>phy;
cout<<endl<<"Enter chemistry marks : ";
cin>>chem;
cout<<endl<<"Enter c++ marks : ";
cin>>cpp;
cout<<endl<<"Enter English marks : ";
cin>>eng;
sum=math+phy+chem+cpp+eng;
cout<<"Your total marks are "<<sum;
cout<<endl<<"Enter maximum marks : ";
cin>>Max;
per=(sum*100/Max);
cout<<endl<<"Your percentage is "<<per;
cout<<endl<<"output of Sayed Amaan Ali";
return 0;
}

Practical 5
#include <iostream>
using namespace std;
int main()
{
int age;
cout<<endl<<"Enter your age : ";
cin>>age;
if(age<18)
cout<<endl<<"You are not eligible to vote";
else
cout<<endl<<"You are eligible to vote";
cout<<endl<<"output of Sayed Amaan Ali";
return 0;
}
Practical 6
#include <iostream>
using namespace std;
int main()
{
int fact=1;
int i=0,no;
cout<<"Enter the no for which you want to calculate the factorial :
";
cin>>no;
for(i=no;i>=1;i--)
{
fact=fact*i;
}
cout<<"Factorial : "<<fact;
return 0;
}

Practical 7
#include <iostream>
using namespace std;
int main()
{
int n,a=0,b=1,c=0;
cout<<"Enter the number of terms: ";
cin>>n;
cout<<"Fibonacci Series:";
cout<<a<<"\t"<<b;
for(int i=2;i<n;i++)
{
c=a+b;
cout<<"\t"<<c;
a=b;
b=c;
}
return 0;
}

Practical 8
#include <iostream>
using namespace std;
int main()
{
int a,b;
char c;
cout<<"Enter the numbers : ";
cin>>a;
cin>>b;
cout<<endl<<"Enter the operation (+,-,/,*) : ";
cin>>c;
switch(c)
{
case '+' :
cout<<a+b;
break;
case '-' :
if(a>b)
cout<<a-b;
else
cout<<b-a;
break;
case '/' :
if(a>b)
cout<<a/b;
else
cout<<b/a;
break;
case '*' :
cout<<a*b;
break;
default :
cout<<"Please enter a valid operator";
break;
}
return 0;
}

Practical 9
#include <iostream>
using namespace std;
int main()
{
int arra[3][3]= {{1,2,3},
{4,5,6},
{7,8,9}};
for(int i=0;i<=2;i++)
{
for(int j=0;j<=2;j++)
{
cout<<arra[i][j]<<"\t";
}
cout<<endl;
}
cout<<endl;
int arrb[3][3]= {{1,2,3},
{4,5,6},
{7,8,9}};
for(int i=0;i<=2;i++)
{
for(int j=0;j<=2;j++)
{
cout<<arrb[i][j]<<"\t";
}
cout<<endl;
}
cout<<endl;
cout<<endl<<"Sum of the matrices\n";
for(int i=0;i<=2;i++)
{
for(int j=0;j<=2;j++)
{
cout<<arra[i][j]+arrb[i][j]<<"\t";
}
cout<<endl;
}
return 0;
}
Practical 10 missing
Practical 11
#include <iostream>
using namespace std;
class room
{
public:
int l,b,h;
void cal(int l, int b, int h)
{
cout<<"Area of the room : "<<l*b;
cout<<endl<<"Volume of the room : "<<l*b*h;
}
};
int main()
{
room r1,r2;
cout<<"Enter the length, breadth and height of the room 1 : ";
cin>>r1.l>>r1.b>>r1.h;
r1.cal(r1.l,r1.b,r1.h);
cout<<endl<<"Enter the length, breadth and height of the room 2 :
";
cin>>r2.l>>r2.b>>r2.h;
r2.cal(r2.l,r2.b,r2.h);
return 0;
}
Practical 12 missing
PRACTICAL 13
#include <iostream>
using namespace std;
class time
{
int h,m,sec;
public:
void intime()
{
cout<<"Enter hours : ";
cin>>h;
cout<<"Enter minutes : ";
cin>>m;
cout<<"Enter seconds : ";
cin>>sec;
}
void disptime();
void addtime(time, time);
};
void time::disptime()
{
cout<<h<<"h"<<m<<"min"<<sec<<"sec";
}
void time::addtime(time t1, time t2)
{
sec=t1.sec + t2.sec;
m=sec/60;
sec=sec%60;
m=m+t1.m+t2.m;
h=m/60;
m=m%60;
h=h+t1.h+t2.h;
}
int main()
{
time t1, t2, t3;
t1.intime();
t2.intime();
t3.addtime(t1, t2);
cout<<"T1 : ";
t1.disptime();
cout<<"t2 : ";
t2.disptime();
cout<<"Added time : ";
t3.disptime();
return 0;
}
Practical 14 missing

Practical 15
#include<iostream>
using namespace std;
class comp
{
public:
int r,i;
comp()
{
}
comp(int d)
{
r=d;
i=d;
}
comp(int e, int f)
{
r=e;
i=f;
}
void out()
{
cout<<endl<<"The sum of two complex nos. is "<<r<<"+"<<i<<"i.";
}
friend comp add(comp, comp);
};
comp add(comp c1, comp c2)
{
comp c3;
c3.r=c1.r+c2.r;
c3.i=c1.i+c2.i;
return c3;
}
int main()
{
int a,b,c;
comp c1;
cout<<endl<<"Enter the values for equal real and imaginary number : ";
cin>>a;
comp c2(a);
c2.out();
cout<<endl<<"Enter the different real and imaginary number : ";
cin>>b>>c;
comp c3(b,c);
c3.out();
comp c4;
c4=add(c2,c3);
c4.out();
}
Practical 16
#include <iostream>
using namespace std;
class opover
{
public:
int feet, inch;
void enter()
{
cout<<endl<<"Enter feet : ";
cin>>feet;
cout<<endl<<"Enter inch : ";
cin>>inch;
}
void operator+()
{
feet++;
inch++;
cout<<endl<<"Feet after increment : "<<feet;
cout<<endl<<"Inch after increment : "<<inch;
}
};
int main()
{
opover a;
a.enter();
+a;
return 0;
}

Practical 17
#include <iostream>
using namespace std;

class opover
{
public:
int x,y;
void enter()
{
cout<<endl<<"Enter x : ";
cin>>x;
cout<<endl<<"Enter y : ";
cin>>y;
}
void operator ==(opover)
{
cout<<endl<<"Sum : "<<x+y;
}
};
int main()
{
opover ob;
ob.enter();
ob==ob;
return 0;
}

Practical 18 missing
Practical 19 missing
Practical 20
#include <iostream>
#include <stdio.h>
using namespace std;

class basic_info
{
char name[20];
int rollno;
char sex;
public:
void getdata( )
{
cout<<endl<<"Enter name : ";
gets(name);
cout<<endl<<"Enter Roll no : ";
cin>>rollno;
cout<<endl<<"Enter Sex : ";
cin>>sex;
}
void display( )
{
cout<<endl<<"Name : "<<name;
cout<<endl<<"Roll no : "<<rollno;
cout<<endl<<"Sex : "<<sex;
}
};
class physical_fit : public basic_info
{
float h;
float w;
public:
void getdata2()
{
cout<<endl<<"Enter the height(in cm) : ";
cin>>h;
cout<<endl<<"Enter the weight(in kg) : ";
cin>>w;
}
void diplay2()
{
cout<<endl<<"height : "<<h;
cout<<endl<<"weight : "<<w;
}
};
int main()
{
physical_fit p;
p.getdata();
p.getdata2();
p.display();
p.diplay2();
return 0;
}

Practical 21
#include <iostream>
#include <stdio.h>
using namespace std;

class student
{
char name[20];
int roll;
public:
void getdata()
{
cout<<endl<<"Enter name : ";
gets(name);
cout<<"Enter roll no : ";
cin>>roll;
}
void diplay()
{
cout<<endl<<"Name : "<<name;
cout<<endl<<"Roll no : "<<roll;
}
};
class exam : public student
{
int eng, phy, chem, math, cpp, bio;
public:
int sum;
void getdata2()
{
cout<<endl<<"English : ";
cin>>eng;
cout<<"Physics : ";
cin>>phy;
cout<<"Chemistry : ";
cin>>chem;
cout<<"Maths : ";
cin>>math;
cout<<"c++ : ";
cin>>cpp;
cout<<"Biology : ";
cin>>bio;
sum=eng+phy+chem+math+cpp+bio;
}
};
class result : public exam
{
int total;
public:
void display2()
{
total=sum;
cout<<endl<<"Total marks : "<<total;
}
};
int main()
{
result r;
r.getdata();
r.getdata2();
r.diplay();
r.display2();
return 0;
}

Practical 22
#include <iostream.h>
#include <stdio.h>

class first
{
int bno;
char name[20];
public:
void getdata()
{
cout<<endl<<"Enter Book No. : ";
cin>>bno;
cout<<endl<<"Enter the name of book : ";
gets(name);
}
void putdata()
{
cout<<endl<<"Book No. : "<<bno;
cout<<endl<<"Name of Book : "<<name;
}
};
class second
{
char author[20], publisher[20];
public:
void getdata()
{
cout<<endl<<"Enter Author Name : ";
gets(author);
cout<<endl<<"Enter Publisher : ";
gets(publisher);
}
void showdata()
{
cout<<endl<<"Author Name : "<<author;
cout<<endl<<"Publisher : "<<publisher;
}
};
class third: public first, public second
{
int pages, year;
public:
void getdata()
{
first::getdata();
second::getdata();
cout<<endl<<"Enter No. of Pages : ";
cin>>pages;
cout<<endl<<"Enter the year of publication : ";
cin>>year;
}
void display()
{
putdata();
showdata();
cout<<endl<<"No. of Pages : "<<pages;
cout<<endl<<"Year of Publication : "<<year;
}
};
int main()
{
third b[10];
int num;
cout<<endl<<"Enter the number of books : ";
cin>>num;
for(int i=1;i<=num;i++)
{
b[i].getdata();
cout<<endl;
}
for(i=1;i<=num;i++)
{
b[i].display();
cout<<endl;
}
}

Practical 23

#include <iostream>
using namespace std;

class shape
{
public:
double h,b;
void getdata()
{
cout<<endl<<"Enter height : ";
cin>>h;
cout<<endl<<"Enter base : ";
cin>>b;
}
virtual void display()
{
//base class function must be defined
}
};
class triangle : public shape
{
public:
void display()
{
cout<<endl<<"Area of Triangle = "<<(h*b)/2;
}
};
class rectangle : public shape
{
public:
void display()
{
cout<<endl<<"Area of Rectangle = "<<h*b;
}
};
int main()
{
triangle t;
rectangle r;
shape *ptr;
ptr=&t;
ptr->getdata();
ptr->display();
ptr=&r;
ptr->getdata();
ptr->display();
}

Neeche wale mei zyada dhyaan rakhio,


kyonki mera program ka format bohot basic
sa hai
Practical 24
#include <iostream>
using namespace std;
template <class T>
void Swap(T &a, T &b)
{
T temp;
temp = a;
a = b;
b = temp;
}
void show(int a1,int b1,float a2,float b2, char a3,char b3)
{
cout<<endl<<"int 1 = "<<a1;
cout<<endl<<"int 2 = "<<b1;
cout<<endl<<"float 1 = "<<a2;
cout<<endl<<"float 2 = "<<b2;
cout<<endl<<"char 1 = "<<a3;
cout<<endl<<"char 2 = "<<b3;
Swap(a1, b1);
Swap(a2, b2);
Swap(a3, b3);
cout<<endl<<"values after swapping";
cout<<endl<<"int 1 = "<<a1;
cout<<endl<<"int 2 = "<<b1;
cout<<endl<<"float 1 = "<<a2;
cout<<endl<<"float 2 = "<<b2;
cout<<endl<<"char 1 = "<<a3;
cout<<endl<<"char 2 = "<<b3;
}
int main()
{
int a1,b1;
float a2,b2;
char a3,b3;
cout<<endl<<"Enter Two Integer values:\n";
cin>>a1>>b1;
cout<<endl<<"Enter Two Float values:\n";
cin>>a2>>b2;
cout<<endl<<"Enter Two Characters:\n";
cin>>a3>>b3;
show(a1,b1,a2,b2,a3,b3);
return 0;
}
Practical 25
#include <iostream>
using namespace std;
template <class T>
float square(T a)
{
T sq;
sq = a*a;
return sq;
}
void display(int a, float b)
{
int x;
float y;
x = square(a);
y = square(b);
cout<<endl<<"Square of "<<a<<" : "<<x;
cout<<endl<<"Square of "<<b<<" : "<<y;
}
int main()
{
int a;
float b;
cout<<endl<<"Enter Integer value : ";
cin>>a;
cout<<endl<<"Enter Float value : ";
cin>>b;
display(a,b);
return 0;
}
Iss wale mei bhi dhyaan rakhio, variable
names dekh, change kardio kyonki mere
wale bohot hi alag dikh rahe hain
Practical 26
#include <iostream>
#include <fstream>
#include <stdio.h>
using namespace std;
int main()
{
ofstream writeinfile;
char writename[20], readname[20];
cout<<"Enter the name : ";
gets(writename);
writeinfile.open("filename.txt");
writeinfile<<writename;
writeinfile.close();
ifstream readfromfile;
readfromfile.open("filename.txt");
cout<<endl<<"Reading from filename.txt"<<endl;
while(!readfromfile.eof())
{
readfromfile>>readname;
cout<<readname;
}
cout<<endl;
readfromfile.close();
return 0;
}
Practical 27
#include <iostream>
#include <fstream>
#include <stdio.h>
using namespace std;
int main()
{
ofstream file;
char text[50];
file.open("filename2.txt");
cout<<"Enter some text : ";
gets(text);
file<<text;
file.close();
return 0;
}
Practical 28
#include <iostream>
#include <fstream>
#include <stdio.h>
using namespace std;
int main()
{
fstream file1;
ofstream file2;
char f1[10], f2[10];
char ch[20];
cout<<"Enter original file name(with .txt) : ";
gets(f1);
file1.open(f1, ios::out);
file1<<"abcdefgh ";
file1.close();
cout<<endl<<"Enter second file name(with .txt) : ";
gets(f2);
file1.open(f1, ios::in);
file2.open(f2);
while(file1)
{
file1>>ch;
file2<<ch;
}
cout<<endl<<"copying done";
file1.close();
file2.close();
}

Practical 29 missing
Practical 30 missing

Bhai plz....jo variables ke naam hain aur jo


cheezein strings hain yaani double quotes
mei text hai, use change kardio, tere paas 10
tareeq tak time hai. Jo missing hain, woh
mere khud nahi hue, jitne the saare
bhejdiye, ab bas different karke output
nikalna baaki hai tujhe. Thank you

You might also like