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

Assignment 2

This document outlines Assignment Number 2 for CS1004 - Object Oriented Programming, due on October 10, 2024, with a total of 100 marks. It includes several programming tasks focused on applying object-oriented concepts in C++, such as creating classes for a Home Energy Management System, a cricket game, a tollbooth, resistors, fighter jets, string manipulation, and a vehicle showroom. Students are instructed to submit handwritten solutions and follow specific guidelines to avoid penalties for late or copied work.

Uploaded by

omaishmalik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Assignment 2

This document outlines Assignment Number 2 for CS1004 - Object Oriented Programming, due on October 10, 2024, with a total of 100 marks. It includes several programming tasks focused on applying object-oriented concepts in C++, such as creating classes for a Home Energy Management System, a cricket game, a tollbooth, resistors, fighter jets, string manipulation, and a vehicle showroom. Students are instructed to submit handwritten solutions and follow specific guidelines to avoid penalties for late or copied work.

Uploaded by

omaishmalik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CS1004 – OOP Assignment Number 2

CS1004 – Object Oriented Programming


Assignment Number 2
Fall 2024

Maximum Marks: 100 Due Date: 10 October 2024

Instructions:
• Partially or fully copied assignments will be marked as zero.
• Only handwritten solution on A4 page will be accepted.
• Use the title page provided with this assignment.
• Late submissions are not allowed.
• Solve all the questions in the given order.

Taxonomy
CLO No. CLO Statement Domain
Level
Apply the basic and advanced concepts of Object-
2 Oriented Programming to write C++ programs to Cognitive 3
solve engineering problems.

Question Number 1 (CLO 2) (15 marks)


The major components of a Home Energy Management System (HEMS) are Grid, Renewable
Energy Resources, Inverter, Battery storage, a controller, and Loads as shown in the figure
below. This complex problem can be reduced to several simple problems by using the Object-
Oriented Programming concepts. Use data modelling to identify possible classes, objects,
attributes, methods, and constant methods for HEMS.

National University of Computer and Emerging Sciences – FAST, CFD Campus 1


CS1004 – OOP Assignment Number 2

Question Number 2 (CLO 2) (15 marks)


Suppose that you are coding a cricket game. For this you need to take care of players, ground,
crowd, equipment (bat, ball, stumps etc) and Umpires. This task is too difficult with structural
programming, that why we need to go for Object Oriented Programming. Use the data
modeling technique to find:
• Class(es)
• Object(s) in each class
• Attributes of each object
• Constant Object(s) of each class (if any)
• Method(s) of every class
• Static Data in all classes (if any)

Question Number 3 (CLO 2) (10 marks)


Imagine a tollbooth at a bridge. Cars passing by the booth are expected to pay a RS 30/- toll.
Mostly they do, but sometimes a car goes by without paying. The tollbooth keeps track of the
number of cars that have gone by, and of the total amount of money collected.
Interpret this tollbooth with a class called tollBooth. The two data items are a type unsigned
int to hold the total number of cars, and a type double to hold the total amount of money
collected. A constructor initializes both of these to 0. A member function called
payingCar() increments the car total and adds 30 to the cash total. Another function, called
nopayCar(), increments the car total but adds nothing to the cash total. Finally, a member
function called display() displays the two totals.
Include a main program to test this class. This program should allow the user to repeatedly
push one key to count a paying car, and another key to count a nonpaying car. Pushing the Esc
key should cause the program to print out the total cars and total cash and then exit.
The ASCII code for ESC key is 27.

Question Number 4 (CLO 2) (20 marks)


A resistor is a passive electrical circuit component with the following characteristics.
• Material Type: String
• Value: Double
• Power Rating: Float
• Tolerance: Integer
The resistors can be combined in series or parallel with the following relation.
In series Req = R1 + R2 + … + RN
In parallel
1
𝑅𝑒𝑞 =
1 1 1
𝑅1 + 𝑅2 + ⋯ + 𝑅𝑁
Write a C++ class to represent a resistor with the following functions.
• Constructors and Destructor.
• Input Function → no argument, nothing to return
• Display Function → no argument, nothing to return
• Combine in Series Function → one resistor in the argument, return equivalent resistor,
concatenate the types, tolerance and power of the highest value resistor will dominate.
• Combine in Parallel Function → one resistor in the argument, return equivalent resistor,
concatenate the types, tolerance and power of the lowest value resistor will dominate.
After writing the class definition, write a main program to test your code.

National University of Computer and Emerging Sciences – FAST, CFD Campus 2


CS1004 – OOP Assignment Number 2

Question Number 5 (CLO 2) (20 marks)


Write an object-oriented program that will take the specifications of two different fighter jets
as input, display their specifications side by side like below. And then decide that which one is
better.

Specifications Jet 1 Jet 2


Crew Capacity 10 12
Maximum Speed 2200 km/hr 2500 km/hr
Combat Radius 10.5 km 16.8 km
Accuracy 10 12
Load Capacity 2500 kg 2800 kg

Some Useful Hints


• You need to declare the specifications as a private data.
• A member function input() will ask the user to enter the attributes for the jets.
• Another function show() will display the data in the given format. (This function will
accept one object as an argument)
• Another function compare() will compare both these jets attribute by attribute, and
the jet having better attributes will be declared as best. (Compare each attribute and
assign points after comparison, in the end the jet with more points will be the best).
This function will also accept one object as an argument.
• Write a main program to use the defined class. In main program declare 2 objects (both
of them must be initialized with 0 values). Then call the methods in appropriate
sequence to complete the task.

Question Number 6 (CLO 2) (10 marks)


Use the C++ string class and string class functions to write a C++ program which will ask the
user to enter two strings, and then generate a substring from the midpoint of first string to the
midpoint of second string. A sample run of the program is given below.

Enter String 1 : Programming Fundamentals


Enter String 2 : Spring 2020
Generated Substring is : “ FundamentalsSprin”

Question Number 7 (CLO 2) (10 marks)


Suppose that you are running a showroom, and you deal in cars and jeeps. The price of a new
car is 20,000$ and price of a jeep is 35,000$. You want to design a system for your daily
earnings that tells you the total vehicles sold, and total cash received. Your program must tell
you that how many cars and jeeps are sold, and the earning of cars and jeeps must be displayed
separately. And in the end the total earning and total vehicles must display.

<< Good Luck >>

National University of Computer and Emerging Sciences – FAST, CFD Campus 3

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy