Objective:
(a) The purpose of this part of the question is to ensure that you have installed MS Visual C++ Express Edition and to get you familiar with the steps in writing, compiling, and running a C++ program using the installed software.
(i) After you have installed MS Visual C++ Express Edition and registration on your machine, you area ready for the next step.
(ii) Create a new empty project. Please refer to https://msdn.microsoft.com/en-us/library/bb384842.aspx on how to create an empty project.
(iii) Add a source file. Please refer to Adding a Source File section in https://msdn.microsoft.com/en-us/library/bb384842.aspx. Name this cpp code file as ABCQ1a.cpp where ABC denotes the initials of your name.
int main() {
int x = 6, y = 3;
int a, c;
float b, k = 7.0;
bool r;
a = x++ *--y; // Line 1
b = x / y; // Line 2
c = x % y; // Line 3
k = k / y; // Line 4
r = k == b; // Line 5
cout << "(a)" << a << endl;
cout << "(b)" << b << endl;
cout << "(c)" << c << endl;
cout << "(k)" << k << endl;
cout << "(r)" << r << endl;
return 0;
}
(iv) Copy and paste the following code to this empty source code file.
(v) Compile and run the program.
(vi) Capture the output screen of the run. You can do this by using the Print Screen facility. Your keyboard should have a key labeled Print Screen or Prt Scr which can capture the contents of the active window. Pressing Alt + Print Screen will copy an image of the active window to the clipboard.
(vii) Open MS-Word and then Choose Edit|Paste to copy the clipboard contents into the blank document.
(b) Study the increment and decrement operator used in Line 1 of the program in Table 1.1. Explain how the line of code works using the respective operator.
(c) Describe the operations indicated in Line 2, Line 3, Line 5 of the program in Table 1.1.
(d) Demonstrate your ability to use C++ syntax to develop code to calculate the electricity bill of the domestic users. The program uses a loop to prompt the user to enter the name of the user and units consumed and calculates the charges based on the following:
-- For the first 200 units – 10c per unit
-- For the next 300 units – 20c per unit
-- Beyond 500 units (that is 501 and above) – 30c per unit
All uses are charged a minimum of $15. If the total amount is more than $100 then an additional surcharge of 15% of the total amount is added.
The program prints the total charges for the user with the name. The loop is control via the sentinel value, E.