CPP Assignment Q Set 02
CPP Assignment Q Set 02
1: Write a program to display the following output using a single cout statement
Maths = 90
Physics = 77
Chemistry = 69
2: Write a program to read two numbers from the keyboard and display the larger
3: Write a program to input an integer from the keyboard and display on the
screen “WELL DONE” that many times.
4: Write a program to read the values a, b and c and display x, where x = a / b –c.
5: Write a C++ program that will ask for a temperature in Fahrenheit and display it
in Celsius using a class called temp and member functions.
6: Write a function using reference variables as arguments to swap the values of a
pair of integers.
7: A cricket has the following table of batting figure for a series of test matches:
Player’s name Run Innings Time not
outSachin 8430 230
18Saurav 4200 130 . . . .
Write a program to read the figures set out in the above forms, to calculate the
batting arranges
and to print out the complete table including the averages.
8: An electricity board charges the following rates to domestic users to
discourage large consumption of energy:
For the first 100 units – 60P per unit
For the first 200 units – 80P per unit
For the first 300 units – 90P per unit
All users are charged a minimum of Rs. 50.00. If the total amount is more than Rs.
300.00 then an
additional surcharge of 15% is added.
Write a program to read the names of users and number of units consumed and
print out the
charges with names.
14 : Define a class String that could work as a user-defined string type. Include
constructors that will enable us to create an uninitialized string:
String s1; // string with length 0
And also initialize an object with a string constant at the time of creation
like
String s2(“Well done!”);
Include a function that adds two strings to make a third string. Note that
the statement
S2 = s1;
will be perfectly reasonable expression to copy one string to another.
Write a complete program to test your class to see that it does the
following tasks:
(a) Creates uninitialized string objects.
(b) Creates objects with string constants.
(c) Concatenates two strings properly.
(d) Displays a desired string object
15 :A book shop maintains the inventory of books that are being sold at the shop.
The list
includes details such as author, title, price, publisher and stock position.
Whenever a
customer wants a book, the sales person inputs the title and author and the
system searches
the list and displays whether it is available or not. If it is not, an appropriate
message is
displayed. If it is, then the system displays the book details and requests for the
number of
copies required. If the requested copies are available, the total cost of the
requested copies is
displayed; otherwise “Required copies not in stock” is displayed.
Design a system using a class called books with suitable member functions and
constructors.
Use new operator in constructors to allocate memory space required.