Вы находитесь на странице: 1из 10

VIT

UN I V E R S I T Y
(Estd. u/s 3 of UGC Act 1956)

School of Information Technology and Engineering


LAB CYCLE SHEET

Course: II Semester M.S (S.E)


Lab: SWE102 Object Oriented Programming

1. Write a program which inputs a person’s height (in centimeters) and weight (in
kilograms) and outputs one of the messages: underweight, normal, or overweight, using
the criteria:
Underweight: weight < height/2.5
Normal: height/2.5 <= weight <= height/2.3
Overweight: height/2.3 < weight

2. Write a C++ program to perform calculator operations using switch-case.


3. Write a program which inputs an integer value, checks that it is positive, and outputs
its factorial using functions.
4 . Write a function which outputs all the prime numbers between 2 and a given positive
integer n:

void Primes (unsigned int n);


5. To read a line of text and counting the number of characters in the text.

6. Write a program that prints the memory requirements of different data types and their
ranges of values.

7. A parking garage charges a 2.00Rs minimum fee to park for up to three hours. The
garage charges an additional an additional 0.50Rs per hour for each hour or part
therof in excess of three hours.the maximum charge given for any 24 hour period is
10Rs.Assume no car parks for longer than 24 hours at a time.Write a program that
calculates and prints the parking charges for each of the three customers who parked
their cars in this garage yesterday .You should enter the hours parked for each
customer .Your program should print the result in a neat tabular format and should
calculate and print the total of yesterday’s receipts. The program should use the
function calculateCharges to determine the charge of each customer. Your output
should appear in the following format.
Car Hours Charge

1 1.0 2.0

2 4.0 2.50

3 24.0 10.00

Tot 29.5 14.50

8. Write a line to accomplish each of the following tasks. You will want to look up the
documentation for string functions online. (Recall that the way to call a function on a
string variable is, for instance, myString.find("a"). Also note that the usual cin and cout
syntaxes work for strings, but cin will stop reading at the first whitespace character.)
a. Declare a variable papayaWar of type string (assuming header file <string> has
been included). Initialize it to the value "No, sir, away! A papaya war is on!"
b. Print the index of the first instance of the exclamation point character in
papayaWar.

c. Print the length of the papayaWar string.


d. Print the last 5 characters of papayaWar.
e. Replace the contents of the string with a string that the user enters.
f. Append the string "rotator" to the end of papayaWar.
g. Print the contents of papayaWar.
9. Use a two-dimensional array to solve the following problem. A company has four
sales person who sell five different products (1 to 5). Once a day, each salesperson
passes in slip for each different type of product sold. Each slip contains the following.
The salesman number
The product number
The total value of that product sold that day.
Thus, each salesperson passes in between 0 to 5 sales slips per day. Assume that
the information from all of the slips for last month is available. Write a program
that will read all this information for last month’s sales and summarize the total
sales by salesperson by product. All totals should be stored in two dimensional
array sales. After processing all the information for last month, print the results in
tabular format with each of the columns represent a particular salesperson and each
row representing the particular product. Cross total each row to get the total sales
of each product for last month; cross total each column to get the total sales by
salesperson for last month. Your tabular results should include these cross totals to
the right of the totaled rows and to the bottom of the totaled columns.

10. Implement Towers of Hanoi Problem using recursive function.

11. Write a function areaShapes to find the area of a triangle. Overload


areaShapes function to find the area of a square, sphere, and cylinder.

12. Write a program to compute Tax. A Tax Compute function takes two arguments:
amount and tax percentage. Default tax percentage is 15% of income

13. Write a function stringCompare that checks if two strings are equal. Overload
the function stringCompare to compare two strings up till “n
“characters.Overload the same function to do a case insensitive comparison. The
function prototypes as given as below.
stringCompare (char [], char []);
stringCompare (char [], char [], int);
stringCompare (char [], char [], char [] = “sensitive”); //use of default
argument is must

14. Write a function with prototype given as bubbleSort (char [ ] [15], int) to sort
the array of Strings. Overload the function to sort array of integers.

15. Write a C++ program that prompts the user for the radius of a circle then calls
inline function circleArea to calculate the area of that circle.

16. Create a Structure student containing regno, name, age and address. Write an
inline functions to read and display details of a Student.

17. Write a program that uses function template called sqr to find the square of an
integer, a float and a double.

18. Write a recursive function recursiveMin that takes an integer array, a


starting subscript and an ending subscript as arguments, and returns the smallest
element in the array. The function should stop processing and return when
starting subscript equals ending subscript.
19. Create a structure Employee containing emp_id, name, age, address as members.
Write separate functions to read details about “n” employees, display
details about all employees, display average age of all employees, display
details of employees whose age is 54 and above.

