Professional Documents
Culture Documents
Worksheet 1
Due: February 1, 2019
____________________________________________________________________________
Part A
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:
[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;
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
3. Create a counting program that counts backward from 1000 to 0 in increments of 100.
3 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
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;
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
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
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***