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

ASSIGNMENT 1 OOP LAB

The document contains multiple class definitions in C++ for various objects including Circle, Rectangle, BankAccount, Student, and TimeDuration. Each class has private data members and public member functions to set values, calculate areas, and display information. The main function for each class demonstrates its usage by creating an instance and invoking its methods.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

ASSIGNMENT 1 OOP LAB

The document contains multiple class definitions in C++ for various objects including Circle, Rectangle, BankAccount, Student, and TimeDuration. Each class has private data members and public member functions to set values, calculate areas, and display information. The main function for each class demonstrates its usage by creating an instance and invoking its methods.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Name: Ahmad Ibrahim

Roll No: BSCS51F24S047


OOP LAB ASSIGNMENT NO.1
/**1. Problem Statement: Circle Class

Objective:

Create a class Circle that represents a circle. The class should have:

- A private data member radius to store the radius of the circle.

- A public member function setRadius() to set the radius.

- A public member function getArea() to calculate and return the area of the circle.

- A public member function displayArea() to display the area of the circle.*/

#include <iostream>

using namespace std;

class Circle

private:

int radius;

public:

void setradius(int r)

radius = r;

float getarea()

return (3.14*radius*radius);

void displayarea()

cout<<"Area is: "<<getarea();

};
int main()

Circle c;

c.setradius(5);

c.getarea();

c.displayarea();

return 0;

/**2. Problem Statement: Rectangle Class

Objective:

Design a class Rectangle to represent a rectangle. The class should include:

- Private data members length and width.

- Public member functions setDimensions() to set the length and width of the rectangle.

- Public member function calculateArea() to compute and return the area.

- Public member function displayArea() to display the area of the rectangle.*/

#include <iostream>

using namespace std;

class Rectangle

private:

int length, width;

public:

void setDimensions(int l, int w)

width = w;

length = l;

float calculateArea()

return (length*width);

}
void displayArea()

cout<<"Area is: "<<calculateArea();

};

int main()

Rectangle c;

c.setDimensions(5,7);

c.calculateArea();

c.displayArea();

return 0;

/**3. Problem Statement: BankAccount Class

Objective:

Create a BankAccount class that simulates a simple bank account. The class should have:

- A private data member balance.

- Public member functions:

- deposit() to deposit money into the account.

- withdraw() to withdraw money from the account.

- getBalance() to return the current balance.*/

#include <iostream>

using namespace std;

class BankAccount

private:

int balance;

public:

BankAccount()

balance = 0;
}

void deposit()

int amount;

cout<<"Enter deposit amount: ";

cin>>amount;

if (amount > 0)

balance += amount;

cout<<"Deposited: "<<amount<<endl;

} else

cout<<"Invalid deposit amount!"<<endl;

void withdraw()

int amount;

cout<<"Enter amount to withdraw: ";

cin>>amount;

if (amount > 0 && amount <= balance)

balance -= amount;

cout<<"Withdrawn: "<<amount<<endl;

} else if (amount > balance)

cout<<"Insufficient balance!"<<endl;

} else

cout<<"Invalid withdrawal amount!"<<endl;

}
}

void getBalance()

cout<<"Available balance is: "<<balance;

};

int main()

BankAccount c;

c.deposit();

c.withdraw();

c.getBalance();

return 0;

/**4. Problem Statement: Student Class

Objective:

Define a class Student that stores and displays student information. The class should have:

- Private data members name, rollNo, and marks.

- Public member functions:

- setData() to input student details (name, roll number, and marks).

- displayData() to display the student's information.*/

#include <iostream>

using namespace std;

class Student

private:

string name;

int rollno,marks;

public:

void setData()
{

cout<<"Enter Name of Student: ";

cin>>name;

cout<<"Enter Roll no. of Student: ";

cin>>rollno;

cout<<"Enter marks of Student: ";

cin>>marks;

void displayData()

cout<<"Name of Student is: "<<name;

cout<<"\nRoll No. of Student is: "<<rollno;

cout<<"\nMarks of Student is: "<<marks;

};

int main()

Student s;

s.setData();

s.displayData();

return 0;

/**5. Problem Statement: TimeDuration Class

Objective:

Create a class TimeDuration that stores a time duration in hours, minutes, and seconds. The class
should have:

- Private data members hours, minutes, and seconds.

- Public member functions:

- setTime() to set the values for hours, minutes, and seconds.

- displayTime() to display the time in hh:mm:ss format.*/


#include <iostream>

using namespace std;

class TimeDuration

private:

int hrs,mints,sec;

public:

void setTime()

cout<<"Enter hours: ";

cin>>hrs;

cout<<"Enter minutes: ";

cin>>mints;

if(mints >= 60)

hrs = hrs+mints/60;

mints = mints%60;

cout<<"Enter seconds: ";

cin>>sec;

if(sec >= 60)

mints = mints+sec/60;

sec = sec%60;

void dispalyTime()

cout<<"Time is: "<<hrs<<":"<<mints<<":"<<sec;

};
int main()

TimeDuration t;

t.setTime();

t.dispalyTime();

return 0;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy