You are on page 1of 12

Object Oriented Programming (22EC005)

Task 1.1
Topic: Introduction to Object Oriented Programming
Overview: Object Oriented programming (OOP) is to structure a software program into
simple, reusable pieces of code blueprints (usually called classes), which are used to create
individual instances of objects.
Task Statement: Manav is working in an automobile company. He is working to provide
services that can facilitate certain operations for the customer’s cars. Now help Manav in
building the programming structure for a software that can take user’s input for car details
(like color, brand, and model) and offer different maintenance services like paint and wash etc.
Ensure that software must be reusable by implementing the concept of OOP.
Screenshot of compiler code and output (if applicable):

code in text (if applicable):


#include <iostream>

using namespace std;

class car

Submitted By: Raunak, 2310994547, Branch


Object Oriented Programming (22EC005)

public:

string name, model, brand;

int a;

void input()

cout << "Enter the details of car: " << endl;

cout << "Car name- ";

cin.ignore();

getline(cin, name);

cout << "Car model- ";

cin.ignore();

getline(cin, model);

cout << "Car brand- ";

cin.ignore();

getline(cin, brand);

void output()

cout << "Choose maintenance service: " << endl;

cout << "1. Wash- Rs300" << endl;

cout << "2. Paint- Rs1000" << endl;

cout << "3. Denting- Rs500 \n";

cout << "4. Wheel Alignment- Rs2000 \n";

cout << "5. Engine service- Rs800 \n";

cout << "6. All in one- Rs6500 \n";

cin >> a;

cout << "Maintenance of: \n";

switch (a)

Submitted By: Raunak, 2310994547, Branch


Object Oriented Programming (22EC005)

case 1:

cout << "Wash the car \n";

break;

case 2:

cout << "Paint the car \n";

break;

case 3:

cout << "Denting of car \n";

break;

case 4:

cout << "Wheel Alignment of car \n";

break;

case 5:

cout << "Engine service of car \n";

break;

case 6:

cout << "Service of the whole car \n";

break;

default:

cout << "None of these \n";

break;

};

int main()

car c1;

c1.input();

c1.output();

return 0;

Submitted By: Raunak, 2310994547, Branch


Object Oriented Programming (22EC005)

Link for Compilation/Simulation output (if applicable):


https://onlinegdb.com/ClOs_4CKx

Interpretation of results: The C++ program defines a `car` class with attributes for name, model, brand, and a
user-selected option for maintenance services. The `input()` function gathers car details from the user, utilizing
`cin.ignore()` to handle input correctly. The `output()` function presents a menu of maintenance services, prompts
the user to choose one, and uses a `switch` statement to display the selected service. In the `main()` function, an
instance of the `car` class is created, and the user is guided to input car details and select a maintenance service. This
program provides a simple interactive system for managing car information and maintenance service selection.

Submitted By: Raunak, 2310994547, Branch


Object Oriented Programming (22EC005)

Task 1.2
Topic: Classes and Objects.
Overview: Classes and objects are basic concepts of Object-Oriented Programming (OOPs)
that are used to represent real-world concepts and entities.
Statement: An Orthopedic hospital demands a software which should accommodate the
following features:
1. Entering the name, age, gender of patient
2. Issues faced by the patient
3. Provision for advance booking with the doctor
4. Emergency Appointment
Help them by building a reusable program that must take these inputs from the user and
display them on screen.
Screenshot of compiler code and output (if applicable):

Submitted By: Raunak, 2310994547, Branch


Object Oriented Programming (22EC005)

code in text (if applicable):


#include <iostream>

using namespace std;

class patient

public:

string name, gender, problems, urgent;

int age, yesorno;

void personal_details();

void issues();

void booking();

void emergency();

Submitted By: Raunak, 2310994547, Branch


Object Oriented Programming (22EC005)

void output();

};

void patient::personal_details()

cout << "Name of the person: ";

getline(cin, name);

cout << "Age of person: ";

cin >> age;

cin.ignore();

cout << "Sex: ";

getline(cin, gender);

void patient::issues()

cout << "Name the problems[if more than 1 put comma(,)]: ";

getline(cin, problems);

void patient::booking()

cout << "If any booking: \n";

cout << "1. YES \n";

