Assignment 1
Assignment 1
1
1.) Write a function that, when you call it, displays a message telling how many times it
has been called: “I have been called 3 times”, for instance. Write a main() program that
calls this function at least 10 times. Try implementing this function in two different ways.
First, use a global variable to store the count. Second, use a local static variable. Which
is more appropriate? Why can’t you use a local variable?
2.) Create a class phone having data members: 1. The STD code 2. The Exchange code
3.Phone Number Ex :- 212-766-8901 Write a C++ program to accept details from user
(max 10) and change input phone number to new phone number using following criteria:
c) In 3rd part of structure, 1st two digits should be reversed. Ex: I/P : 212-766-890 =>
O/P : 312-766-980 Display all changed phone numbers.
3.) A common place to buy candy is from a machine. The machine sells candies, chips,
gum, and cookies. You have been asked to write a program for this candy machine.
1. Show the customer the different products sold by the candy machine.
4.) An electricity board charges the following rates to users – For first 100 units : 40p per
unit – For next 200 units : 50p per unit – Beyond 300 units : 60p per unit All users are
charged a minimum of Rs.150. If the total cost is more than Rs.250.00 then an additional
charges of 15% are added. Write a C++ program using class to read the name of users
& number of units consumed & print out the charges with names.
5.) Write the definition for a class called Distance that has data member feet as integer
and inches as float. The class has the following member functions:
void set(int, float) to give value to object void disp() to display distance in feet and
inchesDistance add(Distance) to sum two distances & return distance.