BACS1013 & BACS1014 Problem Solving and Programming Tutorial 1
Tutorial 1 - Intro & Basic Elements of C++
1. Define the following terms:
(a) Syntax
(b) Compiler
(c) Algorithm
2. Describe the full process on how a C++ source code is compiled and executed. Illustrate your answer
with an appropriate diagram.
3. Describe the following tools and their advantages in planning a program:
(a) Structure chart
(b) Pseudocode
(c) Flowchart
4. Differentiate between a structure chart and an organization chart. jjto aid your answer.
5. Draw a flowchart to represent the Pseudocode below:
if code is equal to ‘1’
display “junior”
assign 800.00 to salary
else if code is equal to ‘2’
display “senior”
assign 1200.0 to salary
else
display “Wrong code!”
6. According to this institution exam grading system, design an algorithm by using Pseudocode to display
the GPA (Grade Point Average) based on the total grade points of the courses and the total credit
hours.
7. Differentiate between compilation error and runtime error.
8. Give THREE (3) reasons why it is important to provide comments in your code. Demonstrate in two
different ways of writing comments using C++.
9. Identify invalid identifier(s) and explain the reasons why they are invalid.
a) 40Hours k) my_age
b) year l) Get Data
c) cost_in_$ m) Double
d) number1 n) A4
e) include o) mark&score
f) int p) first name
g) box-44 q) 5th-Edition
h) Student-name r) Page#
i) DVD_ROM s) C++
j) 2morrow t) 1stName
Page 1 of 3
BACS1013 & BACS1014 Problem Solving and Programming Tutorial 1
10. Write the output of the following segments of code:-
(a) cout << "\"\\nnow\"";
(b) cout << "A1 \"Butch\" Jones”;
(c) cout << "\"Hello\\\n Gandalf!";
11. Briefly explain and correct the error(s) in each of the code segments below.
(a) string word;
cout << "Enter a word: ";
cin << word;
(b) cout << "Two plus two is " 2+2;
(c) double invest = 2000.0;
double return = 1.016 * invest;
cout << "The return on your investment of $"
<< invest << " is $" << return;
(d) int x, y;
cin << x << y;
12. Determine the appropriate data type for the following data:
(a) The average of four marks.
(b) The number of days in a month.
(c) The length of the Penang Bridge.
(d) The number of students in your class.
(e) The distance from your house to TAR UC KL in kilometers.
(f) The single-character prefix that specifies a product type.
13. Code the variable definitions for each of the following:
(a) A character variable named option.
(b) An integer variable, sum, initialized to 0.
(c) A floating-point variable, product, initialized to 1.
14. Write single C++ statement to perform each of the following tasks:
(a) Declare num1, num2, and num3 as integer type variables.
(b) Declare tempA, tempB, and tempC as double precision type variables. Initialize tempA
to value 28.9.
(c) Declare let1 as a character type variable and initialize it to value ‘a’.
(d) Declare variable rate as memory constant with value 2.95
(e) Assign the letter “B” to the char variable initial.
(f) Sends the value in variable name to the stream cout
15. Write pseudocode for a program that calculates the current balance in a bank account. The program
must ask the user for
● the starting balance
● the total amount of deposits made
● the total amount of withdrawals made
Once the program calculates the current balance, it should be displayed on the screen.
Page 2 of 3
BACS1013 & BACS1014 Problem Solving and Programming Tutorial 1
16. Write pseudocode for a program that calculates the total of a retail sale. The program should ask
the user for
● the retail price of the item being purchased
● the sales tax rate
Once these items have been entered, the program should calculate and display
● the sales tax for the purchase
● the total of the sale
17. Provided algorithm is to find the perimeter and area of the rectangle is as follow:
1. Get the length of the rectangle.
2. Get the width of the rectangle.
3. Find the parameter using the following equation:
Perimeter = 2 X (length + width)
4. Find the area using the following equation:
Area = length X width
5. Display Perimeter and Area of the rectangle
Write C++ statements for each algorithm step specified above.
Page 3 of 3