ASSIGNMENT 1 OOP LAB
ASSIGNMENT 1 OOP LAB
Objective:
Create a class Circle that represents a circle. The class should have:
- A public member function getArea() to calculate and return the area of the circle.
#include <iostream>
class Circle
private:
int radius;
public:
void setradius(int r)
radius = r;
float getarea()
return (3.14*radius*radius);
void displayarea()
};
int main()
Circle c;
c.setradius(5);
c.getarea();
c.displayarea();
return 0;
Objective:
- Public member functions setDimensions() to set the length and width of the rectangle.
#include <iostream>
class Rectangle
private:
public:
width = w;
length = l;
float calculateArea()
return (length*width);
}
void displayArea()
};
int main()
Rectangle c;
c.setDimensions(5,7);
c.calculateArea();
c.displayArea();
return 0;
Objective:
Create a BankAccount class that simulates a simple bank account. The class should have:
#include <iostream>
class BankAccount
private:
int balance;
public:
BankAccount()
balance = 0;
}
void deposit()
int amount;
cin>>amount;
if (amount > 0)
balance += amount;
cout<<"Deposited: "<<amount<<endl;
} else
void withdraw()
int amount;
cin>>amount;
balance -= amount;
cout<<"Withdrawn: "<<amount<<endl;
cout<<"Insufficient balance!"<<endl;
} else
}
}
void getBalance()
};
int main()
BankAccount c;
c.deposit();
c.withdraw();
c.getBalance();
return 0;
Objective:
Define a class Student that stores and displays student information. The class should have:
#include <iostream>
class Student
private:
string name;
int rollno,marks;
public:
void setData()
{
cin>>name;
cin>>rollno;
cin>>marks;
void displayData()
};
int main()
Student s;
s.setData();
s.displayData();
return 0;
Objective:
Create a class TimeDuration that stores a time duration in hours, minutes, and seconds. The class
should have:
class TimeDuration
private:
int hrs,mints,sec;
public:
void setTime()
cin>>hrs;
cin>>mints;
hrs = hrs+mints/60;
mints = mints%60;
cin>>sec;
mints = mints+sec/60;
sec = sec%60;
void dispalyTime()
};
int main()
TimeDuration t;
t.setTime();
t.dispalyTime();
return 0;