You are on page 1of 8

The Mico University College

Department of Computer Studies


Structure Programming

Worksheet 1
Due: February 1, 2019
____________________________________________________________________________
Part A

1. Fill in the blank in each of the following statements:


a. _______________ are used to document a program and improve its readability.
b. A variable declared as ____________ can only store whole numbers, however
variables declared as ____________ and _____________ can store rational
numbers.
c. In C++ ___________________ is used for input while ________________ is
used for output.
d. What arithmetic operations have the same precedence as multiplication?
_________
e. When parentheses are nested, which set of parentheses is evaluated first in an
arithmetic expression? ________________
f. A location in the computer’s memory that may contain different values at various
times throughout the execution of a program is called a _______________.
6 marks

2. Given that y=ax3 + 9, which of the following are correct C++ statements for this
equation? 3 marks
a. y = a * x * x* x + 9;
b. y = a * x * x * (x + 9);
c. y = (a * x) * x * (x + 9);
d. y = (a * x) * x * x + 9;
e. y = a * (x * x * x) + 9;
f. y = a * x * (x * x + 9);

3. Write an application that displays the numbers 1 to 4 on the same line, with each pair of
adjacent numbers separated by one space. Write the program using the following:
a. One cout statement
b. Four cout statements 2 marks

4. Write an application that asks the user to enter two numbers, obtains the numbers from
the user and prints the sum, product, difference and quotient (division) of the numbers.
5 marks

3. Create a program that prompts a user for her name and return a greeting back to the user
using her name. 1 mark
4. Create a new program that prompts the user for the current year and the year he or she was
born. Your program should then calculate and print the user’s age.
Current Age = Current Year * Year of Birth. (Ensure that the year of birth is not after the current
year) 3 marks

5. Build a new program that prompts a user for data and determines a commission using the
following formula:

Commission = Rate * (Sales Price – Cost). 4 marks

[Total - 24 marks]
***Good Luck***
---------------------------------------------------
The Mico University College
Department of Computer Studies
Structured Programming

Worksheet 2
Due: February 14, 2019
____________________________________________________________________________

1. A program is required to read a customer’s name, and purchase amount and determine the
sales tax based on the following;

Purchase Amount Sales Tax rate (% of purchase amount)


Below 300 tax exempt (0%)
300 to 1000 sales tax (3%)
Over 1000 but lesser than 5000 sales tax (5%)
5000 and over sales tax (9%)

The program must then compute the sales tax and the total amount due, and print the customer’s
name, purchase amount, sales tax and total amount due. 10 marks

2. Create a counting program that counts from 0 to 300 in increments of 30.


3 marks

3. Create a counting program that counts backward from 1000 to 0 in increments of 100.
3 marks

4. Write a program that does the following sequence of tasks:


i. Generate a random number in the range of 1 to 50
ii. Prompt the user to guess the number that was generated. Your program should not accept
more than 5 guesses from the user.
iii. If the user guess the number correctly, print the statement “Bingo, You guessed right”; if
the user enters an incorrect guess print the statement (“I’m sorry please try again and the
number of chances left”) 10 marks

5. Design an algorithm that will prompt for and receive an age in years and calculate and display
the age in months. If the calculated months figure is more than 300, four asterisks should also
appear beside the month figure. Your program is to continue processing until a sentinel of 555 is
entered. 5 marks

6. Write an application that inputs from the user the radius of a circle and prints the circle’s
diameter, circumference and area. Use the value 3.14159 for π. Use the following formulae:
Diameter=2r
Circumference = 2πr
Area = πr2 6 marks
7. Write an application that reads five integers and determine and print the largest and smallest
integers in the group. 6 marks
8. Write an application that reads in two integers and determines and print if the first is a
multiple of the second. [Hint: use the modulus operator] 5 marks

[Total 48 marks]
***Good Luck***
The Mico University College
Department of Computer Studies
Structured Programming
Worksheet 3
Due: February 28, 2019
____________________________________________________________________________
Functions
1. Write a function prototype for the following components: 12 marks
a. i. A function <Sum> that accepts two parameters and calculate and prints their sum.
ii. A function <Sum> that accepts three parameters and calculate and prints their
sum.
Iii A function <Sum> that accepts four parameters and calculate and prints their sum.

