0% found this document useful (0 votes)
21 views14 pages

C++ Object-Oriented Programming Assignments

The document contains a series of C++ programming assignments submitted by Anees Abbasi to Dr. Saima Jabeen, covering various object-oriented programming concepts. Each program demonstrates different functionalities such as creating classes, performing arithmetic operations, and displaying formatted outputs. Additionally, it includes a class project on a Finance Management System involving team members and a brief explanation of its purpose.

Uploaded by

aneesabbasitg
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)
21 views14 pages

C++ Object-Oriented Programming Assignments

The document contains a series of C++ programming assignments submitted by Anees Abbasi to Dr. Saima Jabeen, covering various object-oriented programming concepts. Each program demonstrates different functionalities such as creating classes, performing arithmetic operations, and displaying formatted outputs. Additionally, it includes a class project on a Finance Management System involving team members and a brief explanation of its purpose.

Uploaded by

aneesabbasitg
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

Name: Anees abbasi Submitted to: Dr. Saima Jabeen.

Department: Ai-22-Blue

Assignment No 2:
Object Oriented Programing
Program 1:
Create a Class with the name myClass. Write code to show the following output on the screen. Replace
“Your Name” with your own real name, adjust the size of the box if you have to:

Answer:
Code:
#include <iostream>

#include <string>

using namespace std;

