You are on page 1of 4

VALLEY VIEW UNIVERSITY

SCHOOL OF EDUCATION

DEPARTMENT OF MATHEMATICS AND SCIENCE EDUCATION  

END OF SECOND SEMESTER 2019/2020 (2ND SESSION) EXAMINATION

COSC221 PROGRAMMING WITH C++


 

INSTRUCTOR: KOFI SARPONG ADU-MANU

DURATION: 2 HOURS TOTAL MARKS: 100

INSTRUCTIONS:    

READ  ALL  INSTRUCTIONS  CAREFULLY.    


ANSWER  PART  A  (50  MARKS)  ON  THE  E-­‐‑LEARNING  SYSTEM  AND  PART  B  (50  
MARKS)  ON  SHEETS  OF  PAPERS.  
ATTEMPT  ALL  QUESTIONS.  
   
SUBMISSION  INSTRUCTION  

i.   Please  take  your  time  to  read  and  follow  the  instructions.  
ii.   Do  the  work  on  a  sheet  of  paper  (s)  with  your  NAME  and  ID  on  each  
page  (Preferably  A4).  
iii.   When  done,  take  a  picture  of  your  work.  (You  can  use  Microsoft  
Office  Lens  mobile  app  to  assist  you).  
iv.   Submit  your  work  by  uploading  the  pictures.  
v.   Follow  the  training  manuals  for  assistance.    

PART  B                     50  MARKS  

QUESTION  1                   [15  marks]    


a)   Roman  Numeral  Converter  
Write  a  program  that  displays  the  Roman  numeral  equivalent  of  any  decimal  number  
between   1   and   20   that   the   user   enters.   The   Roman   numerals   should   be   stored   in   an  
array  of  strings  and  the  decimal  number  that  the  user  enters  should  be  used  to  locate  
the  array  element  holding  the  Roman  numeral  equivalent.  The  program  should  have  
a  loop  that  allows  the  user  to  continue  entering  numbers  until  an  end  a  sentinel  of  0  
is  entered.                   [8  marks]  
 
b)   Fat  Gram  Calculator  
Write  a  program  that  asks  for  the  number  of  calories  and  fat  grams  in  a  food.  The  
program  should  display  the  percentage  of  calories  that  come  from  fat.  If  the  calories  
from  fat  are  less  than  30  percent  of  the  total  calories  of  the  food,  it  should  also  
display  a  message  indicating  the  food  is  low  in  fat.  
One  gram  of  fat  has  9  calories,  so  
Calories  from  fat  =  fat  grams  *  9  
The  percentage  of  calories  from  fat  can  be  calculated  as  
Calories  from  fat  ÷  total  calories  

Input  Validation:  The  program  should  make  sure  that  the  number  of  calories  is  greater  
than  0,  the  number  of  fat  grams  is  0  or  more,  and  the  number  of  calories  from  fat  is  not  
greater  than  the  total  number  of  calories.  

                    [7  marks]  

Page  2  of  4  
 
Question  2                     [10  marks]  
a)   Calories  Burned  

Running  on  a  particular  treadmill  you  burn  3.9  calories  per  minute.  Write  a  program  
that  uses  a  loop  to  display  the  number  of  calories  burned  after  10,  15,  20,  25,  and  30  
minutes.                   [5  marks]  

b)   Restaurant  Bill  

Write  a  program  that  computes  the  tax  and  tip  on  a  restaurant  bill  for  a  patron  with  
a   GHC44.50   meal   charge.   The   tax   should   be   6.75   percent   of   the   meal   cost.   The   tip  
should   be   15   percent   of   the   total   after   adding   the   tax.   Display   the   meal   cost,   tax  
amount,  tip  amount,  and  total  bill  on  the  screen.       [5  marks]  

Question  3                     [10  marks]  

a)    

i.    Convert  the  following  do-­‐‑while  loop  to  a  while  loop:  

char sure;
do
{
cout << "Are you sure you want to quit? ";
cin >> sure;
} while (sure != 'Y' && sure != 'N');
[2.5  marks]  

ii.    Convert  the  following  while  loop  to  a  for  loop:  

int count = 0;
while (count < 50)
{
cout << "count is " << count << endl;
count++;
}
[2.5  marks]  

 
Page  3  of  4  
 
b)   Average  Rainfall  

Write  a  program  that  calculates  the  average  monthly  rainfall  for  three  months.  The  
program  should  ask  the  user  to  enter  the  name  of  each  month,  such  as  June  or  July,  
and  the  amount  of  rain  (in  inches)  that  fell  that  month.  The  program  should  display  a  
message   similar   to   the   following:   The   average   monthly   rainfall   for   June,   July,   and  
August  was  6.72  inches.               [5  marks]  
 
Question  4                     [15  marks]  
a)   Population  

Write  a  program  that  will  predict  the  size  of  a  population  of  organisms.  The  program  
should   ask   the   user   for   the   starting   number   of   organisms,   their   average   daily  
population  increase  (as  a  percentage  of  current  population),  and  the  number  of  days  
they  will  multiply.  A  loop  should  display  the  size  of  the  population  for  each  day.  

Input  Validation:  The  program  should  not  accept  a  number  less  than  two  for  the  starting  
size  of  the  population,  a  negative  number  for  average  daily  population  increase,  or  a  
number  less  than  one  for  the  number  of  days  they  will  multiply.     [8  marks]  

b)   Mass  and  Weight  

Scientists  measure  an  object’s  mass  in  kilograms  and  its  weight  in  newtons.  If  you  
know  the  amount  of  mass  that  an  object  has,  you  can  calculate  its  weight,  in  newtons,  
with  the  following  formula:  
 
Weight  =  mass  ×  9.8  
 
Write  a  program  that  asks  the  user  to  enter  an  object’s  mass,  and  then  calculates  and  
displays  its  weight.  If  the  object  weighs  more  than  1,000  newtons,  display  a  message  
indicating   that   it   is   too   heavy.   If   the   object   weighs   less   than   10   newtons,   display   a  
message  indicating  that  the  object  is  too  light.            
                    [7  marks]  
 
SUBMISSION  INSTRUCTION  

i.   Please  take  your  time  to  read  and  follow  the  instructions.  
ii.   Do  the  work  on  a  sheet  of  paper  (s)  with  your  NAME  and  ID  on  each  page  (Preferably  
A4).  
iii.   When  done,  take  a  picture  of  your  work.  (You  can  use  Microsoft  Office  Lens  mobile  
app  to  assist  you).  
iv.   Submit  your  work  by  uploading  the  pictures.  
v.   Follow  the  training  manuals  for  assistance.    

ALL THE BEST!!!


Page  4  of  4  
 

You might also like