Dev C Exercises

C functions 1. Write a C program that will display the calculator menu. The program will prompt the user to choose the operation choice (from 1 to 5). Loop programming exercises and solutions in C June 20, 2015 Pankaj C programming C, Exercises, Loop, Programming In programming, there exists situations when you need to repeat single or a group of statements till some condition is met.

< C++ Programming‎ | Exercises

Q6a[edit]

Dev C Exercises

Write a program named question6a.cpp that will calculate and print pay slips. User inputs are the name of the employee,the number of hours worked and the hourly pay rate. You have to declare three functions.d) one for input;e) one to calculate the employee’s pay; andf) one to print the payslip.The input function has to input the name of the employee, the number of hours worked and the hourly pay rate into thevariables theEmployee, theHoursWorked and thePayRate. The variable employee is a string and the other twovariables are of type float. As the values of theEmployee, theHoursWorked and thePayRate will be changed inthis function, reference parameters need to be used.The calculation function will receive two parameters that represent the number of hours worked and the hourly pay rate,do the calculation and return the pay for the employee. An employee, who has worked more than 40 hours, is paid 1.5times the hourly pay rate for each hour of overtime. As the parameters are not changed in the function, they should bevalue parameters. The function should return a float value which represents the pay.The output function has to display the name of the employee, the number of hours worked, the number of overtime hoursand the hourly pay rate entered by the user as well as the employee’s pay. For example:

Pay slip for Harry MatsipeHours worked: 43.5 hoursOvertime hours: 3.5Hourly pay rate: R125.35Pay: R5672.09

The main function includes a for loop that allows the user to repeat the calculation of a pay slip for five employees. Wegive the main function below. You must submit the three functions you have developed as well as output for repeatingthe loop five times with the following input data:Harry Matsipe 43.5 125.35Ellen Malan 39.4 112.75Joey Rashdien 40 120.45Mpho Bopape 41.2 123.60Veli Singh 39.7 135.30

Q6b[edit]

Dev C++ Exercises

NuMetro has a special on movies for all members of the public but special discounts for students and pensioners. Ifpensioners or students buy a movie ticket they receive 10% if they buy a movie and popcorns, they receive 20% discount. 100Other customers only receive a discount when they buy a movie ticket and popcorn; there is no discount for just a movieticket alone. Write a program named question6b.cpp that will consist of two functions. The program must prompt theuser for type of customer (‘p’ for pensioner, ‘s’ for student, ‘o’ for other). It must then call the relevant function accordingto that entry. The first function must receive the customer type and calculates discount for pensioners and students. Thesecond function calculates the discount for customers that are not pensioners or students.

Dev C++ 5.11

Q6c[edit]

Dev C++ Download Windows 10

Write a program named question6c.cpp that demonstrates the use of the following functions. A C++ function namedgetName()prompts the user for two string values; first name and last name and return a combination of the two asone value. The second function getHours()calculate employee’s weekly pay, it must receive one argument,fullName, a string variable and a float value for the rate. It must then prompt the user for hours worked for eachday of the week, i.e. Monday – Friday and calculates the weekly pay. Employees who have worked more than 40 hoursthat week will receive a bonus of 10% and those who have worked less than 40 hour will receive 10% less pay for thatweek.

Dev C++ Online

Retrieved from 'https://en.wikibooks.org/w/index.php?title=C%2B%2B_Programming/Exercises/Iterations&oldid=3434151'