0% found this document useful (0 votes)
4 views7 pages

Program 1

Uploaded by

haiderkazmi3708
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)
4 views7 pages

Program 1

Uploaded by

haiderkazmi3708
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

Program 1: Student Record

Create a class Student with the following:

 Private data members: RollNo, Name, Marks.


 Public functions:
o get() to input data.
o show() to display data.
o set(int, string, float) to set data.
o getMarks() to return marks.
 In main(), create 2 student objects and display the student with the highest marks.

#include<iostream>

using namespace std;

class Student{

private:

int RollNo;

string Name;

float Marks;

public:

void get(){

cout<<"Enter roll no"<<endl;

cin>>RollNo;

cout<<"Enter Name"<<endl;

cin>>Name;

cout<<"Enter Marks"<<endl;

cin>>Marks;

void show(){

cout<<"RollNo ="<<RollNo<<endl;

cout<<"Name ="<<Name<<endl;
cout<<"Marks ="<<Marks<<endl;

void set(int rn, string na, float mr){

RollNo = rn;

Name = na;

Marks = mr;

float getMarks(){

return Marks;

};

int main(){

Student s1, s2;

[Link]();

[Link](2, "Ali", 90.5);

if([Link]() > [Link]())

[Link]();

else

[Link]();

return 0;

}
//Program 2: Rectangle Comparison

//Create a class Rectangle with:

//Private members: length, width.

//Public functions:

//get() to input dimensions.

//area() to return the area.

//compare(Rectangle) to compare areas and return the larger one.

//In main(), create 2 rectangles and display the one with the larger area.

#include<iostream>

using namespace std;

class Rectangle{

private:

int length, width;

public:

void get(){

cout<<"Enter Length and Width of Rectangle"<<endl;

cin>>length>>width;

int area(){

return length * width;

void show(){

cout<<"Length ="<<length<<endl;

cout<<"Width ="<<width<<endl;

cout<<"Area ="<<area()<<endl;
}

};

int main(){

Rectangle r1, r2;

[Link]();

[Link]();

if([Link]() > [Link]())

[Link]();

else

[Link]();

return 0;

}
#include<iostream>

using namespace std;

class BankAccount {

private:

int accountNumber;

string name;

int balance; // sirf integer rakha taake aur simple ho

public:

// Input lena

void get() {

cout << "Account number dijiye: ";

cin >> accountNumber;

cout << "Naam dijiye: ";

cin >> name;

cout << "Starting balance dijiye: ";

cin >> balance;

// Paisa jama karna

void deposit(int amount) {

balance = balance + amount;

}
// Paisa nikaalna

void withdraw(int amount) {

if(amount <= balance) {

balance = balance - amount;

} else {

cout << "Balance kam hai. Paisa nahi nikaal sakte.\n";

// Details dikhana

void show() {

cout << "\nAccount Number: " << accountNumber << endl;

cout << "Naam: " << name << endl;

cout << "Balance: " << balance << " rupees" << endl;

};

int main() {

BankAccount acc;

[Link](); // Pehle account ki info lo

[Link](500); // 500 rupees jama karo

[Link](200); // 200 rupees nikaalo

[Link](); // Sab kuch dikhado


return 0;

You might also like