Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Fundamentals of Programming I Worksheet I

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Fundamentals of Programming I

Worksheet I
1. Define the following terms:
Computer programming Algorithm
Programmer SDLC
Programming paradigm Compiler
Programming languages Assembler
Develop an algorithm for each of the following problems. Use flowchart and pseudocode
method of developing an algorithm.
An algorithm that:
2. Converts a mark for a course to its corresponding letter-grade. (You may set your
own scale for the grading)
3. Checks if a number is EVEN or ODD.
4. Counts and displays the number of even and odd occurrences in a given list of
integers.
5. Finds the minimum and maximum of two given numbers.
6. Finds the minimum and maximum numbers from a given list of numbers.
7. Searches for the Greatest Common Divisor (GCD) of two natural numbers.
8. Searches for the Least Common Multiple (LCM) of two natural numbers.
9. Converts a decimal number to its binary equivalent.
10. Finds the number of days in a month of the Gregorian calendar.
11. Displays the next day’s date, given today’s date.
12. That accepts two numbers and displays the product, sum, and difference of the
two numbers.
13. That reads a number and print the sum of the integers up to the number, i.e.
1 + 2 + 3 + 4 + . . .+ n
14. That reads a number n and prints 2n.

1
15. What does the following algorithm, described using a flow chart, do? Give the
pseudo code of the algorithm.

Start

Sum=0

i
1 10
1

Input x

Sum=x + Sum

Avg = sum/10

Print avg

End

16. What are the two phases in problem solving using computers? Describe each
phases in detail.
17. Describe compiled languages Vs. interpreted languages.
Worksheet II
1. What are the steps that we have to follow in order to have an executable C++
program? Describe each step.
2. What is a preprocessor directive? For what purpose do we use it?
3. Describe the three kinds of program errors?
4. Tell what kind of errors the compiler catches?
5. What kind of error is produced if you forget a punctuation symbol such as a semi-
colon?

2
6. Tell what type of error is produced when a program runs but produces incorrect
results?
7. Why every C++ programs must have a main function?
8. Define the following terms
• Source code • Executable code
• Object code • Syntax error
9. What is the difference between an algorithm and a program?
10. What are C++ statements? What ends every C++ statement?
11. What is the output of the following program?
#include <iostream.h>

int main()
{
cout << "Hello guys!";
cout << "welcome to:\n";
cout << "Introduction to programming!";
return 0;
}

Worksheet III

         Instruction  
• First,   draw   flow   charts   describing   the   algorithms   that   you   apply   to   solve   the  
following  problems  and  then  transform  the  algorithms  into  programs.    
1. Compute  the  value  of  each  legal  C++  arithmetic  expression.  If  the  expression  is  not  
legal,  explain  why.  Clearly  indicate  what  the  data  type  of  the  result  of  each  
expression  would  be.  
 
a) (1.0  /  4)  *  6  
b) (6  *  3)  %  5  
c) (3  /  4)  *  4  
d) (4.0  *  2)  %  5  
e) ((10  +  5  /  2)  /  3)  
 

3
2. Write  a  program  that  implements  the  following  algorithm.    
           Start  
             Read  the  total  hours  the  employee  has  worked,  TotalHours  
             Read  the  hourly  rate  of  pay  for  the  employee,  HourlyRate  
                GrossSalary    =  TotalHours    *    HourlyRate  
                Tax  =  GrossSalary  *  0.1  
            NetSalary      =      GrossSalary  -­‐  Tax  
           Display  NetSalary  
         Stop  
3. Write   a   program   that   calculates   and   displays   the   area   and   the   circumference   of   a  
circle  based  on  its  radius  entered  from  the  keyboard.  
4. Write   a   program   that   swaps   the   values   of   two   variables   and   displays   their   former  
and  current  values.  The  values  of  the  variables  are  to  be  entered  from  the  keyboard.  
5. Write   a   program   that   tells   whether   a   number   entered   from   the   keyboard   is   an   even  
or  an  odd  number.  
6. Write   a   program   that   tells   whether   a   number   entered   from   the   keyboard   is   a  
positive  number  or  a  negative  number  or  zero.  
7. Write  a  program  that  accepts  a  character  from  the  keyboard  and  displays  its  ASCII  
code.  
8. Write   a   program   that   tells   whether   a   character   entered   from   the       keyboard   is   in  
upper  case  or  in  lower  case  or  neither.  
9. Write   a   program   that   accepts   a   character   entered   from   the   keyboard   and   tells  
whether  it  is  a  digit  or  a  letter  or  a  special  symbol.  
10. Write   a   program   that   converts   a   temperature   given   in   Fahrenheit   into   Celsius   and  
vice  verse.  The  program  should  distinguish  temperature  entered  from  the  keyboard  
as   in   degree   centigrade   or   as   in   degree   Fahrenheit   by   the   letters   ‘c/C’   or   ‘f/F’   that  
must  be  written  in  front  of  the  numeric  values  of  temperatures.      For  example:-­‐    If  
the   user   enters   10   c   or   10   C,     the   program   must   understand   that   the   input   is   in  
degree   centigrade   so   it   should   change   to   degree   Fahrenheit   and   must   display     the  
temperature  as  50  f  or  50  F.  
 

4
11. Write   a   program   that   requests   the   user   to   input   his/her   height   in   cms   and   weight   in  
kg  from  the  keyboard  and  tells  the  user  whether  he/she  is  balanced,  underweight  or  
overweight.   A   balanced   person   must   weight   in   the   range   of   x   +   (10   percent   of   x).
  Where  x  =  height  in  cms  -­‐100.  
12. Write  a  program  that  calculates  and  displays  the  income  tax  of  a  salary  entered  from  
the  keyboard.  Your  program  must  calculate    taxes  according  to  the  following  rates:  
 
Up          to          200Br        0%  
200Br      –        600Br     10%  
600Br      –    1200Br       15%  
1200Br  –    2000Br     20%  
2000Br  –    3500Br     25%  
3500Br    &      above     30%  
 
For   example:-­‐   The   income   tax   of   a   gross   salary   of   900   Birr     is   85   Birr,   which   is  
calculated  as  (200*0%  +  400*10%  +  300*15%)=85  Birr.  
13. Write  a  program  that  tells  the  number  of  days  found  in  the  months  of  a  European  
calendar.  Where  the  month  and  the  year  are  to  be  entered  from  the  keyboard.  Your  
program  must  consider  leap  year  condition  along  with  other  conditions.  
14. Write  a  program  that  computes  and  displays  the  next  date  of  a  European  calendar  
date  entered  from  the  keyboard.  Your  program  must  consider  leap  year  condition,  
along  with  other  conditions.  
For   example:-­‐   The   next   date   of   24/11/07   must   be   computed   and   displayed   as  
25/11/07.  
15. Write a program that converts a mark of a course entered from the keyboard
to its corresponding letter-grade based on the following scales.
Mark Grade Mark Grade

>=90 A+ >=55 C+
>=80 A >=45 C
>=75 B+ >=30 D
>=60 B < 30 F

5
Note that all your programs must provide some mechanisms of
validating appropriate input entries.

You might also like