0% found this document useful (0 votes)
9 views

Function

The document outlines 9 programming tasks involving defining and calling functions in C++. The tasks include writing functions to: 1) check if a character is a vowel, 2) sum two integers, 3) return the larger of two integers, 4) check if a character is lowercase, 5) calculate the distance between two points, 6) calculate the average of student marks in an array, 7) print elements of an array, and 8) convert between 12-hour and 24-hour time notation with menu options. Additional tasks include defining functions to: 9a) initialize variables, 9b) get user input for hours and pay rate, 9c) calculate pay, 9d) print pay details, 9e) modify a

Uploaded by

Doaa Idais
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Function

The document outlines 9 programming tasks involving defining and calling functions in C++. The tasks include writing functions to: 1) check if a character is a vowel, 2) sum two integers, 3) return the larger of two integers, 4) check if a character is lowercase, 5) calculate the distance between two points, 6) calculate the average of student marks in an array, 7) print elements of an array, and 8) convert between 12-hour and 24-hour time notation with menu options. Additional tasks include defining functions to: 9a) initialize variables, 9b) get user input for hours and pay rate, 9c) calculate pay, 9d) print pay details, 9e) modify a

Uploaded by

Doaa Idais
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Lab1: Function.

1. Write a complete c++ Program to input a character, send the character to the function and if
the character is vowel (‘a’,’e’,’i’, ‘o’,’u’, ‘y’) return true otherwise return false. (Using this
function prototype): bool isVowel(char x).

2. Write a program to declare two integer variable, input the values from the keyboard and
send them to the function to return their sum:
(using this function prototype): int getSum(int a, int b);

3. Write a program to input two integers values, send them to a function and return the larger
value. (using this function prototype): int larger(int x, int y);

4. Write a program to prompt the user to input a character and send it to the function to return
true if the letter is small otherwise return false (using this function prototype): bool
isSmall(char letter);

5. Write a program to prompt the user to input four integer variables namely x1,x2,y1,y2. And
send them to a function to calculate the distance using the following formula: √((x2-x1)^2)+
(y2-y1)^2 )
(using this function prototype): double getDistance(int x1, int x2, int y1, int y2);

6. Write c++ program that ask the user to enter five marks of a student and save then into
array, then calculate the average of these marks using function.

7. Write a c++ program that ask the user to enter element of an array of size 5 then print them
using a function.

8. Write a program to convert the time from 24-hour notation to 12-hour notation and vice
versa. Your program must be menu driven, giving the user the choice of converting the time
between the two notations. Furthermore, your program must contain at least the following
function: a function to convert the time from 24-hour notation to 12-hour notation, a
function to convert the time from 12-hour notation to 24-hour notation, a function to display
the choices, function(s) to get the input, and function(s) to display the results. (For 12-hour
time notation, your program must display AM or PM.)

9. Consider the definition of the function main.


int main()
{
int x, y;
char z;
double rate, hours;
double amount;
.
.
.
}
The variables x, y, z, rate, and hours referred to in items a through f below are the variables
of the function main. Each of the functions described must have the appropriate parameters
to access these variables. Write the following definitions:
a. Write the definition of the function initialize that initializes x and y to 0 and z to the blank
character.
b. Write the definition of the function getHoursRate that prompts the user to input the hours
worked and rate per hour to initialize the variables hours and rate of the function main.
c. Write the definition of the value-returning function payCheck that calculates and returns the
amount to be paid to an employee based on the hours worked and rate per hour. The hours
worked and rate per hour are stored in the variables hours and rate, respectively, of the
function main.

The formula for calculating the amount to be paid is as follows: For the first 40 hours, the
rate is the given rate; for hours over 40, the rate is 1.5 times the given rate.
d. Write the definition of the function printCheck that prints the hours worked, rate per hour,
and the salary.
e. Write the definition of the function funcOne that prompts the user to input a number. The
function then changes the value of x by assigning the value of the expression 2 times the
(old) value of x plus the value of y minus the value entered by the user.
f. Write the definition of the function nextChar that sets the value of z to the next character
stored in z.
g. Write the definition of a function main that tests each of these functions.

You might also like