C++ Assignments

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 ordinal numbers. Write a program where the user inputs a number, then the program prints the corresponding ordinal number. For example, if the user types 3, the program should respond with 3rd. 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"). Extensions 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. Extensions o Besides 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

Write a C++ Program to implement the following operations on Queue o Create an empty Queue o Add new item o Delete an item o Display the Queue elements 20. Write a program that can read values for the class objects and add one object DM with another object DB. Design constructors for the class in exercise 13 17. Design constructors for the class in exercise 15 18. Include the following data members o Name of the depositor o Account number o Type of account o Balance amount in the account Member Functions o o o o 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.13. . 16. Write a C++ Program to implement the following operations on stack o Create an empty stack o Add new item o Delete an item o Display the stack elements 19. The display should be in the format of feet and inches or met ers and centimeters depending on the object on display. An educational institution wishes to maintain a database of its employees. Create two classes DM and DB which store the value of distances. depending on units in which the results are required. Define a class to represent a bank account. Use friend function to carry out the addition operation. DM stores distances in meters and centimeters and DB in feet and inches. Modify the above class and the program for handling 10 customers 15. The object that stores the results may be a DM object or DB object. The database is divided into a number of classes whose hierarchical relationships are shown in the following figure.

Extend the program 21 to display the area of circles. title. a member function get_data() to initialise base class data members and another member function display_area() to compute and display the area of figures. If it is. If it is not. Make display_area() as the virtual function and redefine this function in the derived classes to suit their requi rements. The list includes details such as author. an appropriate message is displayed. publisher and stock position. but the get_dat a() function in the base class requires two values to be passed. Derive 2 specific classes called triangle and rectangle from the base shape . Add another data class called education that holds two pieces of educational information. Whenever a customer wants a book. Using these three classes design a program that will accept dimensions of a triangle or rectangle interactively and display the area. for a circle we need only one value. Use this class to store 2 double type values that could be used to compute the area of figures. A book shop maintains the inventory of books that are being sold at the shop. the total cost of the requested copies is displayed. the sales person inputs the title and author and the system searches the list and displays whether it is available or not. This class should be inherited by the class teacher and officer. 23. 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. 21. 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. price.The figure also shows the minimum information required for each class. If the requested copies are available. otherwise the message "required copies not in stock" is displayed. etc. Remember. then the system displays the book details and requests for the n umber of copies required. namely. 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. . Modify the program of exercise 20 to incorporate these features. This requires addition of a new derived class circle that computes the area of a circle. Add to the base class. its radius. Create Base class called shape . highest qualification in general education and highest professional qualification.

Use new operator in constructors to allocate memory space required.Design a system using a class called books with suitable member functions and constructors. Use static data members to keep count of transactions. . 24. Use a private member function to implement this o The stock value of each book should be automatically updated as soon as a transaction is completed o The number of successful and unsuccessful transactions should be recorded for the purpose of statistical analysis. Inprove the system design in Exersise 23 to incorporate the following features o The price of the books should be updated as when required.

Sign up to vote on this title
UsefulNot useful