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

24k2027_L1

The document contains multiple C++ code snippets demonstrating the use of classes for various applications, including input and output operations, calculations, and data management. Each code segment showcases different functionalities such as handling distances, time, employee records, student grades, and flight information. The examples illustrate basic object-oriented programming concepts like encapsulation, member functions, and data manipulation.

Uploaded by

k242016
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

24k2027_L1

The document contains multiple C++ code snippets demonstrating the use of classes for various applications, including input and output operations, calculations, and data management. Each code segment showcases different functionalities such as handling distances, time, employee records, student grades, and flight information. The examples illustrate basic object-oriented programming concepts like encapsulation, member functions, and data manipulation.

Uploaded by

k242016
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/ 16

NAME M Tayyab

CLASS BSSE

ROLL NO 24K2027

ASSIGNMENT 01

CODE
#include<iostream>
#include<string>
using namespace std;
class num
{

int m;

public:
void input()
{
cout<<"enter the value "<<endl;
cin>>m;
}

void shoe()
{
cout<<"the number is "<<m<<endl;
}

};

int main()
{ num obj;
obj.input();
obj.shoe();

system("pause");
return 0;
}
OUTPUT

CODE
#include <iostream>
using namespace std;
// Class definition
class Distance {
private:
int feet; // Integer for feet
float inches; // Float for inches

public:
// Function to get distance from user
void getDist() {
cout << "Enter feet: ";
cin >> feet;
cout << "Enter inches: ";
cin >> inches;
}

// Function to set distance using parameters


void setDist(int f, float i) {
feet = f;
inches = i;
}

// Function to display distance


void showDist() {
cout << "Distance: " << feet << "' " << inches << "\"" << endl;
}
};

int main() {
Distance d1, d2; // Create two Distance objects

cout << "Enter first distance:" << endl;


d1.getDist(); // Get values for first object

cout << "Enter second distance:" << endl;


d2.getDist(); // Get values for second object

// Display the distances


cout << "\nDisplaying Distances:" << endl;
d1.showDist();
d2.showDist();
system("pause");
return 0;
}

OUTPUT
CODE
#include <iostream>
using namespace std;

