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

Question No.1

The document contains code for three C++ programs that demonstrate object-oriented programming concepts. Program 1 defines classes for vehicles, cars, bikes, and specific models that inherit from the parent classes and overload functions to get and print vehicle data. Program 2 defines a Zakat class to calculate religious alms tax based on a static rate and balances over a threshold. Program 3 defines a BankAccount class to manage accounts with functions for input, deposit, withdraw, display and generating account numbers.

Uploaded by

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

Question No.1

The document contains code for three C++ programs that demonstrate object-oriented programming concepts. Program 1 defines classes for vehicles, cars, bikes, and specific models that inherit from the parent classes and overload functions to get and print vehicle data. Program 2 defines a Zakat class to calculate religious alms tax based on a static rate and balances over a threshold. Program 3 defines a BankAccount class to manage accounts with functions for input, deposit, withdraw, display and generating account numbers.

Uploaded by

Ahsan Sandhu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Question No.

1
#include<iostream>

using namespace std;

class Vehicle{

protected:

int price;

string mileage;

public:

void Get_Data()

cout<<"Enter Price: ";

cin>>price;

cout<<"Enter Mileage";

cin>>mileage;

void Print_Data()

cout<<"Enter Price: "<<price;

cout<<"Enter Mileage"<<mileage;

};

class Car : public Vehicle{

protected:

int Ownership_Cost;

float Warranty;

string Fuel_Type;

int Seats;

public:
void Get_Data()

Vehicle :: Get_Data();

cout<<"Enter Ownership Cost: ";

cin>>Ownership_Cost;

cout<<"Enter Warranty: ";

cin>>Warranty;

cout<<"Enter Fuel Type: ";

cin>>Fuel_Type;

cout<<"Enter No. of Seats:";

cin>>Seats;

void Print_Data()

Vehicle :: Print_Data();

cout<<"Ownership Cost: "<<Ownership_Cost;

cout<<"Warranty: "<<Warranty;

cout<<"Fuel Type: "<<Fuel_Type;

cout<<"No. of Seats:"<<Seats;

};

class Bike : public Vehicle{

private:

int No_Cylenders;

int Gears;

string Cooling_Type;

string Wheel_type;

float FT_Size;

public:
void Get_Data()

Vehicle :: Get_Data();

cout<<"Enter No of Cylenders: ";

cin>>No_Cylenders;

cout<<"Enter No. of Gears: ";

cin>>Gears;

cout<<"Enter Cooling Type: ";

cin>>Cooling_Type;

cout<<"Enter Wheel Type: ";

cin>>Wheel_type;

cout<<"Enter Fuel Tank Size: ";

cin>>FT_Size;

void Print_Data()

Vehicle :: Print_Data();

cout<<"No of Cylenders: "<<No_Cylenders;

cout<<"No. of Gears: "<<Gears;

cout<<"Cooling Type: "<<Cooling_Type;

cout<<"Wheel Type: "<<Wheel_type;

cout<<"Fuel Tank Size: "<<FT_Size;

};

class Audi : public Car{

private:

string Model;

public:

void Get_Data()
{

Car :: Get_Data();

cout<<"Enter Model of Car: ";

cin>>Model;

void Print_Data()

Car :: Print_Data();

cout<<"Model of Car: "<<Model;

};

class Ford : public Car{

private:

string Model;

public:

void Get_Data()

Car :: Get_Data();

cout<<"Enter Model of Car: ";

cin>>Model;

void Print_Data()

Car :: Print_Data();

cout<<"Model of Car: "<<Model;

};

class TVS : public Bike{

private:
string Make_Type;

public:

void Get_Data()

Bike :: Get_Data();

cout<<"Enter Make of Bike: ";

cin>>Make_Type;

void Print_Data()

Bike :: Print_Data();

cout<<"Make of Bike: "<<Make_Type;

};

class Bajaj : public Bike{

private:

string Make_Type;

public:

void Get_Data()

Bike :: Get_Data();

cout<<"Enter Make of Bike: ";

cin>>Make_Type;

void Print_Data()

Bike :: Print_Data();

cout<<"Make of Bike: "<<Make_Type;

}
};

int main()

cout<<"\n\n For Car:";

cout<<"\n For Audi:\n\n";

Audi A;

A.Get_Data();

A.Print_Data();

cout<<"\n\n For Ford:\n\n";

Ford F;

F.Get_Data();

F.Print_Data();

cout<<"\n\n For Bike:";

cout<<"\n For TVS:\n\n";

TVS T;

T.Get_Data();

T.Print_Data();

cout<<"\n\n For Bajaj:\n\n";

Bajaj B;

B.Get_Data();

B.Print_Data();

return 0;

Program No 2

#include<iostream>

using namespace std;

class zakat{

private:
string owner_name;

double total_amount;

static float zakat_rate;

public:

zakat()

owner_name="NULL";

total_amount=0;

zakat(string name,double amount)

owner_name=name;

total_amount=amount;

void calzakat()

double zakat_amount;

if(total_amount>100000)

zakat_amount=(total_amount * zakat_rate ) / 100;

cout<<"Zakat amount= "<<zakat_amount<<endl;

else

cout<<"Zakat is not included"<<endl;

};
float zakat::zakat_rate=2.5;

int main()

zakat obj1,obj2("Ahsan",100001),obj3(obj2);

cout<<"Zakat for default constructor"<<endl;

obj1.calzakat();

cout<<"Zakat for two argument constructor"<<endl;

obj2.calzakat();

cout<<"Zakat for copy constructor"<<endl;

obj3.calzakat();

return 0;

PROGRAM 3

#include<iostream>

using namespace std;

class bankaccount{

private:

string name;

string address;

string type_of_account;

double balance;

int transaction;

static int ac_no;

public:

void input()

cout<<"Enter name: ";

cin>>name;
cout<<"Enter address: ";

cin>>address;

cout<<"Enter Balance: ";

cin>>balance;

cout<<"Enter type of account: ";

cin>>type_of_account;

static void account_number()

int aco_no;

ac_no++;

aco_no=ac_no;

cout<<"BA"<<aco_no<<endl;

void display()

cout<<"Name: ";

cout<<name<<endl;

cout<<"Address: ";

cout<<address<<endl;

cout<<"Account Type: ";

cout<<type_of_account<<endl;

cout<<"Account Number: ";

account_number();

cout<<"Balance: ";

cout<<balance;

void deposit()
{

double dep_amo=0;

cout<<"Enter deposit Amount: ";

cin>>dep_amo;

balance=balance+dep_amo;

void withdraw()

double wid_amo=0;

if(wid_amo<=balance)

balance=balance-wid_amo;

else

cout<<"Enough Balance"<<endl;

void change_address()

cout<<"Enter changing address: "<<endl;

cin>>address;

};

int bankaccount::ac_no=1000;

int main()

int *p=new int;

cout<<"Enter number of depositors"<<endl;


cin>>*p;

bankaccount obj[*p];

for(int i=0;i<*p;i++)

obj[i].input();

obj[i].deposit();

obj[i].withdraw();

obj[i].display();

You might also like