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

Lab Task 5

Uploaded by

nabil.furious
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Lab Task 5

Uploaded by

nabil.furious
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Problem 1

#include <iostream>

using namespace std;

class Person {

private:

string name;

int age;

public:

void setName(string newName) {

name = newName;

void setAge(int newAge) {

age = newAge;

void displayInfo() {

cout << "Name: " << name << std::endl;

cout << "Age: " << age << std::endl;

};

int main() {

Person person;

person.setName("Rahim");

person.setAge(25);

person.displayInfo();

return 0;

}
Problem 2

#include <iostream>

using namespace std;

class BankAccount {

private:

string accountNumber;

string accountHolder;

double balance;

public:

BankAccount(string number,string holder,double initialBalance) {

accountNumber = move(number);

accountHolder = move(holder);

balance = initialBalance;

void deposit(double amount) {

if (amount > 0) {

balance += amount;
cout << "Deposit of $" << amount << " successful.\n";

} else {

cout << "Invalid deposit amount.\n";

void withdraw(double amount) {

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

balance -= amount;

cout << "Withdrawal of $" << amount << " successful.\n";

} else {

cout << "Invalid withdrawal amount or insufficient funds.\n";

void displayBalance() {

cout << "Account Number: " << accountNumber << "\n";

cout << "Account Holder: " << accountHolder << "\n";

cout << "Balance: $" << balance << "\n";

};

int main() {

BankAccount account("123456789", "Rahim", 1000);

account.deposit(500);

account.displayBalance();

cout<<endl;

account.withdraw(200);

account.displayBalance();

cout<<endl;

account.withdraw(1000);

account.displayBalance();
cout<<endl;

return 0;

Problem 3

#include <iostream>

using namespace std;

class Student {

private:

string name_;

int rollNumber_;

int marks_;

public:

Student(string name, int rollNumber, int marks = 0) {

name_ = name;

rollNumber_ = rollNumber;

marks_ = marks;

}
void setName(string name) {

name_ = name;

void setRollNumber(int rollNumber) {

rollNumber_ = rollNumber;

void displayInfo(){

cout<<"Student information: "<<endl;

cout << "Name: " << name_ << endl;

cout << "Roll Number: " << rollNumber_ <<endl;

};

int main() {

Student student("Rahim",20);

student.displayInfo();

return 0;

}
Problem 4

#include <iostream>

using namespace std;

class Book{

private:

string title;

string author;

int publicationYear;

public:

void setDetails(string bookTitle,string bookAuthor,int year){

title = bookTitle;

author = bookAuthor;

publicationYear = year;

void DisplayDetails(){

cout<<"Title: "<<title<<endl;

cout<<"Author: "<<author<<endl;

cout<<"Publication year: "<<publicationYear<<endl;

};

int main(){

Book myBook;

myBook.setDetails("The Great Gatsby","F. Scott Fitzgerald",1925);

myBook.DisplayDetails();

return 0;

}
Problem 5

#include <iostream>

using namespace std;

class Car {

private:

string make;

string model;

int year;

public:

void setMake(string carMake) {

make = carMake;

void setModel(string carModel) {

model = carModel;

void setYear(int carYear) {

year = carYear;

}
void DisplayCarInfo() {

cout << "Make: " << make << endl;

cout << "Model: " << model << endl;

cout << "Year: " << year << endl;

};

int main() {

Car myCar;

myCar.setMake("Toyota");

myCar.setModel("Camry");

myCar.setYear(2023);

cout << "Car Information:" << endl;

myCar.DisplayCarInfo();

return 0;

Problem 6

#include <iostream>
using namespace std;

class TimeConverter {

private:

int hours;

int minutes;

int seconds;

public:

void SetTime(int h, int m, int s) {

hours = h;

minutes = m;

seconds = s;

int ConvertToTotalSeconds() {

return (hours * 3600) + (minutes * 60) + seconds;

};

int main() {

TimeConverter myTime;

myTime.SetTime(1, 32, 10);

int totalSeconds = myTime.ConvertToTotalSeconds();

cout << "Total seconds: " << totalSeconds << std::endl;

return 0;

You might also like