b. A function <Shout> that accepts a string as its parameter and display it, following by the
cursor on a new line.

c. A function <Remainder> that accepts two parameters, divides them and returns the
remainder.

d. A function <Quotient> that accepts two parameters, calculates and return the quotient of
the two numbers.

e. A function <Larger> that accepts two parameters; it should then finds the larger of two
numbers and returns the result

g. A function <Calculator> that prints an the menu below—it receives no parameters


and returns no value

CALCULATOR – MENU

1………Sum
2………Quotient
3………Remainder
4……....Larger
5………Exit

2. Build the function definitions for each preceding function prototype. 32 marks
3. Create the following main method:

int main()
{
int a,b,c,d;
int choice=0;
Shout(“Enter a number”);
cin>>a;
Shout(“Enter a number”);
cin>>b;
Shout(“Enter a number”);
cin>>c;
Shout(“Enter a number”);
cin>>d;

while (choice != 5){


//call the calculator method here
if (choice = = 1){
cout<<Sum(a, b);
//print the sum of the first three numbers
//print the sum of the four numbers
}
else if(choice = = 2){
//print the quotient of the first two numbers
//use the quotient method
}
else if(choice = = 3){
//print the remainder of the first number divided by the second
//use the remainder method
}
else if(choice = =4){
//use the Larger method to print the larger of the first two numbers
}
cin>>choice;
}

return 0;
} 14 marks

4. Write a program to prompt a user to enter three decimal numbers. The program should find the
maximum, minimum and average of the numbers. (create appropriate functions)
12 marks

[Total 70 marks]
***Good Luck***
The Mico University College
Department of Computer Studies
Structured Programming
Worksheet 4
Due March 8, 2019
____________________________________________________________________________
Based Arrays, Pointers, Strings
1. Build a program that uses a single dimension array to store 7 numbers inputted by a user. After
Inputting the numbers, the user should see a menu with two options to quit or to print the 7
numbers. 10 marks

2. Create a student GPA average calculator. The program should prompt the user to enter up to 5
GPAs, which are stored in a singledimension array. Each time he or she enters a GPA, the user
should have the option to calculate the current GPA average or enter another GPA. Sample data
for this program is shown below.
∙ GPA: 3.5
∙ GPA: 2.8
∙ GPA: 3.0
∙ GPA: 2.5
∙ GPA: 4.0
∙ GPA: 3.9
∙ GPA Average: 3.25
Hint: Be careful to not calculate empty array elements into your student GPA average.
10 marks

3. Create a program that allows a user to enter up to five names of friends. Use a twodimensional
array to store the friends’ names. After each name is entered, the user should have the option to
enter another name or print out a report that shows each name entered thus far.
10 marks

4. Build a program that performs the following operations:


a. Declares three pointer variables called iPtr of type int, cPtr of type char, and fFloat of type
float.

b. Declares three new variables called iNumber of int type, fNumber of float type, and Character
of char type.
 Assigns the address of each nonpointer variable to the matching pointer variable.
 Prints the value of each nonpointer variable.
 Prints the value of each pointer variable.
 Prints the address of each nonpointer variable.
 Prints the address of each pointer variable. 10 marks

5. Create a program that allows a user to select one of the following four menu options:
a. Enter New Integer Value
b. Print Pointer Address
c. Print Integer Address
d. Print Integer Value
For this program you will need to create two variables: one integer data type and one pointer.
10 marks

6. Create a program that performs the following functions:


a. Use character arrays to read a user’s name from standard input.
b. Tells the user how many characters are in his or her name.
c. Displays the user’s name in uppercase. 10 marks

9. Create a program that uses the strstr() function to search the string, “When the going gets
tough, the tough stay put!” for the following occurrences (display each occurrence found to
standard output):
a. “Going”
b. “tou”
c. “ay put!” 10 marks

[Total 70 marks]
***Good Luck***

You might also like