100 likes | 121 Views
Learn debugging skills in Visual Studio with practical exercises. Implement NiMo's varying rates program and extend it to include energy supply charges computation.
E N D
Lab Session-2 CSIT 121 Spring 2005 • Debugging Tips • NiMo’s Varying Rates • Lab-2 Exercise
Some Aspects of Visual Studio • Your project can be set in “Debug” or “Release” states (Build->Set Active Configuration) • In “Debug” state, you can apply several debugging options. • Debug is set by default • You can start debugging by invoking the debugger
Debugging Tips • Let us try a few simple steps • Open your source file, make a mistake and try to recompile it (demo) • The compiler gives an error message • Click on the error message • The compiler takes you to the line where the error is, press F1 to learn more
Starting the Debugger • Once you have compiled the project, you can start the debugger by first inserting breakpoints • A Breakpoint is where the program execution will halt • Thus you can see the values of variables at that point
Using the Debugger • Inserting breakpoints is very convenient way of stopping at a suspected problem location and examining the values of variables (Click the “hand” in the corner) • Using “GO” causes the debugger to run the program until the next break point • (Click on “Build”--> “Start Debug”-->GO)
NiMo’s varying rates • Example: Niagara Mohawk wants to apply different rates to its customers. If a customer burns more than 1000 units in a month, rate B is applied else rate A is applied. Develop a program that outputs the monthly bill given a customer’s consumption. • Test the program with two sample customers. One customer will have rate A (20 cents) applied and the other one will have rate B (17 cents) applied to the monthly bill.
NiMo’s varying rates • You develop the data model and algorithm for this problem • What is the input to your function? • Answer: • What is the output? • Answer: • What are the processing requirements? • Answer (A or B)*consumption • Write the algorithm on paper
NiMo’s varying rates • In our example, the program can be divided into three sections: • Write a code segment to get the rates • Write a code segment to process the charges • Write a code segment to output the charges • (Input Processing Output)
Programming Exercise Due Feb 9 • Extend the NiMo program by computing the monthly bill with the energy supply charge. Energy supply charge is different for rate A and rate B customers. For rate A customers, it is 10 percent of the energy bill. For rate B customers, it will be 8 percent of the bill. Add this charge to the bill and display the cumulative monthly bill with explanatory information.
Sample Run • How many units did you burn this month?1200 • Your Electricity Bill this month is • Energy Charges $204 • Supply Charges $16.32 • Total Charges excluding taxes $220.32 • ======================================= • How many units did you burn this month?900 • Your Electricity Bill this month is • Energy Charges $180 • Supply Charges $18 • Total Charges excluding taxes $198