OOPS Karan 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Practical File

OOP with C++ Lab (PCS 307)

B. Tech Third Semester


Session : 2024 - 25

Submitted to: Submitted by:


Ms. Rashmi Deopa Name -Karan Bungla
Lecturer B. Tech (CSE)
Computer Science & Engineering Section- B
Graphic Era Hill University Roll No- 2361240
Bhimtal Campus
COLLEGE ROLL NO : EXAMINATION ROLL NO :

THIS IS TO CERTIFY THAT MR./MS __________________________________HAS


SATISFACTORILY COMPLETED ALL THE EXPERIMENTS IN THE
LABORATORY OF THIS COLLEGE. THE COURSE OF THE EXPERIMENTS /
TERM WORK IN OOP WITH C++ LAB (PCS 307) IN PARTIAL FULFILMENT
OF THE REQUIREMENT IN THIRD SEMESTER OF BACHELOR OF
TECHNOLOGY (C.S.E.) DEGREE COURSE PRESCRIBED BY THE GRAPHIC ERA
HILL UNIVERSITY, BHIMTAL DURING THE YEAR 2024 - 25.

CONCERNED FACULTY HEAD OF DEPARTMENT

NAME OF EXAMINER :

SIGNATURE OF EXAMINER :
Index
Exp. Page
No. Date Experiment No. Sign

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


• For the next 200 units :- 80 P per unit
• Beyond 300 units :- 90 P per unit
1
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.

2 Construct a C++ program that removes a specific


character from a given string and return the updated string.
Typical Input: computer science is the future
Typical Output: compuer science is he fuure

3 Implement a C++ program to find the non-repeating


characters in string.
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
4 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
Index
Output In the output you have to print an integer that
denotes the maximum special sum

Input/Output Format

Typical Input Expected Output

13125 8

10

2 1 3 9 2 4 -10 -9 1 3 9

5 Implement a C++ program to demonstrate the concept of


data abstraction using the concept of Class and Objects.

6 Define a class Hotel in C++ with the


following specifications:

Private members:

• Rno : Data member to store room number


• 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()
Index
7 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.)
● 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

8 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 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.
Index
3
30 40 45 10 10
40 40 40 10 10
50 20 30 10 10
Sample Output 1
9 Construct a Program in C++ to show the working of
function overloading(compile time polymorphism) by using
a function named calculate Area () to calculate area of
square, rectangle and triangle using different signatures as
required.
10 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)
• 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.
11 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. 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.
Index
12 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. 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
13 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 For batches
admitted in 2023-24 and 2024-25 onwards, Applicable
from Academic Session 2024-25
calculateMonthlyInterest() to calculate the monthly interest
by multiplying the savingsBalance by annualInterestRate
divided by 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
14 Create a class Complex having two int type variable named
real & img denoting 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

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