class time {
private:
int hours ;
int mintues;
int seconds;
public:

void settime(int a, int b,int c) {

hours =a;
mintues=b;
seconds=c;

void showtime() {
cout << "time " << hours << " " << mintues << " " <<seconds<< endl;
}
};

int main() {
time t1, t2;
t1.settime(12,13,15);
t2.settime(12,13,15);
cout << "first time is:" << endl;
t1.showtime();

cout << " second time is:" << endl;


t2.showtime();
system("pause");
return 0;
}

OUTPUT

CODE
#include <iostream>
#include <string>
using namespace std;

class Person {
private:
int Pid;
string Pname;
float PSalary;

public:

void getData() {
cout << "Enter Person ID: ";
cin >> Pid;
cout << "Enter Name: ";
cin>>Pname;
cout << "Enter Salary: ";
cin >> PSalary;
}

void setData(int id, string name, float salary) {


Pid = id;
Pname = name;
PSalary = salary;
}

void showData() {
cout<<"pid is"<<Pid<<"name is"<<Pname<<"salary is "<<PSalary<<endl;
}

float getSalary() {
return PSalary;
}
};

int main() {
Person p1, p2, p3;

cout << "Enter details for Person 1:" << endl;


p1.getData();
cout << "Enter details for Person 2:" << endl;
p2.getData();
cout << "Enter details for Person 3:" << endl;
p3.getData();

Person highest = p1;


if (p2.getSalary() > highest.getSalary())
highest = p2;
if (p3.getSalary() > highest.getSalary())
highest = p3;

cout << "\nPerson with the highest salary:" << endl;


highest.showData();
system("pause");
return 0;
}

OUTPUT
CODE
#include <iostream>
#include <string>
using namespace std;

class Employee {
private:
int Eid;
string Ename;
double ESalary;

public:

void getData() {
cout << "Enter Person ID: ";
cin >> Eid;
cin.ignore();
cout << "Enter Name: ";
getline(cin ,Ename);
cout << "Enter Salary: ";
cin >> ESalary;
}

void setData(int id, string name, double salary) {


Eid = id;
Ename = name;
ESalary = salary;
}

void showData() {
cout<<"eid "<<Eid<<"name is "<<Ename<<"salary is "<<ESalary<<endl;
}

double getSalary() {
return ESalary;
}
};

int main() {
Employee p1, p2;
cout << "Enter details for Employee 1:" << endl;
p1.getData();
cout << "Enter details for Employee 2:" << endl;
p2.getData();

Employee highest = p1;


if (p2.getSalary() > highest.getSalary())
highest = p2;

cout << "\nPerson with the highest salary:" << endl;


highest.showData();
system("pause");
return 0;
}

OUTPUT

CODE
#include <iostream>
#include <string>
using namespace std;

class student {
private:
int eng;
int che;
int bio;
int math;
int phy;

public:

void getData() {
cout << "Enter eng numbre: ";
cin >> eng;
cout << "Enter che number: ";
cin>>che;
cout << "Enter bio number: ";
cin >> bio;
cout << "Enter math number: ";
cin >> math;
cout << "Enter phy number: ";
cin >> phy;
}
int sum() {
int sum;
sum=eng+che+bio+math+phy;
return sum;

int average() {
float average;
average=(sum()/5);
return average;
}

};

int main() {
student p1;

cout << "Enter details for Employee 1:" << endl;


p1.getData();

cout << "sum is:" << endl;


cout<< p1.sum()<<endl;
cout << "avreage is :"<<endl;
cout<< p1.average();
cout<<endl;
system("pause");
return 0;
}

OUTPUT
CODE
#include <iostream>
#include <string>
using namespace std;

class Student {
private:
int admno;
string sname;
float eng, math, science, total;

float ctotal() {
return eng + math + science;
}

public:
void Takedata() {
cout << "Enter Admission Number: ";
cin >> admno;
cin.ignore();
cout << "Enter Student Name: ";
getline(cin, sname);
cout << "Enter English Marks: ";
cin >> eng;
cout << "Enter Math Marks: ";
cin >> math;
cout << "Enter Science Marks: ";
cin >> science;
total = ctotal();
}

void Showdata() {
cout << "\nStudent Details" << endl;
cout << "Admission Number: " << admno << endl;
cout << "Student Name: " << sname << endl;
cout << "English Marks: " << eng << endl;
cout << "Math Marks: " << math << endl;
cout << "Science Marks: " << science << endl;
cout << "Total Marks: " << total << endl;
}
};

int main() {
Student student;
student.Takedata();
student.Showdata();
system("pause");
return 0;
}

OUTPUT
CODE
#include <iostream>
#include <string>
using namespace std;

class Batsman {
private:
int bcode;
string bname;
int innings, notout, runs;
float batavg;

void calcavg() {
if (innings - notout > 0)
batavg = static_cast<float>(runs) / (innings - notout);
else
batavg = 0; // To handle division by zero case
}

public:
void readdata() {
cout << "Enter Batsman Code (4-digit number): ";
cin >> bcode;
cin.ignore();
cout << "Enter Batsman Name: ";
getline(cin, bname);
cout << "Enter Innings Played: ";
cin >> innings;
cout << "Enter Not Out Innings: ";
cin >> notout;
cout << "Enter Total Runs Scored: ";
cin >> runs;
calcavg();
}

void displaydata() {
cout << "\nBatsman Details" << endl;
cout << "Batsman Code: " << bcode << endl;
cout << "Batsman Name: " << bname << endl;
cout << "Innings Played: " << innings << endl;
cout << "Not Out Innings: " << notout << endl;
cout << "Total Runs: " << runs << endl;
cout << "Batting Average: " << batavg << endl;
}
};

int main() {
Batsman batsman;
batsman.readdata();
batsman.displaydata();
system("pause");
return 0;
}

OUTPUT

CODE
#include <iostream>
#include <string>
using namespace std;

class TEST {
private:
int TestCode;
string Description;
int NoCandidate;
int CenterReqd;

int CALCNTR() {
return (NoCandidate / 100) + 1;
}

public:
void SCHEDULE() {
cout << "Enter Test Code: ";
cin >> TestCode;
cin.ignore();
cout << "Enter Description: ";
getline(cin, Description);
cout << "Enter Number of Candidates: ";
cin >> NoCandidate;
CenterReqd = CALCNTR();
}

void DISPTEST() {
cout << "\nTest Details" << endl;
cout << "Test Code: " << TestCode << endl;
cout << "Description: " << Description << endl;
cout << "Number of Candidates: " << NoCandidate << endl;
cout << "Number of Centers Required: " << CenterReqd << endl;
}
};

int main() {
TEST test;
test.SCHEDULE();
test.DISPTEST();
system("pause");
return 0;
}

OUTPUT
CODE
#include <iostream>
#include <string>
using namespace std;

class Flight {
private:
int FlightNumber;
string Destination;
float Distance;
float Fuel;

void CALFUEL() {
if (Distance <= 1000)
Fuel = 500;
else if (Distance > 1000 && Distance <= 2000)
Fuel = 1100;
else
Fuel = 2200;
}

public:
void FEEDINFO() {
cout << "Enter Flight Number: ";
cin >> FlightNumber;
cin.ignore();
cout << "Enter Destination: ";
getline(cin, Destination);
cout << "Enter Distance: ";
cin >> Distance;
CALFUEL();
}

void SHOWINFO() {
cout << "\nFlight Details" << endl;
cout << "Flight Number: " << FlightNumber << endl;
cout << "Destination: " << Destination << endl;
cout << "Distance: " << Distance << " km" << endl;
cout << "Fuel Required: " << Fuel << " liters" << endl;
}
};

int main() {
Flight flight;
flight.FEEDINFO();
flight.SHOWINFO();
system("pause");
return 0;
}

OUTPUT
CODE
#include <iostream>
#include <string>
using namespace std;

class BOOK {
private:
int BOOK_NO;
string BOOKTITLE;
float PRICE;

float TOTAL_COST(int N) {
return PRICE * N;
}

public:
void INPUT() {
cout << "Enter Book Number: ";
cin >> BOOK_NO;
cin.ignore();
cout << "Enter Book Title: ";
getline(cin, BOOKTITLE);
cout << "Enter Price per Copy: ";
cin >> PRICE;
}

void PURCHASE() {
int N;
cout << "Enter number of copies to purchase: ";
cin >> N;
float total = TOTAL_COST(N);
cout << "Total Cost: " << total << "\n";
}
};
int main() {
BOOK book;
book.INPUT();
book.PURCHASE();
system("pause");
return 0;
}

OUTPUT

CODE
#include <iostream>
#include <string>
using namespace std;

class REPORT {
private:
int adno;
string name;
float marks[5];
float average;

void GETAVG() {
float sum = 0;
for (int i = 0; i < 5; i++) {
sum += marks[i];
}
average = sum / 5;
}

public:
void READINFO() {
cout << "Enter Admission Number (4 digits): ";
cin >> adno;
cin.ignore();
cout << "Enter Name: ";
getline(cin, name);
cout << "Enter Marks for 5 Subjects: ";
for (int i = 0; i < 5; i++) {
cin >> marks[i];
}
GETAVG();
}
void DISPLAYINFO() {
cout << "\nStudent Report" << endl;
cout << "Admission Number: " << adno << endl;
cout << "Name: " << name << endl;
cout << "Marks: ";
for (int i = 0; i < 5; i++) {
cout << marks[i] << " ";
}
cout << "\nAverage Marks: " << average << endl;
}
};

int main() {
REPORT student;
student.READINFO();
student.DISPLAYINFO();
system("pause");
return 0;
}

OUTPUT

You might also like