Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Lab Session-XIV CSIT121 Fall 2000 b Tips for good programming b Complete Lab Exercise 13-B for Using Classes b Work on developing an object oriented.

Similar presentations


Presentation on theme: "1 Lab Session-XIV CSIT121 Fall 2000 b Tips for good programming b Complete Lab Exercise 13-B for Using Classes b Work on developing an object oriented."— Presentation transcript:

1 1 Lab Session-XIV CSIT121 Fall 2000 b Tips for good programming b Complete Lab Exercise 13-B for Using Classes b Work on developing an object oriented program for implementing a calculator

2 2 Tips for Good Programming b Always plan for your program on paper before starting on computer b For example, when implementing vending machine object, write down the number of items on sale and the user-interface of the machine

3 3 Tips for Good Programming b Divide the program into a number of functions, each one dedicated to a small task b In vending machine problem, write a separate function for buying items and another one for displaying remaining items

4 4 Tips for Good Programming b Before writing a function, write comments about it, including pre and post-conditions and what is it supposed to accomplish. Use meaningful variable names b For example, buy() function allows the user to buy an item. It subtracts one item from the machine’s contents and adds sale amount to total cash in the machine

5 5 Tips for Good Programming b To represent apple juice cans in the machine, declare a variable called b int apple_juice_cans; b instead of declaring b int var1; b Also constants are to be declared by name b For example, const int price_per_can=50

6 6 Tips for Good Programming b Use diagnostic messages if your program hangs and you see a blank screen b For example, use b cout<<“OK until this line”<<endl; b and keep moving this statement forward if you see it displayed in the output window

7 7 Lab Exercise 13-B for Handling Classes b A vending machine contains fruit juices and soft drinks. It can have a maximum of 10 apple juice cans, 10 orange juice cans, 10 mixed juice cans, 10 pepsi cans and 10 sprite cans. Users can buy one can at a time and more items can be added to the machine

8 8 Lab Exercise 13-B b Develop a program that models this vending machine as an object. It should have all items as private data items and buy/add functions as public functions. There should be another public function show() that shows (prints) all items and their current quantity available.

9 9 Lab Exercise 14-A b Declare a class calculator that has member functions add,subtract, multiply and divide. It has one private member named result. Only the member functions can access the result. Show implementation of at least two member functions. How will the client program use the result of one function for the other function. For example b (12+3)-5


Download ppt "1 Lab Session-XIV CSIT121 Fall 2000 b Tips for good programming b Complete Lab Exercise 13-B for Using Classes b Work on developing an object oriented."

Similar presentations


Ads by Google