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

assignment

The document contains multiple C++ programming tasks that cover various concepts such as functions, classes, structures, and arrays. Each task includes code snippets that demonstrate operations like arithmetic calculations, array manipulations, class inheritance, and user input handling. The final task involves creating a simple donut shop billing system, showcasing object-oriented programming principles.

Uploaded by

talalhaider199
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 views20 pages

assignment

The document contains multiple C++ programming tasks that cover various concepts such as functions, classes, structures, and arrays. Each task includes code snippets that demonstrate operations like arithmetic calculations, array manipulations, class inheritance, and user input handling. The final task involves creating a simple donut shop billing system, showcasing object-oriented programming principles.

Uploaded by

talalhaider199
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/ 20

NAME : NASEEBULLAH

ID : F2024408304
ASSIGNMENT NO 1 :
SUBJECT : OOP

TASKS:

TASK 1: #include <iostream>

using namespace std;

int calculate(int c,int d){

int a=c;

int b=d;

int sum=(a+b)*(a+b);

return sum;

int cal(int c,int d){

int a=c;

int b=d;

int sum=(a-b)*(a-b);

return sum;

int calcu(int c,int d){

int a=c;

int b=d;

int sum=(a*a)-(b*b);
return sum;

int main(){

int a,b,sum;

cout<<"input 2 numbers "<<endl;

cin>>a>>b;

cout<<"a+b whole square is "<<calculate(a,b)<<endl;

cout<<"(a-b whole square is ) "<<cal(a,b)<<endl;

cout<<"a+b and a-b is "<<calcu(a,b);

TASK 2:

#include <iostream>

using namespace std;

int multiply(int , int);

float divide(int,int);

int subtruct(int,int);
int mod(int,int);

int main(){

int a,b;

cout<<"input 2 numbers "<<endl;

cin>>a>>b;

cout<<"A multiply B is "<<multiply(a,b)<<endl;

cout<<"A / b is "<<divide(a,b)<<endl;

cout<<"A - B is "<<subtruct(a,b)<<endl;

cout<<"A % b ia "<<mod(a,b)<<endl;

return 0;

int multiply(int a,int b){

return a*b;

float divide(int a,int b){

return(float)a/b;

int subtruct(int a,int b){

return a-b;

int mod(int a,int b){

return a%b;

TASK 3:

#include <iostream>

using namespace std;

int Array(int array[],int size){


cout<<"input the five members if array "<<endl;

for (int i=0;i<size;i++){

cin>>array[i];}

int max=array[0];

for (int i=0;i<size;i++){

if(array[i]>max){

max=array[i];

return max;

int main(){

int array[5],size=5;

cout<<"the max of array is "<<Array(array,size);

return 0;

TASK 4:

#include <iostream>

using namespace std;

struct circle{

float diameter,radius,area,circumference;

};

circle readdata(){

circle c;

cout<<"input the Diameter "<<endl;

cin>>c.diameter;

c.radius=c.diameter/2;
c.circumference=3.14*c.radius;

return c;

void compare(circle c1,circle c2){

if(c1.area==c2.area&&c1.circumference==c2.circumference){

cout<<"both circles are equal "<<endl;

else{

cout<<"circles are not equal "<<endl;

int main(){

circle circle1,circle2;

cout<<"enter data for circle 1 "<<endl;

circle1=readdata();

cout<<"enter data for circle 2 "<<endl;

circle2=readdata();

compare(circle1,circle2);

return 0;

TASK 5:

#include <iostream>

#include <string>

using namespace std;

struct Employee {

string name;

int salary;

float hoursWorked;

void inputHours() {
cout << "Enter hours worked per day: ";

cin >> hoursWorked;}

int calculateSalary() {

if (hoursWorked >= 12) {

salary = hoursWorked * 150;}

else if (hoursWorked > 8) {

salary = hoursWorked * 100;}

else {

salary = hoursWorked * 50;}

return salary;}

void displaySalary() {

cout << "Salary of " << name << " is: " << salary << endl;}

void inputName() {

cout << "Enter employee's name: ";

cin.ignore();

getline(cin, name);}

};

int main() {

const int numEmployees = 10;

Employee employees[numEmployees];

for (int i = 0; i < numEmployees; ++i) {

cout << "Employee Number --> " << i + 1 << endl;

employees[i].inputName();

employees[i].inputHours();
}

cout << "\n--- Salaries of All Employees \n";

for (int i = 0; i < numEmployees; ++i) {

employees[i].displaySalary();

return 0;

TASK 6:

#include <iostream>

using namespace std;

class person{

public:

int weight;

float height;

char gender;

person(){

cout<<"this is a person class "<<endl;

};

class Employee:public person{

public:

string designation;

int hours_day;

Employee(){

cout<<"this is Employee class"<<endl;

};
class teacher:public Employee{

public:

void display(){

cout<<"teacher details are "<<endl;

cout<<"the weight is "<<weight<<endl;

cout<<"the height is "<<height<<endl;

cout<<"the gender is "<<gender<<endl;

cout<<"the designation is "<<designation<<endl;

cout<<"the houra_dat is "<<hours_day<<endl;

};

int main(){

teacher t;

t.weight=70.50;

t.height=180,5;

t.gender='m';

t.designation="OOP teacher ";

t.hours_day=8;

t.display();

return 0;

TASK 7:

#include <iostream>

using namespace std;

class person{

public:

float weight,height;

string gender;

void walk(){
cout<<"the person is walking "<<endl;

void sit(){

cout<<"the person is siting "<<endl;

};

class student:public person{

public:

int id;

string first_name,last_name;

string graduation;

void print_detail(){

cout<<"these are the details of the person "<<endl;

void write(){

cout<<"the person is writing "<<endl;

};

class graduation_student:public student{

public:

string uni_name;

int graduation_year;

void display(){

cout<<"the weight of person is "<<weight<<endl;

cout<<"the height of person is "<<height<<endl;

cout<<"the gender of person is "<<gender<<endl;

cout<<"the id of person is "<<id<<endl;


cout<<"the first name of person is "<<first_name<<endl;

cout<<"the last_name of person is "<<last_name<<endl;

cout<<"the person is gradated ? "<<graduation<<endl;

cout<<"the uni of person is "<<uni_name<<endl;

cout<<"the graduation year of person is "<<graduation_year<<endl;

};

int main(){

graduation_student g;

g.weight=70.12;

g.height=180.5;

g.gender="male";

g.walk();

g.id=2024408304;

g.first_name="Naseeb";

g.last_name="ullah";

g.graduation="No";

g.uni_name="UMT";

g.graduation_year=2028;

g.display();

g.print_detail();

g.write();

return 0;

TASK 8:

#include <iostream>

using namespace std;

class date{
public:

int day,month, year;

void display(){}

};

class time:public date{

public:

int hours;

float minutes;

float seconds;;

void display(){}

};

class time_date:public time{

public:

void display(){

cout<<"the year is "<<year<<endl;

cout<<"the month is "<<month<<endl;

cout<<"The day is"<<day<<endl;

cout<<"The hourse are "<<hours<<endl;

cout<<"The minutes are "<<minutes<<endl;

cout<<"The seconds are "<<seconds<<endl;

};

int main(){

time_date obj1;

cout<<"Input year ";

cin>>obj1.year;

cout<<"Input month ";


cin>>obj1.month;

cout<<"Input day ";

cin>>obj1.day;

cout<<"Input hours ";

cin>>obj1.hours;

cout<<"Input minutes ";

cin>>obj1.minutes;

cout<<"Input seconds ";

cin>>obj1.seconds;

cout<<"-------------------";

obj1.display();

TASK 9:

#include<iostream>

using namespace std;

class book{

private:

int No_pages;

int price;

string type;

public:

void read_data(){

cout<<"Input No of pages of book "<<endl;

cin>>No_pages;

cout<<"Input The price of book "<<endl;

cin>>price;

cout<<"Input the type of book (Local or Foriegn)"<<endl;

cin>>type;}
void display_data(){

cout<<"The No of pages are "<<No_pages<<endl;

cout<<"The price of book is "<<price<<endl;

cout<<"the type of book is "<<type;}

};

int main(){

book b1,b2,b3;

b1.read_data();

b2.read_data();

b3.read_data();

b1.display_data();

b2.display_data();

b3.display_data();

TASK 10:

#include <iostream>

#include <string>

#include <cstdlib> // Include this for exit()

using namespace std;

class DonutShop {

private:

string flavor;

int quantity;

char coffeeChoice;
int total;

public:

DonutShop() {

quantity = 0;

total = 0;

void getOrder() {

cout << "Enter donut flavor (cinnamon, chocolate, blueberry, vanilla, coffee): ";

cin >> flavor;

cout << "Enter number of donuts (max 12): ";

cin >> quantity;

if (quantity > 12) {

cout << "Invalid input! You can't order more than 12 donuts.\n";

exit(0); // Exit if invalid input

cout << "Do you want coffee with donuts? (y/n): ";

cin >> coffeeChoice;

void calculateBill() {

total = quantity * 60; // Base price for donut

if (flavor == "chocolate") {

total += quantity * 50; // Additional charge for chocolate flavor

}
if (coffeeChoice == 'y') {

total += 100; // Additional charge for coffee

void showBill() {

cout << "\n--- BILL ---\n";

cout << "Flavor: " << flavor << endl;

cout << "Quantity: " << quantity << endl;

if (coffeeChoice == 'y') {

cout << "Coffee: Yes\n";

} else {

cout << "Coffee: No\n";

cout << "Total Amount: Rs " << total << endl;

~DonutShop() {

cout << "\nThank you for ordering from Shezan Bakers!\n";

};

int main() {

DonutShop order;

order.getOrder();

order.calculateBill();

order.showBill();
return 0;

}
OUTPUT OF ALL THE TASKS :

You might also like