Professional Documents
Culture Documents
2
#include <iostream>
#include <string.h>
using namespace std;
class Course
{
private:
int cnum;
char cname[100];
public:
Course(): cnum(0)
{
strcpy(cname,"");
}
Course(int num,char name[]): cnum(num)
{
strcpy(cname,name);
}
void show()
{
cout<<"Course Number is : "<<cnum<<endl;
cout<<"Course Name is : "<<cname<<endl;
}
};
class Labcourse: public Course
{
private:
int labhrs;
public:
Labcourse(): Course(), labhrs(0)
{
}
Labcourse(int num,char name[],int lh):Course(num,name),labhrs(lh)
{
}
void show()
{
Course::show();
cout<<"Lab Hours : "<<labhrs<<endl;
if(labhrs==4)
{
cout<<"This is Labcourse "<<endl;
}
else
{
cout<<"This is Not a Labcourse "<<endl;
}
}
};
int main()
{
Labcourse l1(101,"OOP",3);
l1.show();
return 0;
}
2019 Qno.3
#include <iostream>
#include <string.h>
using namespace std;
class Shape
{
private:
int X,Y;
char name[100];
public:
Shape():X(0),Y(0)
{
strcpy(name,"");
}
void get()
{
cout<<"Enter X-coordinate : ";
cin>>X;
cout<<"Enter Y-coordinate : ";
cin>>Y;
cout<<"Enter Shape Name : ";
cin.ignore();
cin.getline(name,100);
}
void show() const
{
cout<<"X-coordinate : "<<X<<endl;
cout<<"Y-coordinate : "<<Y<<endl;
cout<<"Shape Name : "<<name<<endl;
}
bool operator ==(Shape ss)
{
if(X==ss.X && Y==ss.Y && strcmp(name,ss.name)==0)
return true;
else
return false;
}
};
int main()
{
Shape s1,s2,s3;
cout<<"\t\t~~Enter Shape-1 Details~~"<<endl;
s1.get();
cout<<"\t\t~~Enter Shape-2 Details~~"<<endl;
s2.get();
if((s1==s2)==true)
cout<<"\nBoth Shapes are Equal " <<endl;
else
cout<<"\nBoth Shapes are Not Equal "<<endl;
return 0;
}
2019 Qno.4
#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;
class Publication
{
private:
char title[100];
float price;
public:
Publication():price(0.0f)
{
strcpy(title,"");
}
virtual void get()
{
cout<<"Enter Price : ";
cin>>price;
cout<<"Enter Title : ";
cin.ignore();
cin.getline(title,100);
}
virtual void show()
{
cout<<"Price : "<<price<<endl;
cout<<"Title : "<<title<<endl;
}
virtual bool IsOverSize()=0;
virtual void IsOverSize2()=0;
};
class Book: public Publication
{
private:
int page;
public:
Book():Publication(),page(0)
{
}
void get()
{
Publication::get();
cout<<"Enter Pages : ";
cin>>page;
}
void show()
{
Publication::show();
cout<<"Pages : "<<page<<endl;
}
bool IsOverSize()
{
if(page>500)
return true;
else
return false;
}
void IsOverSize2()
{
cout<<"OverSIZE Book "<<endl;
}
};
}
void get()
{
Publication::get();
cout<<"Enter Playtime(in Minutes) : ";
cin>>playtime;
}
void show()
{
Publication::show();
cout<<"Playtime : "<<playtime<<endl;
}
bool IsOverSize()
{
if(playtime>90)
{
return true;
}
else
return false;
}
void IsOverSize2()
{
cout<<"OverSIZE TAPE "<<endl;
}
};
int main()
{
Publication *ptr[10];
int choice;
int i=0;
char opt;
do
{
cout<<"1. For Book "<<endl;
cout<<"2. For Tape "<<endl;
cout<<"\nEnter Your Choice : ";
cin>>choice;
if(choice==1)
{
ptr[i]= new Book();
cout<<"\n\t\t~~Details FOr BOOK~~"<<endl;
ptr[i]->get();
cout<<"\n\t\t~~Details You Entered~~"<<endl;
ptr[i]->show();
if(ptr[i]->IsOverSize()==true)
{
ptr[i]->IsOverSize2();
}
}
else if(choice==2)
{
ptr[i]= new Tape();
cout<<"\n\t\t~~Details FOr TAPE~~"<<endl;
ptr[i]->get();
cout<<"\n\t\t~~Details You Entered~~"<<endl;
ptr[i]->show();
if(ptr[i]->IsOverSize()==true)
{
ptr[i]->IsOverSize2();
}
}
else
{
cout<<"Invalid Choice ...Try Again "<<endl;
exit(1);
}
i++;
cout<<"\nDo You want To Continue (y/n) : ";
cin>>opt;
}
while(opt=='y' || opt=='Y');
return 0;
}
2019 Qno.5
#include <iostream>
#include <exception>
#include <stdlib.h>
return 0;
}
2019 Qno.6
#include <iostream>
#include <stdlib.h>
#include <fstream>
#include<string.h>
using namespace std;
class Text
{
public:
void upper()
{
ifstream file;
file.open("C:\Bs.txt",ios::in);
if(!file)
{
cout<<"FIle Not found "<<endl;
exit(1);
}
char ch,ch1;
while(!file.eof())
{
file.get(ch);
ch1=toupper(ch);
cout<<ch1;
}
file.close();
}
void countt()
{
int count=0;
ifstream file;
file.open("C:\Bs.txt",ios::in);
if(!file)
{
cout<<"FIle Not found "<<endl;
exit(1);
}
string ch;
while(!file.eof())
{
file>>ch;
if(ch=="is")
{
count++;
}
}
cout<<"\n\nTotal Words Named as *is* are "<<count<<endl;
}
};
int main()
{
Text t1;
t1.upper();
t1.countt();
return 0;
}
2022 Qno.1
#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <string.h>
}
virtual void get()
{
cout<<"Enter Length : ";
cin>>length;
cout<<"Enter Width : ";
cin>>width;
}
virtual double showarea()=0;
};
class Rectangle : public Shape
{
private:
double area;
public:
Rectangle():Shape()
{}
double showarea()
{
area=(2*length)*(2*width);
return area;
}
};
class Triangle: public Shape
{
private:
double area;
public:
Triangle():Shape()
{}
double showarea()
{
area=(length*width)/2.0f;
return area;
}
};
int main()
{
Shape *ptr[2];
int opt,i=0;
double area;
char choice;
ofstream fri8;
fri8.open("C:\Computer.bin",ios::binary);
if(!fri8)
{
cout<<"ERrOr...Not Found "<<endl;
}
do
{
cout<<"1. For TRIANGLE "<<endl;
cout<<"2. For Rectangle "<<endl;
cout<<"\nEnter option : ";
cin>>opt;
switch (opt)
{
case 1 :
{
ptr[i]=new Triangle();
cout<<"\n\t\t~Enter Details For Traingle~"<<endl;
ptr[i]->get();
cout<<"\nAREA OF TRIANGLE IS : "<<ptr[i]->showarea();
break;
}
case 2:
{
ptr[i]=new Rectangle();
cout<<"\n\t\t~Enter Details For Rectangle~"<<endl;
ptr[i]->get();
return 0;
}
2022 Qno.2
#include <iostream>
#include <string.h>
#include <exception>
using namespace std;
class String
{
private:
char str[50];
public:
String()
{
strcpy(str, "");
}
String(char st[])
{
strcpy(str, st);
}
// Overloaded input stream operator
friend istream& operator >> (istream &, String&);
int main()
{
String s1;
try
{
cin >> s1;
}
catch (runtime_error &r)
{
cout << "Error: " << r.what() << endl;
}
String s2;
s2 = "Imran " + s1;