0% found this document useful (0 votes)
16 views

Assignment 1 2

The document contains code for several C++ classes implementing object-oriented programming concepts like encapsulation, inheritance, polymorphism etc. It includes classes for a Person, Bank Account, Rectangle, Student, Employee, Circle, Library, Temperature Converter, Song and Student Record. The code demonstrates creating objects of these classes, setting and getting attributes, defining methods and calling methods to perform operations.

Uploaded by

thorlogics
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Assignment 1 2

The document contains code for several C++ classes implementing object-oriented programming concepts like encapsulation, inheritance, polymorphism etc. It includes classes for a Person, Bank Account, Rectangle, Student, Employee, Circle, Library, Temperature Converter, Song and Student Record. The code demonstrates creating objects of these classes, setting and getting attributes, defining methods and calling methods to perform operations.

Uploaded by

thorlogics
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Shaheed Zulfikar Ali Bhutto Institute of Science & Technology University

COMPUTER SCIENCE DEPARTMENT

Total Marks:

Obtained Marks:

Oop lab

Submitted To: Sir Shahid Raza

Student Name: Mohammad Sarib

Reg. Number: 2280261


Shaheed Zulfikar Ali Bhutto Institute of Science & Technology University
COMPUTER SCIENCE DEPARTMENT

#include<iostream>
using namespace std;
class person{
private:
string name;
int age;
string address;
public:
person(){
name="";
age=19;
address="";
}
void info(string name,int age , string address){
this->name=name;
this->age=age;
this->address=address;
}
void display(){
cout<<name<<endl;
cout<<age<<endl;
cout<<address<<endl;
}
};
int main(){
person p;
p.info("sarib",19,"cvucxw");
p.display();
}
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology University

#include<iostream>
using namespace std;
class bankaccount{
private:
int acc_no;
int balance;
public:
bankaccount(){
balance = 10000;
acc_no=123;
}
void deposit(int amount){
if(amount>0){
balance+=amount;
cout<<amount<<endl;
}else{
cout<<"invalid"<<endl;
}
}
void withdraw(int amount){
if(amount>0 && amount<=balance){

balance-=amount;
cout<<amount<<endl;
}else {
cout<<"invalid"<<endl;
}
}
void display (){
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology University
cout<<acc_no<<endl;
cout<<balance<<endl;
}
};
int main(){
bankaccount b;

b.deposit(10000);
b.display();
b.withdraw(5000);
b.display();
}

#include<iostream>
using namespace std;

class rectangle{
private:
int length;
int width;
public:
void calarea(int length,int width){

cout<<length*width;
}
};
int main(){
rectangle r;
r.calarea(5,6);
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology University
}

#include<iostream>

using namespace std;

class student{
private:
string name;
int roll_no;
char grade;
public:
student(string name,int roll_no,char
grade):name(name),roll_no(roll_no),grade(grade){

}
void upgrade(char grad){
if(grad>='A' && grad <='B'){
cout<<grad<<endl;
}else{
cout<<"invalid"<<endl;
}
}
void display(){
cout<<name<<endl;
cout<<roll_no;
cout<<grade<<endl;
}
};
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology University
int main(){
student stud("babar azam",56,'B');

stud.upgrade('A');
stud.display();
}

#include<iostream>

using namespace std;


class empolyee{
private:
int employee_id;
string name;
int salary;
public:
empolyee(string name,int employee_id,int
salary):name(name),employee_id(employee_id),salary(salary){

}
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology University
void raise(int amount){
if(amount>0){
salary+=amount;
cout<<amount;
}
}
void display(){
cout<<name<<endl;
cout<<employee_id<<endl;
cout<<salary<<endl;
}
};
int main(){
empolyee emp("babar azam",124,50000);

emp.raise(9000);
emp.display();
}

#include<iostream>
using namespace std;

class circle{
private:
double radius;
public:
circle(double r){
radius =r;
}
double calcircumference(){
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology University
return 2*3.14*radius;
}
};
int main(){
circle c1(5.6);

double circumference=c1.calcircumference();
cout<<circumference<<endl;
}

#include<iostream>
#include<string>
using namespace std;

class libarary{
private:
string booktitle;
string author;
public:
libarary(string booktitle,string
author):booktitle(booktitle),author(author){

}
void display(){
cout<<booktitle<<endl;
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology University
cout<<author<<endl;
}

};
int main(){
libarary l("world","maxwell");

l.display();
}

#include <iostream>
using namespace std;
class TemperatureConverter {
private:
double celsiusTemperature;

public:

TemperatureConverter(double celsiusTemp) :
celsiusTemperature(celsiusTemp) {}

double convertToFahrenheit() {
return (celsiusTemperature * 9 / 5) + 32;
}
};

int main() {
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology University
TemperatureConverter converter(25.0);

double fahrenheitTemp = converter.convertToFahrenheit();


cout << fahrenheitTemp <<endl;

return 0;
}

#include<iostream>
#include<string>
using namespace std;

class song{
private:
string title;
string artist;
float duration;
public:
void settitle(string title){
this->title=title;
}
void setartist(string artist){
this->artist=artist;
}
void setduration(float duration){
this->duration=duration;
}
string gettitle(){
return title;
}
string getartist(){
return artist;
}
float getduration(){
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology University
return duration;
}
};
int main(){
song s;
s.setartist("bilal saeed");
s.settitle("baari");
s.setduration(2.5);
cout<<s.getartist()<<endl;
cout<<s.gettitle()<<endl;
cout<<s.getduration()<<endl;
}

#include <iostream>
#include <string>
using namespace std;
class StudentRecord {
private:
string studentName;
int studentID;
char grade1;
char grade2;
char grade3;

public:

StudentRecord(string name, int id)


: studentName(name), studentID(id), grade1('A'), grade2('B'),
grade3('C') {}

void setGrades(int g1, int g2, int g3) {


grade1 = g1;
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology University
grade2 = g2;
grade3 = g3;
}

void displayRecord() {
cout << studentName <<endl;
cout << studentID << endl;
cout << grade1 << ", " << grade2 << ", " << grade3 << endl;
}
};

int main() {

StudentRecord student("BABAR AZAM", 12345);

student.setGrades('A', 'B', 'C');

student.displayRecord();

return 0;
}
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology University
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology University
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology University
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology University
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology University

You might also like