Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
124 views8 pages

CP 111: Principles of Programming Assignment Two (Group Assignment)

The document contains 5 questions regarding programming assignments. Question 1 asks about defining variables and data types for storing user information and performing calculations. Question 2 involves designing a program to track items bought and sold and calculate profits. Question 3 provides examples of pseudocode for calculations. Question 4 describes a program to record student information and results. Question 5 is about designing a program to manage daily purchases and sales at a cafeteria.

Uploaded by

lebafortunatus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
124 views8 pages

CP 111: Principles of Programming Assignment Two (Group Assignment)

The document contains 5 questions regarding programming assignments. Question 1 asks about defining variables and data types for storing user information and performing calculations. Question 2 involves designing a program to track items bought and sold and calculate profits. Question 3 provides examples of pseudocode for calculations. Question 4 describes a program to record student information and results. Question 5 is about designing a program to manage daily purchases and sales at a cafeteria.

Uploaded by

lebafortunatus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

CP 111: Principles of Programming

Assignment Two (Group Assignment)


Question One
a) You need an application that will store your names i.e. Juma Ally, Gender i.e. F or M, GPA i.e.
3.5 and marital status such as Single, Married etc. By applying rules for defining variables in
programming, suggest the appropriate variables and their associated data types (Note, each variable
and its associated data type should appear in one line).
b) Given the following equation a = b + c + d whereby b= 20.5, c = 0.1, d = 10
i. Based on the given equation and values of the variables suggest the appropriate data types
for each variable in the equation
ii. Assume a is declared as integer i.e. int a. suggest the value of a after execution of the above
equation
iii. What will happen when a is declared as char?
iv. T/F (True or False): In programming this equation in b) indicates that the value of the sum
of b, c and d (that is b + c + d) will be assigned to a.
v. T/F (True or False): In programming this equation in b) indicates that the value of the sum
of b, c and d (that is b + c + d) will be compared to a
vi. Represent the above equation variables and their values using RAM Diagram (block) and
explain what is happening in RAM.
vii. What is the difference between a = b + c + d and a = = (b + c + d) in programming?

Question Two
Mr. Gratian has a shop located at 77 in Dodoma region, dealing with buying and selling sunflower
oil. Mr. Gratian wants program that will record number of items in terms of liters bought and sold
per year. The program should also, accept the buying and selling prices for each liter. For each
category the program should also calculate the total purchase and selling amount per year. Lastly,
the program should determine the profit earned (if any).
Based on the given information determine:-
a) The variables associated with defined problem
b) For each variable in a) suggest the appropriate data types
c) Declare (in one line) the variable defined in a) using data types suggested in b)
d) Define the processes involved in this application
e) What variable values will be stored, displayed (printed) and inputted into and from a
program?
f) For each input variables, suggest the appropriated value and work through processes defined
in d) to determine the final values

Question Three: Write a Pseudocode for these problems


a) S = (A + B + C) / Y
b) Convert from Celsius to Fahrenheit (Multiply by 9, then divide by 5, then add 32 )
c) Area of Circle ( )

d) Volume of Sphere (

e) Average speed (

Question Four:
A programmer from UDOM was tasked to design and implement a C++ program that will record
information and results of Ifakara Primary School. The program will accept the student’s name,
student’s registration number, student’s age, student’s class level, and student’s scores.
After the March midterm examination, the five best students from level III were Alli, Amina, Aisha,
Aminiel, and Aneth. These students are aged 9, 8, 9, 7, and 7 years respectively. All students have
full registration with registration numbers IPSIII001, IPSIII011, IPSIII100, IPSIII87, and IPSIII92.
Aminiel was the best of all students with 95.5 marks. Amina, Aneth, Aisha, and Alli scored 95, 94.5,
93, and 92 respectively. Information of these students was used to test the developed C++ program.
The program works well by printing the report with the student’s registration numbers and respective
scores as well as the average score and the score of the highest performing student.
Answer the following questions regarding the scenario above:
a. Identify the program’s variables; suggest their respective variable names and their respective
data types.
b. Use the IPO chart to analyze scenario
c. Draw the flow chart for the above scenario
d. Write a Pseudocode for the above scenario

Question Five
The management of the Kikoti cafeteria at CIVE has decided to own an information system that will
help to manage the daily purchases and sales. The system records daily purchases and sales, and prints
the daily report of expenditure and sales. The report will show the total expenditure and the total sales
for that particular day.
To accomplish this task, the system has a module that comprises a computer program that accepts the
amount (in kg) of rice purchased, the amount (in kg) of meat purchased, and the number of bunches
of vegetables purchased. The program will also record the number of plates of rice sold, and the
number of bottles of soft drinks sold. The cashier will also record the price for each of the raw
materials purchased and the products sold.
At the end of the working hours, the cashier and the manager will be able to print the daily report.
Answer the following questions regarding the scenario above:
a. Identify the program’s variables; suggest their respective variable names and their respective
data types.
b. Use the IPO chart to analyze the scenario.
c. Draw the flow chart for the above scenario.
d. Write a Pseudocode for the above scenario.

ANSWERS
1a)
DATA VARIABLE DATA TYPE
Name Name String
Gender Gender Character
GPA GPA Floating point
Martial Status Martial_status String
b)

i.
1. VARIABLE 2. DATA TYPE
A Float
B Float
C Float
D Integer

d)The value of a is 30
e) It give a character as output =$
d) T
e) F
d) ram statue before variable declaration every cell of the computer memory is free
RAM

FREE



- RAM statue after variation declaration (float a , float b ,float c ,int d ) the memory
resourse space for the variable a,b,c,d respectively
RAM
Reserved



free

RAM Status after putting the value to the variable a,b,c,d

RAM

reserved
20.5
0.1
10
free

-RAM status after the process of b+c+d

RAM
30
20.5
0.1
10
free

f) A=B+C+D the value of b+c+d after process is assigned to a


A=b+c+d the value of a is compared to the value of b+c+d and it is true if is exactly
the same

3) To write the pseudocode of the following


a) S= (A+B+C)/Y
Solution
START
READ A,B,C,Y
SUM =A+B+C
S= SUM/Y
PRINT S
END
b) To convert from celcius to fare
Solution
START
INPUT CELCIUS ( C)
F =9/5*C+32
DISPLAY TEMPERATURE IN( T)
STOP
c) The area of circle
START
Input r
= r*r
Display Area
END

d) Volume of sphere
START
Input r
V= 4/3∗ ∗ ∗
Display V
END
g) Average speed
START
Input distance travel
Input time taken
Average speed = distance travel / time taken
Display average speed
END

4)
a)
VARIABLE VARIABLE NAME DATA TYPE
Student name Student_name String
Student registration Studentregistrationnumber Alphanumeric
number
Student age Student_age Integer
Student class level Studentclasslevel Integer
Student score Student_score Floating point

b)
INPUT PROCESSING OUTPUT
Student name Calculate average score Average score
Student registration number Calculate score of high Score of high performance
performance student student
Student age Display average score Registration number
Student class level Display high score
performance student
Student score

c) Flow chart

You might also like