You are on page 1of 4

c 


1. Write a program to read two numbers from the keyboard and display the larger value
on the screen
2. Write a program to input an integer value from keyboard and display on screen
³WELL DONE´ that many times
3. Write a C++ program that will ask for a temperature in Fahrenheit and display in
Celsius
4. Write a Program to sort an array of Numbers
5. Write a program to display the reverse of an input string
6. Write a program to count the number of vowels in the input string
7. Write a function Max() that obtains the largest of 3 numbers.
8. Rewrite the function in 3rd question using inline functions.
9. Write a function power() to raise a number m to a power n. The function takes a
double value for m and int value for n, and returns the result. Use a default value of 2
for n to make the function to calculate squares when this argument is omitted. Write a
main that gets the values of m and n from the user to test the function.
10. Expressions like 1st, 2nd, 3rd, 4th, 5th, 6th, ... are called à 
Write a
program where the user inputs a number, then the program prints the corresponding
ordinal number. For example, if the user types , the program should respond with
.
Your program will need to choose which suffix (st, nd, rd, th) to output, based on the
input number. Choose your own test values, sufficient to show that all the different
cases work correctly.
11. Write a function monthname that returns the name of a month, based on the number
of the month. For example, monthname(10) would return "October".
Your function must use a switch statement as its decision-making structure.
To test your function, write a main program that prompts the user for a date in
numerical form (for example, "3 20 2002"), then outputs that date using the name of
the month ("March 20, 2002").
Ext 
Ã

Make your program display an error message if the month number is outside the valid
range of 1 through 12.
12. Your assignment is to rewrite your temperature conversion program (from
Assignment 3) so that the computation is performed by a function called FtoC. This
function should take a Fahrenheit temperature as a parameter (an input), and return a
Celsius temperature
While the computation will be done in the FtoC function, the input and output sho uld
still occur in the main part of the program. In other words, main should not include
any arithmetic, and FtoC should not contain any cin or cout statements.
Ext 
Ã

à ·esides the above, write a separate program that does the following:
ü Asks the user to input one Fahrenheit temperature and one Celsius
temperature
ü Outputs a message telling which of the two temperatures is warmer (or
stating that the two temperatures are equivalent).

This program must use FtoC and/or CtoF functions identical to those in your
first program. Test the program enough times to show that it handles each kind
of situation correctly
13. Define a class to represent a bank account. Include the following data members
à Name of the depositor
à Account number
à Type of account
à ·alance 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

Write a main program to test the program

14. Modify the above class and the program for handling 10 customers
15. Create two classes DM and DB which store the value of distances. DM stores
distances in meters and centimeters and DB in feet and inches. Write a
program that can read values for the class objects and add one object DM
with another object DB.
Use friend function to carry out the addition operation. The object that stores
the results may be a DM object or DB object, depending on units in which the
results are required.
The display should be in the format of feet and inches or met ers and
centimeters depending on the object on display.
16. Design constructors for the class in exercise 13
17. Design constructors for the class in exercise 15
18. Write a C++ Program to implement the following operations on stack
à Create an empty stack
à Add new item
à Delete an item
à Display the stack elements
19. Write a C++ Program to implement the following operations on Queue
à Create an empty Queue
à Add new item
à Delete an item
à Display the Queue elements
20. An educational institution wishes to maintain a database of its employees.
The database is divided into a number of classes whose hierarchical
relationships are shown in the following figure.
The
figure also shows the minimum information required for each class. Specify all
the classes and define functions to cr eate the database and retrieve individual
information as and when required The database created in Exercise 20 does
not include educational information of the staff. It has been decided to add this
information to teachers and officers (and not for typists) which will help the
management in decision making with regard to training, promotion, etc. Add
another data class called 
 that holds two pieces of educational
information, namely, highest qualification in general education and highest
professional qualification. This class should be inherited by the class  
and  . Modify the program of exercise 20 to incorporate these features.
21. Create Base class called   . Use this class to store 2
  type values
that could be used to compute the area of figures. Derive 2 specific classes
called  and   from the base   . Add to the base class, a
member function  
 to initialise base class data members and
another member function
    to compute and display the area of
figures. Make
    as the virtual function and redefine this function
in the derived classes to suit their requi rements.
Using these three classes design a program that will accept dimensions of a
triangle or 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 rectangle and as ba se and height in the case of triangle
22. Extend the program 21 to display the area of circles. This requires addition of
a new derived class   that computes the area of a circle. Remember, for
a circle we need only one value, its radius, but the get_dat a() function in the
base class requires two values to be passed.
23. 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 n umber of copies
required. If the requested copies are available, the total cost of the requested
copies is displayed; otherwise the message "required copies not in stock" is
displayed.
Design a system using a class called  with suitable member functions
and constructors. Use  operator in constructors to allocate memory space
required.
24. Inprove the system design in Exersise 23 to incorporate the following features
à The price of the books should be updated as when required. Use a
private member function to implement this
à The stock value of each book should be automatically updated as soon
as a transaction is completed
à The number of successful and unsuccessful transactions should be
recorded for the purpose of statistical analysis. Use   data
members to keep count of transactions.

You might also like