Dev C Exercises

Dev C Exercises 3,7/5 1464 votes

We have gathered a variety of C exercises (with answers) for each C Chapter. Try to solve an exercise by editing some code, or show the answer to see what you've done wrong. Count Your Score. You will get 1 point for each correct answer. Your score and total score will always be displayed. Example explained. Line 1: #include is a header file library that lets us work with input and output objects, such as cout (used in line 5). Header files add functionality to C programs. Line 2: using namespace std means that we can use names for objects and variables from the standard library.

Dev-C++ is a free IDE for Windows that uses either MinGW or TDM-GCC as underlying compiler.
Originally released by Bloodshed Software, but abandoned in 2006, it has recently been forked by Orwell, including a choice of more recent compilers. It can be downloaded from:
http://orwelldevcpp.blogspot.com

Installation

Run the downloaded executable file, and follow its instructions. The default options are fine.

Support for C++11

By default, support for the most recent version of C++ is not enabled. It shall be explicitly enabled by going to:
Tools -> Compiler Options
Here, select the 'Settings' tab, and within it, the 'Code Generation' tab. There, in 'Language standard (-std)' select 'ISO C++ 11':
Ok that. You are now ready to compile C++11!

Compiling console applications

To compile and run simple console applications such as those used as examples in these tutorials it is enough with opening the file with Dev-C++ and hit F11.
As an example, try:
File -> New -> Source File (or Ctrl+N)
There, write the following:
Then:
File -> Save As.. (or Ctrl+Alt+S)
And save it with some file name with a .cpp extension, such as example.cpp.
Now, hitting F11 should compile and run the program.
If you get an error on the type of x, the compiler does not understand the new meaning given to auto since C++11. Please, make sure you downloaded the latest version as linked above, and that you enabled the compiler options to compile C++11 as described above.

Tutorial

You are now ready to begin the language tutorial: click here!.
< C++ Programming‎ Exercises

Q6a[edit]

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]

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++ For Windows 10

Q6c[edit]

3u tools not seeing all photos iphone. 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'