class myClass {

private:

string name;

public:

myClass(string name) : name(name) {}

void print_box(string message) {


Name: Anees abbasi Submitted to: Dr. Saima Jabeen.
Department: Ai-22-Blue

cout << " " << message << endl;

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

cout << " "<< "|" << name << "|" << endl;

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

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

cout << " " << "/ Welcome! \\" << endl;

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

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

cout << " " << "|" << " " << "to C++ class" <<" " << "|" << endl;

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

};

int main() {

myClass obj("Anees abbasi");

obj.print_box("My First C++ Program!");

return 0;

Output:

Program 2:
Write a program using class named as Plus that should add any two numbers and display the result:

Answer:
Name: Anees abbasi Submitted to: Dr. Saima Jabeen.
Department: Ai-22-Blue

Code:
#include <iostream>

using namespace std;

class Plus {

private:

int num1;

int num2;

public:

Plus(int n1, int n2) : num1(n1), num2(n2) {}

int add() {

return num1 + num2;

};

int main() {

int x, y;

cout << "Enter First numbers to add: ";

cin >> x ;

cout << "Enter Second numbers to add: ";

cin>> y;

Plus obj(x, y);

cout << "The sum is: " << [Link]() << endl;

return 0;

}
Name: Anees abbasi Submitted to: Dr. Saima Jabeen.
Department: Ai-22-Blue

Output:

Program 3:
Write a complete program in a class named Table2 that produces the following output using a for loop
where 2 can be replaced by any number entered by user. 2 times 1 = 2 2 times 2 = 4 2 times 3 = 6 2 times
4 = 8 ……………………… until 2 times 10 = 20 Your program should be flexible to change 2 to any number
i.e., if user enters 3 your program should display complete table of 3.

Answer:
Code:
#include <iostream>

using namespace std;

class Table2 {

private:

int num;

public:

Table2(int n) : num(n) {}

void display_table() {

for (int i = 1; i <= 10; i++) {

cout << num << " x " << i << " = " << num * i << endl;

};

int main()

{
Name: Anees abbasi Submitted to: Dr. Saima Jabeen.
Department: Ai-22-Blue

int x;

cout << "Enter a number to display its multiplication table: ";

cin >> x;

Table2 obj(x);

obj.display_table();

return 0;

Output:

Program 4:
Write a C++ class that declares a named constant that holds the number of feet in a mile: 5,280. Also
declare a variable to represent the distance in miles between your house and your uncle’s house. Assign
an appropriate value to the variable— for example, 8.5. Compute and display the distance to your
uncle’s house in both miles and feet. Display explanatory text with the values—for example, The distance
to my uncle’s house is 8.5 miles or 44880.0 feet. Save the class as [Link].

Answer:
Code:
#include <iostream>

using namespace std;

class MilesToFeet {

private:
Name: Anees abbasi Submitted to: Dr. Saima Jabeen.
Department: Ai-22-Blue

const int FEET_IN_MILE = 5280;

double distance;

public:

MilesToFeet(double d) : distance(d) {}

void display_distance() {

double distance_feet = distance * FEET_IN_MILE;

cout << "The distance to my uncle's house is " << distance << " miles or " << distance_feet << " feet."
<< endl;

};

int main() {

double distance_miles = 8.5;

MilesToFeet obj(distance_miles);

obj.display_distance();

return 0;

Output:

Program 5:
Convert the MilesToFeet class to an interactive application. Instead of assigning a value to the distance,
accept the value from the user as input. Save the revised class as [Link].

Answer:
Name: Anees abbasi Submitted to: Dr. Saima Jabeen.
Department: Ai-22-Blue

Code:
#include <iostream>

using namespace std;

class MilesToFeet {

private:

double miles;

double feet;

public:

void setMiles() {

cout << "Enter the distance in miles: ";

cin >> miles;

void convert() {

feet = miles * 5280;

void display() {

cout << miles << " miles is equal to " << feet << " feet." << endl;

};

int main() {

MilesToFeet obj;

[Link]();

[Link]();

[Link]();

return 0;

}
Name: Anees abbasi Submitted to: Dr. Saima Jabeen.
Department: Ai-22-Blue

Output:

Program 6:
Create a new class called Design. Write two methods f1() and f2(). method f1() prints the following line:
* * * * * * * * Method f2() prints the following line: * * * * * * * * In the main method, call methods f1()
and f2() to have the following checkerboard pattern printed on screen:

Answer:
Code:
#include<iostream>

using namespace std;

class design

public:

void f1()

cout<<"\t"<<"* * * * * * * *\n";

void f2()

cout<<"\t"<<" * * * * * * * *\n";

}
Name: Anees abbasi Submitted to: Dr. Saima Jabeen.
Department: Ai-22-Blue

};

int main()

design star;

for(int i=0;i<8;i++)

if(i%2==0)

star.f1();

else

star.f2();

Output:

Program 7:
Create a new class called Shapes. Write a program to print the following on screen:
Name: Anees abbasi Submitted to: Dr. Saima Jabeen.
Department: Ai-22-Blue

Answer:
Code:
#include <iostream>

using namespace std;

class Circle{

public:

void draw() {

};

int main() {

Circle c;

[Link]();

Output:

Program 8:
Meadowdale Dairy Farm sells organic brown eggs to local customers. They charge Rs.120 for a dozen
eggs, or 12 Rupees for individual eggs that are not part of a dozen. Write a class that prompts a user for
the number of eggs in the order and then display the amount owed with a full explanation. For example,
Name: Anees abbasi Submitted to: Dr. Saima Jabeen.
Department: Ai-22-Blue

typical output might be, “You ordered 27 eggs. That’s 2 dozen at Rs.120 per dozen and 3 loose eggs at
12/- rupees each for a total of Rs.276.” Save the class as [Link].

Answer:
Code:
#include <iostream>

#include <cmath>

using namespace std;

class Eggs {

private:

int numEggs;

public:

Egg() {

numEggs = 0;

void setNumEggs(int n) {

numEggs = n;

void displayAmount() {

int dozens = numEggs / 12;

int singleEggs = numEggs % 12;

int totalAmount = (dozens * 120) + (singleEggs * 12);

cout << "TOTAL AMOUNT OF EGGS ARE:" << totalAmount << "." << endl;

};

int main() {

Eggs order;

int num;

cout << "Enter the number of eggs you order: ";


Name: Anees abbasi Submitted to: Dr. Saima Jabeen.
Department: Ai-22-Blue

cin >> num;

[Link](num);

[Link]();

Output:

Program 9:
The Happy Yappy Kennel boards dogs at a cost of 50 cents per pound per day. Write a class that accepts a
dog’s weight and number of days to be boarded and displays the total price for boarding. Save the class
as [Link].

Answer:
Code:
#include <iostream>

using namespace std;

class DogBoarding {

public:

DogBoarding(double weight, int days) : weight_(weight), days_(days) {}

double calculatePrice()

const {

return weight_ * days_ * 0.5;

private:

double weight_;

int days_;
Name: Anees abbasi Submitted to: Dr. Saima Jabeen.
Department: Ai-22-Blue

};

int main() {

double weight;

int days;

cout << "Enter the dog's weight in pounds: ";

cin >> weight;

cout << "Enter the number of days to be boarded: ";

cin >> days;

DogBoarding Boarding(weight, days);

cout << "The total price for boarding is $:" << [Link]() << endl;

Output:

Question 10:
Class Project:
Members:
 Muhammad Ali
 Abdul Rafay
 Anees abbasi
 Talha Mehmood Kiyani
Leader:
“Talha Mehmood Kiyani”.
Project Title:
“Finance Management System”.
Name: Anees abbasi Submitted to: Dr. Saima Jabeen.
Department: Ai-22-Blue

Brief Explanation:
“financial management allows users to track their expenses and income. This code uses basic C++
concepts such as arrays, loops, Structure, Pointers and functions”

Deliverable:
“Till now the code is under process. Me and my team is doing its best to make the code
more and more efficient and on an advance level”.

You might also like