OOPFinal

You might also like

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

Q1

#include <iostream>
#include<string>
using namespace std;
class publication
{
protected:
string title;
float price;

public:
publication()
{
title=" ";
price=0.0;

}
publication(string t,float p)
{
title=t;
price=p;

}
void getData(){
cout<<"Enter Title\n";
cin>>title;
cout<<"Enter Price\n";
cin>>price;
}

};

class book : public publication


{
int pagecount;
public:
book()
{
pagecount=0;

book(string t,float p,int pc):publication(t,p)


{

pagecount=pc;

}
void getData() {
publication :: getData();
cout<<"Enter Pagecount\n";
cin>>pagecount;
}

void putData()
{

cout<<"title : "<<title<<endl;
cout<<"Price : "<<price<<endl;

cout<<"Pagecount :"<<pagecount<<endl;

bool isOversize(){
if(pagecount > 800){
return true;
}
}

};

class Tape : public publication


{
float time;
public:
Tape()
{
time=0.0;

Tape(string t,float p,float tim):publication(t,p)


{

time=tim;

void putData()
{
cout<<"title : "<<title<<endl;
cout<<"Price : "<<price<<endl;

cout<<"time in minutes :"<<time<<endl;

}
void getData() {
publication :: getData();
cout<<"Enter Time\n";
cin>>time;
}

bool isOversize(){
if(time > 90){
return true;
}
}

};

int main()
{
cout<<endl<<"Book data"<<endl;
book b;
b.getData();
b.putData();
cout<<endl;
if(b.isOversize()){
cout<<"Book is Oversized"<<endl;
}
cout<<endl;
Tape t;
t.getData();
t.putData();
cout<<endl;
if(t.isOversize()){
cout<<"Tape is Oversized";
}
return 0;
}
Q2
#include <iostream>
#include<string>
using namespace std;

class father
{
protected:
int age;
public:
father (int x)
{
age= x;
}
virtual void iam()
{
cout<<"I AM THE FATHER, my age is "<<age<<endl;
}
};

class son : public father {


public:
son (int x) : father(x)
{

virtual void iam()


{
cout<<"I AM THE SON, my age is "<<age<<endl;
}
};

class daughter : public father {

public:
daughter (int x) : father(x)
{

virtual void iam()


{
cout<<"I AM THE DAUGHTER, my age is "<<age<<endl;
}
};

int main()
{
son s(13);
s.iam();
cout<<endl;
daughter d(24);
d.iam();
return 0;
}
Q4
#include<iostream>
using namespace std;
class Department
{
public:
int deptID;
string deptName;
Department(){}
Department(int id,string name)
{
deptID=id;
deptName=name;
}
void display()
{
cout<<"Department ID:"<<deptID<<endl;
cout<<"Department Name:"<<deptName<<endl;
}
};
class University
{
public:
string universityName;
string location;
Department dept;
};
class Laboratory
{
public:
int labID;
int experimentNo;
Laboratory(){}
Laboratory(int id,int no)
{
labID=id;
experimentNo=no;
}
};
class Person
{
public:
string name;
int age;
Person(){}
Person(string nm,int ag)
{
name=nm;
age=ag;
}
void display()
{
cout<<"Person name:"<<name<<endl;
cout<<"Person age:"<<age<<endl;
}
};
class Professor:public Person
{
public:
string profName;
Department dept;
Professor(){}
Professor(string n,Department d)
{
profName=n;
dept=d;
}
};
class Researcher:public Professor
{
public:
Laboratory lab;
Researcher(Laboratory l)
{
lab=l;
}
};
int main()
{
return 0;
}

Q6

Errors:-

private key word should be in the class

opposite opparands are used after cin

wring opprands are used after cout

anything cannot directly assign to funtion definition

statement endl shoud be end with ; instead of :

inheritance systax is wrong

super method syntax is wrong

private key word should be in the class

opposite opparands are used after cin

wring opprands are used after cout

anything cannot directly assign to funtion definition

statement endl shoud be end with ; instead of :

inheritance systax is wrong

super method syntax is wrong

variable name syntax error

variable before datatype

semicoln in between statements

You might also like