cout << "2. NO \n";

cin >> yesorno;

if (yesorno == 1)

cout << "Go to doctor \n";

else if (yesorno == 2)

cout << "Take an appointment \n";

Submitted By: Raunak, 2310994547, Branch


Object Oriented Programming (22EC005)

void patient::emergency()

cout << "If emergency: ";

cin >> urgent;

void patient::output()

cout << "\n\n REPORT of the Patient \n\n"

<< endl;

cout << "Name of the person: " << name << endl;

cout << "Age of person: " << age << endl;

cout << "Sex: " << gender << endl;

cout << "Name the problems[if more than 1 put comma(,)]: " << problems << endl;

cout << "If any booking: " << yesorno << endl;

cout << "If emergency: " << urgent << endl;

int main()

patient p1;

p1.personal_details();

p1.issues();

p1.booking();

p1.emergency();

p1.output();

return 0;

Link for Compilation/Simulation output:


https://onlinegdb.com/xnRz0MYvX

Submitted By: Raunak, 2310994547, Branch


Object Oriented Programming (22EC005)

Interpretation of results: This C++ program defines a `patient` class to gather and display information about
a patient, including personal details, health issues, booking status, and emergency conditions. The program prompts
the user to input the patient's name, age, gender, health issues, and answers regarding booking and emergency
situations. It utilizes member functions within the class to manage these inputs and outputs. The output is then
presented as a comprehensive report, summarizing the patient's information. The modifications include added input
handling to address potential issues with newline characters in the buffer, ensuring a smoother user experience.
Overall, the program provides a basic framework for recording and reporting patient-related data in a medical
context.

Task 1.3
Topic: Abstraction
Overview: Data abstraction is one of the most essential and important features of objectoriented
programming in C++. Abstraction means displaying only essential information and
hiding the details.

Submitted By: Raunak, 2310994547, Branch


Object Oriented Programming (22EC005)

Statement: Write a piece of software to track the student’s details of a university. Remember,
students may come from different backgrounds, locations, and have different hobbies, ages,
religions, and languages etc. Your software must accommodate these details and display only
the essential details required for student identity on the university campus.
Screenshot of compiler code and output:

code in text:
#include <iostream>

using namespace std;

class student {

long int roll,age,phn;

string name, course, religion, address,blood_grp,uni_mail;

public:

void get_data();

void generate_card();

};

void student::get_data() {

cout << endl;

cout << " Step 1- Basic Details" << endl;;

cout << "Enter Name- ";

Submitted By: Raunak, 2310994547, Branch


Object Oriented Programming (22EC005)

getline(cin, name);

cout << "Enter Age- ";

cin >> age;

cin.ignore();

cout << "Enter Phone Number- ";

cin >> phn;

cin.ignore();

cout << "Enter Blood Group- ";

getline(cin, blood_grp);

cout << "Enter Religion- ";

getline(cin, religion);

cout << "Enter Address- ";

getline(cin, address);

cout << endl;

cout << "Step 2- Course Details" << endl;;

cout << "Enter Course name ";

getline(cin, course);

generate_card();

void student::generate_card() {

int temp_roll=2000; cout << endl;

cout << "Details for Your ID Card" << endl;;

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

cout << ".";

cout<< endl;

cout <<"Name- "<<name << endl;;

cout << "Roll Number- " << temp_roll << endl;;

cout << "Course- " << course << endl;

Submitted By: Raunak, 2310994547, Branch


Object Oriented Programming (22EC005)

cout<<"Blood Group- "<<blood_grp << endl;

int main()

student s1;

s1.get_data();

Link for Compilation/Simulation output:


https://onlinegdb.com/RYHOAvxTy

Interpretation of results: This C++ program defines a `student` class that captures and presents student
information in two steps: basic details and course-related details. The user is prompted to input the student's name,
age, phone number, blood group, religion, address, and course name. Subsequently, the program generates a pseudo
ID card, featuring a temporary roll number, and displays it along with the provided details. The code ensures correct
input handling and employs a static counter for generating unique roll numbers. The main function instantiates the
`student` class and initiates the data collection process. Overall, the program provides a simple yet interactive
system for creating student records and producing associated ID card information.

Submitted By: Raunak, 2310994547, Branch

You might also like