20. Develop a C++ program to perform Complex number arithmetic operations using
class concept. (add,sub,mul,div)
21. Write an OOP to read students name and his average marks. If a student gets less than
40 then declare that he has failed or else he passed. Prepare a computer list to give the list
of names in alphabetical order separately for passed and failed students
22. An automobile dealer has given identity number (id number) to all spare parts.
The class named product was defined to store information about identity number
and listed price of a spare part. Write a program to edit the class product to include
tax in the listed price and then calculate the net price including tax for following
spare parts (Assume: tax is 8 % of listed price.)
a) idno=501 price=1250
b) idno=502 price=1560

23. Create a class Employee (Identity number, name, department code, address,
designation, Salary, DOJ, DOB) and perform the following operations for 5
employees (Use array of objects)
a. Reading the details from keyboard.
b. Displaying the full details of a particular employee.
c. Displaying the detail of senior most employee.

24. Develop an Object Oriented database to carry out the following information from the
keyboard:
Name of the patient
Sex
Age
Ward Number
Bed Number
Nature of the illness
Date of admission
Your program should have the following facilities:
a) Build a master table
b) List a table
c) Insert a new entry
d) Delete old entry
e) Edit an entry
f) Search for a record that to be printed
g) Sort entries

25. Create a class called Rational for performing arithmetic with fractions. Write a
program to test your class. Use integer variables to represent private data of the class-
numerator and the denominator. Provide a constructor that enables an object of this class
to be initialized when it is declared. The constructor should contain default values in case
no initializers are provided. For example the fraction 2/4 would be stored in an object as
1 in numerator and 2 in denominator. Provide public member functions that perform each
of the tasks:
a. Adding 2 rational numbers.
b. Subtracting 2 rational numbers.
c. Multiply two rational numbers.
d. Dividing two rational numbers
e. Printing rational numbers in the form a/b.
f. Printing rational numbers in floating point format.

26. Create a class Rectangle with attributes length and width, each of which defaults
to 1.Provide member function that calculate perimeter and area of the rectangle.
Also provide set and get functions for length and width atrributes.The set function
should verify that length and width are each floating-point numbers larger than
0.0 and less than 20.0

27. Create a class HugeInteger that uses a 40-element array of digits to store integers
as large as 40 digits each.Provide member functions input,output,add and
subtract.Forcomparing HugeInteger objects ,provide functions isEqualTo ,
isLessThan,isGreaterThan,isNotEqual-each of this is a predicate function that
simply return true if relationship holds between two HugeIntegers and returns
false otherwise.

28. Create a class String that uses an array to store the value of a string.Provide
proper constructor and destructor as well as set and get functions. The class
should also provide the following overloaded operator capabilities.
Overloaded + operator to concatenate two strings.
Overloaded += operator.
Overloaded = operator
Overloaded ==,! =, <, > for comparing two string objects.

Also provide a member function sortStrings that sorts string objects using the
suitable overloaded functions defined above. Write a main function to check the
usage of above defined functions.
29. Create a class Matrix having data members- 2D Array, rows, columns for storing
matrix information. Include operation functions for reading and displaying a
matrix. Also include operator member functions for adding, subtracting and
multiplying matrix objects. Also include a friend function to find the transpose of
a matrix. Write a menu driven main function to do all matrix operations.

30. Create a class EncryptDecrypt containing a char [] and length as its


members.Include operator function ++, -- that increments and decrements each
and every character of an array by one.Also include friend functions encryptData
and DecryptData functions which calls ++, -- functions for encryption and
decryption of data.
31. Create an inheritance hierarchy in c++ using following information given below
that a bank might use to represent customers’ bank accounts.

Account

SavingsAccount CheckingAccount
Base class Account should include one data member of type double to represent
account balance.The class should provide constructor that receives an initial
balance and uses it to initialize the data member.The constructor should validate
the initial balance to ensure that it is greater than or equal to 0.If not the balance is
set to 0.0 and the constructor should display an error message,indicating that the
initial balance was invalid.The class also provides three member functions-
credit, debit(debit amount should not exceed the account balance) and
enquiry.Derived class SavingsAccount should inherit the functionality of an
Account,but also include data member of type double indicating the interest rate
assigned to the Account.SavingsAccount constructor should receive the initial
balance ,as well as an initial value for SavingsAccount’s interest
rate.SavingsAccount should provide public member function calculateInterest
that returns double indicating the amount of interest earned by an
account.Member function calculateInterest should determine this amount by
multiplying the interest rate by the account balance.SavingsAccount function
should inherit member functions credit,debit and enquiry without redefining them.
Derived class CheckingAccount should inherit the functionality of an Account,
but also include data member of type double that represents the fee charged per
transaction.CheckingAccount constructor should receive the initial balance ,as
well as parameter indicating fee amount.class CheckingAccount should redefine
credit and debit function so that they subtract the fee from account balance
whenever either transaction is performed.CheckingAccount’s debit function
should charge a fee only if the money is actually withdrawn(debit amount should
not exceed the account balance).After defining the class hierarchy, write program
that creates object of each class and tests their member functions.Add interest to
SavingAccount object by first invoking its calculateInterest function, then passing
the returned interest amount to object’s credit function.

