0% found this document useful (0 votes)
52 views8 pages

Oops

Uploaded by

vedalamuparna
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
52 views8 pages

Oops

Uploaded by

vedalamuparna
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 8

GRAPHIC ERA (DEEMED TO BE UNIVERSITY), DEHRADUN

SEMESTER III

Name of Department: - Computer Science and Engineering

1. Subject Code: PCS 307 Course Title: OOP WITH C++ LAB

2. Contact Hours: L: 0 T: 1 P: 2

3. Examination Duration (Hrs): Theory Practical

4. Relative Weight: CIE 50 MSE 25 SEE 50

5. Credits: 2
6. Semester: III
7. Category of Course: DC

8. Pre-requisite: PCS 101, PCS 102

9. Course After completion of the course the students will be able to:
Outcome**: CO1: Evaluate the basic difference between object-oriented programming
and procedural language and their data types.
CO2: Implement the programs using C++ features such as object
creation, compile time polymorphism, inheritance, abstraction,
encapsulation etc.
CO3: Design and solve programs that incorporates the use of object-
oriented techniques such as abstract classes, pure virtual functions,
and constructors.

CO4: Create programs based on the concepts of virtual base


classes, virtual functions and STL to solve real time problems
** Describe the specific knowledge, skills or competencies the students are expected to acquire
or demonstrate.

10. Details of the Course:


Sl. List of problems for which student should develop program and execute in the Contact
No. Laboratory Hours
An electricity board charges the following rates to domestic users to discourage
large consumption of energy.
For the first 100 units: - 60 P per unit
1. For the next 200 units: -80 P per unit
Beyond 300 units: -90 P per unit
All users are charged a minimum of Rs 50 if the total amount is more than Rs 300
then an additional surcharge of 15% is added.
Implement a C++ program to read the names of users and number of units consumed
and display the charges with names
Construct a C++ program that removes a specific character from a given string and
2. return the updated string.
Typical Input: computer science is the future
Typical Output: compuer science is he fuure
Implement a C++ program to find the non-repeating characters in string.
3. Typical Input: graphic era university
Typical Output: c g h n p s t u v y
You are given an array of elements. Now you need to choose the best index of this
array. An index of the array is called best if the special sum of this index is maximum
across the special sum of all the other indices. To calculate the special sum for any
index you pick the first element that is and add it to your sum. Now you pick next
two elements i.e., and and add both of them to your sum. Now you will pick the
next elements, and this continues till the index for which it is possible to pick the
elements. Find the best index and in the output print its corresponding special sum.
Note that there may be more than one best index, but you need to only print the
maximum special sum.

Input
First line contains an integer as input. Next line contains space separated integers
denoting the elements of the array
4.
Output
In the output you have to print an integer that denotes the maximum special sum

Input/Output Format
Typical Input Expected Output

5 8
13125
10 9
2 1 3 9 2 4 -10 -9 1 3

5. Implement a C++ program to demonstrate the concept of data abstraction using the
concept of Class and Objects

Define a class Hotel in C++ with the following specifications


Private members
• Rno Data member to store room number
6.
• Name Data member to store customer name
• Tariff Data member to store per day charges
• NOD Data member to store number of days of stay
• CALC() Function to calculate and return amount as NOD*Tariff ,and if the value
of days* Tariff >10000,
then total amount is 1.05* days*Tariff.
Public members
• Checkin() Function to enter the content Rno, Name, Tariff and NOD
• Checkout() Function to display Rno, Name, Tariff,
NOD and Amount (amount to be displayed by calling function) CALC()

Implement a Program in C++ by defining a class to represent a bank account.


