0% found this document useful (0 votes)
67 views5 pages

Worksheet One

Haramaya University Cpp Worksheet

Uploaded by

neguyared837
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)
67 views5 pages

Worksheet One

Haramaya University Cpp Worksheet

Uploaded by

neguyared837
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/ 5

Haramaya University

Collage of Computing and Informatics

Department of Computing Science


Computer Programming

Worksheet I
1. Define the following terms:

Computer programming Algorithm

Programmer Compiler

Programming paradigm Assembler

Programming languages

2. Develop an algorithm for each of the following problems. Use flowchart and

Pseudocode method of developing an algorithm. An algorithm that:

a) Converts a mark for a course to its corresponding letter-grade. (You may set

your own scale for the grading)

b) Checks if a number is EVEN or ODD.

c) Check if a number received from the keyboard is divisible by 5 or not.

d) Counts and displays the number of even and odd occurrences in a given list

of integers.

e) Finds the minimum and maximum of two given numbers.

f) Finds the minimum and maximum numbers from a given list of numbers.

g) Converts a decimal number to its binary equivalent.

h) Finds the number of days in a month of the Gregorian calendar.

i) Accepts two numbers and displays the product, sum, and difference of the

two numbers.

j) Reads a number n and prints 2n.

k) Accepts a positive number form the keyboard and displays the value of the

following series.

1|Computer Programming Worksheet I


Sum = 1-32 +52 – 72+ … n2

3. Describe compiled languages Vs. interpreted languages.

4. Describe the three kinds of program errors using examples for each kind?

5. Why every C++ programs must have a main function?

6. What is the difference between an algorithm and a program?

7. What are C++ statements? What ends every C++ statement?

8. What is meant by identifiers? How is a user defined differs from a standard

(reserved) identifiers.

9. Explain what variables and constants are and describe their difference.

10. List out the types of operators used in C++. List out the five arithmetic operators and

give their associative rules. (Use examples).

11. Explain the difference between unary minus and binary minus using examples.

Programming questions

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)

2. The following is a Pseudocode for an algorithm that calculates a Net salary of a

given employee. Write a C++ program that implements this 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

2|Computer Programming Worksheet I


Stop

3. Write a program in C++ that calculates and displays the areas of the following

geometric figures. Note: Your program should ask the user for which figure type the

area should be calculated. Hint: use the switch construct.

a) Circle

b) Triangle

c) Rectangle

4. Write a program that swaps (assign the value of one for the other and vice versa) 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 converts a letter entered from the keyboard to its uppercase or

lower case equivalent.

10. 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.

11. Write a program in C++ to find the simple interest for a given principal, rate of

interest and number of years.

Simple interest = principal * interest rate * time.

12. Write a program in C++ to solve a quadratic equation. Hint: your program should

accept the value of a, b and c in ax2 + bx + c.

13. Write a program in C++ to find the compound interest for a given principal, rate of

interest and number of years.

3|Computer Programming Worksheet I


Compound interest = Ao (1 + r)n where Ao is the principal, r is the rate of interest

and n is the number of years.

14. Write a program in C++ to read a positive integer number n from a standard input

device to display the number and digit. For example for n= 2345 your program

should display the digits 2 3 4 and 5. Use the ‘/t’ to insert a space between the digits.

15. 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.

16. Write a program that converts a temperature given in Fahrenheit into Celsius and

vice versa. 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.

17. 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.

18. 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.
19. 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.

4|Computer Programming Worksheet I


20. 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/10/2024 must be computed and displayed as
25/10/2024.

21. 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.

22. 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
>=90 A+
>=80 A
>=75 B+
>=60 B
>=55 C+
>=45 C
>=30 D

< 30 F

5|Computer Programming Worksheet I

You might also like