Objective:

  • Setting up of the machine and running with the software and course team files correctly installed, if any.
  • Ability to declare variables with the suitable data type.
  • Understanding of selection construct and repetition construct

(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.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.