0% found this document useful (0 votes)
97 views2 pages

Introduction To Computer Programming (Meng 1052) Worksheet 2: Functions, Arrays and Strings Functions

This document provides examples of functions, arrays, and strings exercises for a computer programming course. It includes functions to calculate quality points from grades, hypotenuses of triangles, determine if a number is perfect, determine if a number is prime, and print shapes. It also provides array and string exercises to find minimum and maximum values, sort numbers, calculate letter grades from test scores with input validation, reverse words, and count vowels in names.

Uploaded by

Addisu Dagne
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)
97 views2 pages

Introduction To Computer Programming (Meng 1052) Worksheet 2: Functions, Arrays and Strings Functions

This document provides examples of functions, arrays, and strings exercises for a computer programming course. It includes functions to calculate quality points from grades, hypotenuses of triangles, determine if a number is perfect, determine if a number is prime, and print shapes. It also provides array and string exercises to find minimum and maximum values, sort numbers, calculate letter grades from test scores with input validation, reverse words, and count vowels in names.

Uploaded by

Addisu Dagne
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/ 2

Introduction to Computer Programming

(MEng 1052)
Worksheet 2: Functions, Arrays and Strings
Functions
1. Write a function QualityPoints that inputs a student’s average and returns 4 if a student’s
average is 90–100, 3 if the average is 80–89, 2 if the average is 70–79, 1 if the average is
60–69 and 0 if the average is lower than 60.
2. Write a function hypotenuse that calculates the hypotenuse of a right triangle when the other
two sides are given. The function should take two double arguments and return the
hypotenuse as a double.
3. An integer is said to be a perfect number if the sum of its divisors, including 1 (but not
the number itself), is equal to the number. For example, 6 is a perfect number, because 6
= 1 + 2 + 3. Write a function called isPerfect that determines whether parameter number
is a perfect number. Use this function in a program that determines and prints all the
perfect numbers between 1 and 1000.
4. An integer is said to be prime if it’s divisible by only 1 and itself. For example, 2, 3, 5
and 7 are prime, but 4, 6, 8 and 9 are not. Write a function called isPrime that determines
whether a number is prime. Use this function in a program that determines and prints all
the prime numbers between 2 and 10,000.
5. Write a function that prints the following shapes

(a) (b)

1
Arrays and Strings

6. Write a C++ program that accepts 10 integers from the user and finally displays the
smallest value and the largest value.
7. Write a program that accepts ten different integers from the user and display these
numbers after sorting them in increasing order.
8. Write a C++ program that calculates the letter grades of 20 students. The program should
accept the mid result and the final result from the students. Use the appropriate validity
control mechanism to prevent wrong inputs.
9. Write a C++ program that accepts a word from the user and then displays the word after
reversing it.
10. Develop a C++ program that accepts the name of a person and then counts how many
vowels the person’s name have.

You might also like