Include the following:
Data Members
● Name of the depositor
● Account number
● Type of account (Saving, Current etc.)
7.
● Balance amount in the account
Member Functions
● To assign initial values
● To deposit an amount
● To withdraw an amount after checking the balance
● To display name and balance
Anna is a contender for valedictorian of her high school. She wants to know how
many students (if any) have scored higher than her in the exams given during this
semester.
Create a class named Student with the following specifications:
➢ An instance variable named scores holds a student's 5 exam scores.
➢ A void input () function reads 5 integers and saves them to scores.
➢ An int calculateTotalScore() function that returns the sum of the student's
scores.
Input Format
In the void Student::input() function, you must read 5 scores from standard input
8. and save them to your scores instance variable.
Output Format
In the int Student::calculateTotalScore() function, you must return the student's total
grade (the sum of the values in scores).
The code in the editor will determine how many scores are larger than Anna’s and
print that number to the console.
Sample Input
The first line contains n, the number of students in Anna’s class. The n subsequent
lines contain each student's 5 exam grades for this semester.
3
30 40 45 10 10
40 40 40 10 10
50 20 30 10 10
Sample Output
1
Construct a Program in C++ to show the working of function overloading(compile
9. time polymorphism) by using a function named calculate Area () to calculate area
of square, rectangle and triangle using different signatures as required.
Create a class called Invoice that a hardware store might use to represent an invoice
for an item sold at the store. An Invoice should include four pieces of information
as instance.
Data Members ‐
• partNumber (type String)
• partDescription (type String)
• quantity of the item being purchased (type int)
10.
• price_per_item (type double)
Your class should have a constructor that initializes the four instance variables.
Provide a set and a get method for each instance variable. In addition, provide a
method named getInvoiceAmount() that calculates the invoice amount (i.e.,
multiplies the quantity by the price per item), then returns the amount as a double
value. If the quantity is not positive, it should be set to 0. If the price per item is not
positive,it should be set to0.0. Write a test application named invoiceTest that
demonstrates class Invoice’s capabilities.
Imagine a tollbooth with a class called TollBooth. The two data items are of type
unsigned int and double to hold the total number of cars and total amount of money
collected. A constructor initializes both of these data members to 0. A member
function called payingCar( )increments the car total and adds 0.5 to the cash total.
11. Another function called nonPayCar( ) increments the car total but adds nothing to
the cash total. Finally a member function called display( )shows the two totals.
Include a program to test this class. This program should allow the user to push one
key to count a paying car and another to count a non paying car. Pushing the ESC
key should cause the program to print out the total number of cars and total cash
and then exit.
Create a class called Time that has separate int member data for hours, minutes and
seconds. One constructor should initialize this data to 0, and another should
initialize it to fixed values. A member function should display it in 11:59:59 format.
12. A member function named add() should add two objects of type time passed as
arguments. A main ( ) program should create two initialized values together, leaving
the result in the third time variable. Finally it should display the value of this third
variable.
Create class SavingsAccount. Use a static variable annualInterestRate to store the
annual interest rate for all account holders. Each object of the class contains a private
instance variable savingsBalance indicating the amount the saver currently has on
deposit. Provide method calculateMonthlyInterest() to calculate the monthly
interest by multiplying the savingsBalance by annualInterestRate divided by
13. 12.This interest should be added tosavingsBalance. Provide a static method
modifyInterestRate() that sets the annualInterestRate to a new value. Write a
program to test class SavingsAccount. Instantiate two savingsAccount objects,
saver1 and saver2, with balances of Rs2000.00 and Rs3000.00, respectively. Set
annualInterestRate to 4%, then calculate the monthly interest and print the new
balances for both savers. Then set the annualInterestRate to 5%, calculate the next
month’s interest and print the new balances for both savers
Create a class Complex having two int type variable named real & img denoting
14. real and imaginary part respectively of a complex number. Overload +, - , ==
operator to add, to subtract and to compare two complex numbers being denoted by
the two complex type objects
Using the concept of operator overloading. Implement a program to overload the
following:
15. a. Unary –
b. Unary ++ preincrement, postincrement
c. Unary -- predecrement, postdecrement
Using the concept of operator overloading. Implement a program to overload the
following:
With the help of friend function
16.
a. Unary –
b. Unary ++ preincrement, postincrement
c. Unary -- predecrement, postdecrement
Create a Base class that consists of private, protected and public data members and
member functions. Try using different access modifiers for inheriting Base class to
17. the Derived class and create a table that summarizes the above three modes (when
derived in public, protected and private modes) and shows the access specifier of
the members of base class in the Derived class.
You are given three classes A, B and C. All three classes implement their own
version of func. In class A, func multiplies the value passed as a parameter by 2. In
class B, func multiplies the value passed as a parameter by 3. In class C, func
multiplies the value passed as a parameter by 5.You are given class D such that You
18. need to modify the class D and implement the function update_val which sets D's
val to new_val by manipulating the value by only calling the func defined in classes
A, B and C.It is guaranteed that new_val has only 2, 3 and 5 as its prime factors.
Implement class D's function update_val. This function should update D's val only
by calling A, B and C's func.
Sample Input
new_val = 30
Sample Output
A's func called 1 times
B's func called 1 times
C's func called 1 times
Create a class called Student that contains the data members like age, name,
enroll_no, marks. Create another class called Faculty that contains data members
like facultyName, facultyCode, salary,deptt, age, experience, gender. Create the
19. function display() in both the classes to display the respective information. The
derived Class Person demonstrates multiple inheritance. The program should be
able to call both the base classes and displays their information. Remove the
ambiguity (When we have exactly same variables or same methods in both the base
classes, which one will becalled?) by proper mechanism

