Sie sind auf Seite 1von 31

OOP ASSIGNMENT 2

Name Muhammad Umair


Roll No 19F-0952
Section BSSE-3B
Question 1
using namespace std;
class Book
{
int Id;
string Name;
string Authur;
int Edition;
string DatePublish;
public:
Book();
int getId();
void Name();
void Authur();
void Edition();
void DateofPublish1();
string getName();
string getAuthur();
int getEdition();
string dateofpublish();
};
void sort(Book *arr,int size);

CPP File
#include<iostream>

#include<cstdlib>

#include<cstring>

#include "bookdata1.h"

using namespace std;

using namespace std;

Book::Book()

Id=rand();

int Book::getId()

return Id;

void Book::Name()

cout<<"Enter Name ";

cin>>Name;

void Book::Authur()

cout<<"Enter Authur ";

cin>>Authur;

void Book::Edition()

{
cout<<"Enter Edition ";

cin>>Edition;

void Book::DateofPublish1()

cout<<"Enter Date of publish ";

cin>>DatePublish;

string Book::getName()

return Name;

string Book::getAuthur()

return Authur;

int Book::getEdition(){

return Edition;

string Book::dateofpublish(){

return DatePublish;

void sort(Book *arr,int size){

Book temp;

for(int i=0;i<size-1;i++){

for(int j=0;j<size-i-1;j++){

if(arr[j].dateofpublish()>arr[j+1].dateofpublish()){

temp=arr[j];
arr[j]=arr[j+1];

arr[j+1]=temp;

int databook()

int n;

Book *b;

cout<<"Enter Number Of Books ";

cin>>n;

b=new Book[n];

for(int i=0;i<n;i++)

system("cls");

cout<<"Enter Detail of Book "<<i+1<<endl;

b[i].setName();

b[i].setAuthur();

b[i].setEdition();

b[i].setDateOfPublish();

sort(b,n);

if(n>5)

n=5;

else

cout<<"Not display because you enter less then 5"<<endl;

for(int i=0;i<5;i++)

{
cout<<"Detail of Book "<<i+1<<endl;

cout<<"Id "<<b[i].getId()<<endl;

cout<<"Name "<<b[i].getName()<<endl;

cout<<"Authur "<<b[i].getAuthur()<<endl;

cout<<"Edition "<<b[i].getEdition()<<endl;

cout<<"Date of publish "<<b[i].dateofpublish()<<endl;

Main File
#include<iostream>
#include "books.cpp"
using namespace std;
int main()
{
bookdata();
}Output

using namespace std;


class course
{
string courseId;
string courseName;
int creditHour;
int semsterno;
public:
void courseId();
void courseName();
void creditHour();
void semster();
string getcourseId();
string getcourseName();
int getcreditHour();
int getsem();
};

course *crs;
class student
{
string reg_no;
string name;
int semster;
string cnic;
string address;

public:
int num;
course *c;
void course1();
void reg1();
void name1();
void setsemster();
void setcnic();
void setaddress();
string getreg();
string getname();
int getsemster();
string getcnic();
string getaddress();
void getcourse();
};
void registorStudent();
student search();
void registorCourse();
void update();
void drop();
void delete1();
void getlist();

CPP File
#include<iostream>
#include<cstdlib>
#include "coures.h"
using namespace std;
int scount;
int ccount;

void course::courseId()
{
cout<<"Enter Course ID ";
cin>>courseId;
}
void course::courseName()
{
cout<<"Enter Course Name ";
cin>>courseName;
}
void course::creditHour()
{
cout<<"Enter Credit Hour ";
cin>>creditHour;
}
void course::semster()
{
cout<<"Enter Sem: ";
cin>>semsterno;
}
string course::getcourseId(){
return courseId;
}
string course::getcourseName(){
return courseName;
}
int course::getcreditHour(){
return creditHour;
}
int course::getsem(){
return semsterno;
}

void student::course1(){
cout<<"Enter number of course you want to enter(between 3 and 5): ";
cin>>num;
c=new course[num];
int j=0;
for(int i=0;i<ccount;i++){
if(crs[i].getsem()==semster)
{
c[j]=crs[i];
j++;
}
}
}
void student::reg1(){
cout<<"Enter Reg: ";
cin>>reg_no;
}
void student::name1(){
cout<<"Enter Name: ";
cin>>name;
}
void student::setsemster()
{
cout<<"Enter Semster ";
cin>>semster;
}
void student::setcnic(){
cout<<"Enter cnic: ";
cin>>cnic;
}
void student::setaddress(){
cout<<"Enter address: ";
cin>>address;
}
string student::getreg(){
return reg_no;
}
string student::getname(){
return name;
}
int student::getsemster(){
return semster;
}
string student::getcnic(){
return cnic;
}
string student::getaddress(){
return address;
}
void student::getcourse(){
for(int i=0;i<num;i++){
cout<<"detail of course "<<i+1<<endl;
cout<<"Credit hour"<<c[i].getcourseId()<<endl;
cout<<"Credit hour"<<c[i].getcourseName()<<endl;
cout<<"Credit hour"<<c[i].getcreditHour()<<endl;
}
}
student *s;
void registorStudent(){
int num;
cout<<"Enter number of student you want to enter: ";
cin>>num;
scount=num;
s=new student[num];
for(int i=0;i<num;i++){
cout<<"Enter detail of student "<<i+1<<endl;
s[i].reg1();
s[i].name1();
s[i].setcnic();
s[i].setaddress();
s[i].course1();
s[i].setsemster();

}
}

student search(){
string id;
cout<<"enter student id: ";
cin>>id;
for(int i=0;i<scount;i++){
if(s[i].getreg()==id){
return s[i];
}
}
}
void registorCourse(){
int num;
cout<<"Enter number of student you want to enter: ";
cin>>num;
crs=new course[num];
ccount=num;
for(int i=0;i<num;i++){
cout<<"Enter detail of student "<<i+1<<endl;
crs[i].courseId();
crs[i].courseName();
crs[i].creditHour();
crs[i].semster();

}
}
void update(){
student s1=search();
s1.reg1();
s1.name1();
s1.setcnic();
s1.setaddress();
s1.course1();
s1.setsemster();
}
void drop(){
string id;
cout<<"Enter course id: ";
cin>>id;
for(int i=0;i<ccount;i++){
if(crs[i].getcourseId()==id){
for(int j=i;j<ccount-1;j++){
crs[i]=crs[i+1];
}
ccount--;
}
}
}
void delete1(){
string id;
cout<<"Enter course id: ";
cin>>id;
for(int i=0;i<scount;i++){
if(s[i].getreg()==id){
for(int j=i;j<scount-1;j++){
s[i]=s[i+1];
}
scount--;
}
}
}
void getlist(){
string c;
cout<<"Enter courseName: ";
cin>>c;

for(int i=0;i<scount;i++){
int flag=0;
for(int j=0;j<s[i].num;j++){
if(s[i].c[j].getcourseName()==c)
{
flag=1;
}
}
if(flag){
cout<<"Name: "<<s[i].getname();
cout<<"Cnic: "<<s[i].getcnic();
cout<<"address: "<<s[i].getaddress();
cout<<"sem: "<<s[i].getsemster();
cout<<"rag: "<<s[i].getreg();

}
}
}
int coursestudentdata()
{

int n;
do
{
cout<<"1 for Register Student"<<endl;
cout<<"2 for Register Courses"<<endl;
cout<<"3 for Drop Courses"<<endl;
cout<<"4 for Update Record"<<endl;
cout<<"5 for Delete a Student" <<endl;
cout<<"6 for Search a Student "<<endl;
cout<<"7 for Get a list of students (Studying a specific course together)"<<endl;
cout<<"8 quit"<<endl;
cout<<"enter your choice: ";
cin>>n;
switch(n)
{
if (n == 1)
{
registorStudent();
}
else if (n == 2)
{
registorCourse();
}
else if (n == 3)
{
drop();
}
else if (n == 4)
{
update();
}
else if (n == 5)
{
delete1();
}
else if (n == 6)
{
search();
}
else if (n == 7)
{
getlist();

}
}
}while(n!='8');
}

Main
#include<iostream>
#include "course1.cpp"
using namespace std;
int main()
{
coursestudentdata();
}

Output
Question 3
using namespace std;
class Employee{
const int id=1;
string name;
float salryperhour;
int monthlyWorkedHours;
float taxPaid;
string yearofjoining;
public:
Employee();
void setname(string n);
void setsal(float sal);
void setmont(int m);
void settax(float t);
void setyear(string y);
string getname();
float getsal();
int getmonth();
float gettax();
string getyear();
int getid();
};
void updatehour();
void changesal();
int issenior(Employee e1);
float calculate();
void slip();

CPP File
#include<iostream>
#include "emp.h"
using namespace std;

Employee::Employee(){
name="William";
salryperhour=2000;
monthlyWorkedHours=244;
taxPaid=0.1;
yearofjoining="12-2-2005";
}
void Employee::setname(string n){
name=name;
}
void Employee::setsal(float sal){
salryperhour=sal;
}
void Employee::setmont(int m){
monthlyWorkedHours=m;
}
void Employee::settax(float t){
taxPaid=t;
}
void Employee::setyear(string y){
yearofjoining=y;
}
string Employee::getname(){
return name;
}
float Employee::getsal(){
return salryperhour;
}
int Employee::getmonth(){
return monthlyWorkedHours;
}
float Employee::gettax(){
return taxPaid;
}
string Employee::getyear(){
return yearofjoining;
}
int Employee::getid(){
return id;
}
Employee e;
void updatehour(){
int hour,id;
cout<<"hours of employee work today ";
cin>>hour;
hour+=e.getmonth();
e.setmont(hour);
}
void changesal(){
float hour;
cout<<"enter new salary of employee ";
cin>>hour;
e.setsal(hour);

}
int issenior(Employee e1){
string ch="12-11-2015";
if(e1.getyear()<ch){
return 1;
}
else
return 0;
}
float calculate(){
float sal;
sal=e.getmonth()*e.getsal();
sal=sal-1000-(sal*0.1);
if(issenior(e)){
sal=sal+(sal*0.1);
}
return sal;
}

void slip(){
cout<<"Reciept"<<endl;
cout<<"Name "<<e.getname()<<endl;
cout<<"Salary "<<calculate()<<endl;
}
int working(){
int ch;
do{
cout<<"1 for update hours "<<endl;
cout<<"2 for change salary"<<endl;
cout<<"3 for calculate"<<endl;
cout<<"4 for slip"<<endl;
cout<<"enter choice: ";
cin>>ch;
switch(ch)
{
case 1:
updatehour();
break;
case 2:
changesal();
break;
case 3:
calculate();
break;
case 4:
slip();
}
}while(ch!=4);
}

Main
#include<iostream>
#include "employee.cpp"
using namespace std;
int main()
{
working();
}

Output
Question 4
using namespace std;
class messeges
{
string sent;
string recieved;
public:
messeges();
void setsent(string s);
void setrecieve(string r);
string getsent();
string getrec();

};
class chat
{
string name;
string contactNo;
public:
messeges *s=new messeges[10];
messeges *r=new messeges[10];
void setname();
void setContact();
string getname();
string getContact();
void setr(string r1);
};
chat c[5];
chat cur;
void curr();
int num1=5;
void send();
void viewr();
void empty();
void update();
int check();
void set();

CPP File
#include "messages.h"
using namespace std;
messeges::messeges()
{
sent = " ";
recieved = " ";
}
void messeges::setsent(string s)
{
sent=s;
}
void messeges::setrecieve(string r){
recieved=r;
}
string messeges::getsent()
{
return sent;
}
string messeges::getrec()
{
return recieved;
}

void chat::setname(){
cout<<"Enter Name: ";
cin>>name;
}
void chat::setContact()
{
cout<<"Enter contact number: ";
cin>>contactNo;
}
string chat::getname()
{
return name;
}
string chat::getContact()
{
return contactNo;
}
void chat::setr(string r1)
{
for(int i=0;i<10;i++){
if(r[i].getrec()==""&&r[i].getsent()=="")
{
r[i].setrecieve(r1);
}
}

void curr()
{
string num;
cout<<"Enter your contact ";
cin>>num;
for(int i=0;i<5;i++)
{
if(num==c[i].getContact())
{
cur=c[i];
break;
}
}
}

void send()
{
string num;
cout<<"Enter contact number ";
cin>>num;
for(int i=0;i<5;i++)
{
if(num==c[i].getContact())
{
string mess;
cout<<"Enter messege ";
cin>>mess;
c[i].setr(mess);

}
}
}
void viewr()
{
for(int i=0;i<10;i++)
{
cout<<i+1<<" "<<cur.r[i].getrec()<<endl;
}
}
void empty()
{
cur.r=new messeges[10];
cur.s=new messeges[10];
}

int check(){
int num=10;
for(int i=0;i<10;i++)
{
if(cur.r[i].getrec()!=" "&&cur.r[i].getsent()!=" ")
{
num--;
}
}
return num;

}
void set()
{
for(int i=0;i<5;i++)
{
c[i].setname();
c[i].setContact();
}
}
int message1()
{
int ch;
set();
do{
cout<<"1 for send messege"<<endl;
cout<<"2 for view messege"<<endl;
cout<<"3 for empty messege"<<endl;
cout<<"4 for update messege"<<endl;
cout<<"5 for memory check"<<endl;
cout<<"Enter choice ";
cin>>ch;
switch(ch)
{
case 1:
send();
break;
case 2:
viewr();
break;
case 3:
empty();
break;
case 4:
update();
break;
case 5:
cout<<"you have "<<check()<<" no
message";
break;
}
}
while(ch!=6);
}

Main
#include<iostream>
#include "messages1.cpp"
using namespace std;
int main()
{
message1();
}

Output

Das könnte Ihnen auch gefallen