32. Given a hierarchy


Student

PostGraduateStudent

DoctralStudent

Create classes to implement the following hierarchy. Include data members and member
functions as given in the table below.

Class Data Members Member Functions

Student Name,age,address, Read,display


UG_degree,college,percentage,year_of_comple
tions,area_of_specialization

PostGradutate PG_degree,area_of_specialization,college,year_ Read,display


of_completion,no_of_confrences_attended,no_
of_papers_published,no_of_books_written

Doctoral PHD_area,college,year_of_completion, Read,Display

Thesis_submitted

Also include display functions in all classes to


a. Display information about students who are currently pursuing a course.
b. Display details about PG students who are alumini’s, given the college.
c. Display all details about PhD students who have finished their thesis.

33. Given the following hierarchy

Academician ProfessionalSoceity

Member
Create required classes to implement the hierarchy. Include data members and member
functions as given in the table below.

Class Data Members Member Functions

Academician Name,age,address,qualification,years_of_experi Read, display


ence,area_of_specialization,work_experience,b
ooks_published,confreneces_attended

Professional Name,year_started,head_quaters,confereneces_ Read, display


Society conducted,journals_published

Member Role,year_of_joining,participation_details Read,Display

Also include display functions in all classes to


a. Display information about Academician who is a member of atleast 2
professional Soceity.
b. Display details about Professional Society of VIT chapter.
c. Display all details about members of CSI of Chennai chapter.

34. Given the following hierarchy

CricketPlayer

Batsman Bowler

AllRounder

Create suitable classes and subclasses to implement the following hierarchy.Include


name,age,country,total_runs,average,no_of_50s,no_of_100s,no_of_notouts,total_matches
Also include member functions to read , display and findAeverage to read, display
information about a player.FindAverage function finds the average runs of the player.
Subclass Batsman inherits the features of CricketPlayer class and doesn’t include any
extra features. Subclass Bowler inherits the functionality of Cricket Player and includes
data members- total_wickets, no_of_hatricks, strike_rate, no_of_5wkts.It also includes
redefines the member function read and display to read and display this extra
information. The subclass AllRounder inherits the functionality of Batsman and Bowler
classes.The class redefines the read and display function to display both batting and
bowling strategies. Write main function to call the the below functions.Use friend
functions wherever necessary.

a. To display details about all the players playing, given a country.


b. To display details about the batsman who have more than 6000 runs to his
credit.
c. To display details about bowlers who have more than 5 hatricks.
d. To display the details about all-rounder who have got more than 5000 runs
and more than 200 wkts.

35. Given the following hierarchy


Shape

Circle Rectangle Triangle Square

Base class Shape has a data member of type double to store information about
side/radius and area. Include virtual member functions area () and perimeter () and
display (). Make the class Shape abstract.classes Circle, Rectangle, Triangle, Square
are subclasses to Shape.Include data members in subclass if necessary.Redefine
member functions area and perimeter in respective subclasses to find the area and
perimeter. Write a menu driven main function to call the functions of the subclasses.

36. Create a class Node having data of generic type and a pointer to itself (self
referential class).Create a class Stack List; make the class friend to Node. Include
necessary member functions and data members in Stack List class to implement
operations on Stack. Write a menu driven main program to implement stack
operations on an integer, float and char data items.

37. Write a C++ program to implement a sequential file. the program supports code
for writing into the file the grade sheet of student and to display grade sheet of
the student about student

38. Write a C++ program that implements random access file to read the file
backwards and display the contents of the file on to the screen and on to another
file.

39. An owner of a hardware store has kept an inventory of different tools available in
his store in a random access file. Write a c++ program that initializes the file. The
program enables him to list the tools, delete a record for a tool that is no longer
available; update information about a tool .The tool identification number should
be record number. The information stored in the file looks like

Record No Tool Name Quantity Cost

123 Hammer 76 11.99

223 Electric Sander 7 57.98

111 Wrench 34 7.50

40. Write a C++ program with the following:

a) A function to read two double type numbers from the keyboard.


b) A function to calculate the division of these two numbers.
c) A try block to detect and throw an exception if the condition “divide-by-zero” occurs.

d) Appropriate catch block to handle the exceptions thrown.

Вам также может понравиться