0% found this document useful (0 votes)
2 views

Assignment 1

The document outlines a programming assignment consisting of five tasks. The tasks involve writing functions and classes in C++ to perform various operations such as counting function calls, managing phone numbers, simulating a candy machine, calculating electricity charges, and defining a Distance class. Each task includes specific requirements and criteria for implementation.

Uploaded by

23f3000485
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Assignment 1

The document outlines a programming assignment consisting of five tasks. The tasks involve writing functions and classes in C++ to perform various operations such as counting function calls, managing phone numbers, simulating a candy machine, calculating electricity charges, and defining a Distance class. Each task includes specific requirements and criteria for implementation.

Uploaded by

23f3000485
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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:

a) Add 1 to 1st digit of STD code. (If digit is 9 it becomes 10)

b) The exchange code is retained as it is.

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.

The program should do the following:

1. Show the customer the different products sold by the candy machine.

2. Let the customer make the selection.

3. Show the customer the cost of the item selected.

4. Accept money from the customer.

5. Release the item.

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.

You might also like