20. Implement a real case scenario by a proper C++ code to provide the solution to
Diamond Problem in C++
Create a base class called shape. Use this class to store two double type values that
could be used to compute the area of figures. Derive two specific classes called
triangle and rectangle from base shape. Add to the base class, a member function
get_data() to initialize base class data members and another member function
display_area() to compute and display the area of figures. Make display_area() as a
virtual function and redefine this function in the derived class to suit their
21. requirements. Using these three classes, design a program that will accept
dimensions of a triangle or a rectangle interactively and display the area. Remember
the two values given as input will be treated as lengths of
two sides in the case of rectangles and as base and height in the case of triangle and
used as follows:
Area of rectangle = x * y
Area of triangle = ½ *x*y
Create a base class called CAL_AREA(Abstract). Use this class to store float type
values that could be used to compute the volume of figures. Derive two specific
classes called cone, hemisphere and cylinder from the base CAL_AREA. Add to
the base class, a member function getdata ( ) to initialize base class data members
and another member function display volume( ) to compute and display the volume
21. of figures. Make display volume ( ) as a pure virtual function and redefine this
function in the derived classes to suit their requirements. Using these three classes,
design a program that will accept dimensions of a cone, cylinder and hemisphere
interactively
and display the volumes. Remember values given as input will be and used as
follows:
Volume of cone = (1/3)πr2h
Volume of hemisphere = (2/3)πr3
Volume of cylinder = πr2h
The task is to debug the existing code to successfully execute all provided test files.
You are required to extend the existing code so that it handles the
std::invalid_argument exception properly. More specifically, you have to extend the
implementation of the process_input function. It takes integer n as an argument and
has to work as follows:
1.It calls function largest_proper_divisor(n).
2.If this call returns a value without raising an exception, it should print in a single
line result=d where d is the returned value.
3.Otherwise, if the call raises an invalid_argument exception, it has to print in a
single line the string representation of the raised exception, i.e., its message.
4.Finally, no matter if the exception is raised or not, it should print in a single line
returning control flow to the caller after any other previously printed output.

Input Format
The input is read by the provided locked code template. In the only line of the input,
there is a single integer n, which is going to be the argument passed to function
process input.

22.
Output Format

The output should be produced by the function process_input as described in the


statement.
Sample Input
0
Sample Output
the largest proper divisor is not defined for n=0
returning control flow to the caller
Explanation 1
In the first sample, n = 0, so the call largest_proper_divisor(0) raises an exception.
In this case, the function process_input prints two lines. In the first of them, it prints
the string representation of the raised exception, and in the second line, it prints
returning control flow to the caller.
Sample Input
9
Sample Output
result=3
Templates are the foundation of generic programming, which involves writing code
in a way that is independent of any particular type. Write a program that can create
23.
a list (create a class list) of given type (int, float, char etc.) and perform insertion
and deletion on list object.
Construct a C++ program to demonstrate different methods of List, Vector and Map
24.
in STL (Standard Template Library)
You are provided with a vector of N integers. Then, you are given 2 queries. For the
first query, you are provided with 1 integer, which denotes a position in the vector.
The value at this position in the vector needs to be erased. The next query consists
of 2 integers denoting a range of the positions in the vector. The elements which fall
under that range should be removed. The second query is performed on the updated
vector which we get after performing the first query.
Input Format
The first line of the input contains an integer N. The next line contains N space-
separated integers (1-based index). The third line contains a single integer x,
denoting the position of an element that should be removed from the vector. The
fourth line contains two integers a and b denoting the range that should be erased
from the vector inclusive of a and exclusive of b.
Output Format
Print the size of the vector in the first line and the elements of the vector after the
25.
two erase operations in the second line separated by space.
Sample Input
6
146289
2
24
Sample Output
3
189
Explanation
The first query is to erase the 2nd element in the vector, which is 4. Then, a modified
vector is {1 6 2 8 9}, we want to remove the range of 2~4, which means the 2nd and
3rd elements should be removed. Then 6 and 2 in the modified vector are removed
and we finally get {1 8 9}
Total

11. Suggested Books:


SL. Name of Authors/Books/Publishers Edition Year of Publication
No. / Reprint
Textbooks
1. Herbert Schildt,“The Complete Reference C++”, 4th Edition, 4th 2003
Tata McGraw Hill, 2003.
2. Balagurusamy.” Object Oriented Programming with 8th 2020
C++”,8th Edition, Tata McGraw Hill,2020
Reference Books
1. Paul Deitel and Harvey Deitel,” C++: How to Program”,10 10th 2016
Edition, Pearson

12. Mode of Evaluation Test / Quiz / Assignment / Mid Term Exam / End Term Exam

You might also like