I always give a positive rating!
Language is C++
I know this looks really long, but this is actually
pretty easy.
Just follow the steps in the document below and paste
your code in the answer.
Thanks!
InClass 8 -Using & Writing Functions Goal In this project, you use some basic library functions and then write several of your own functions. This assignment consists of prompting for and reading several different input values and calling various functions on the input, some of the functions you write as part of the assignment 0 Learning Objectives How to call library functions The importance of data types in function parameters, see the last page of this assignment for warnings about submitting to Web-CAT!!! How to write your own functions To write function prototypes Make function calls o Write function implementation code Program Features See the output below for clarification 1. Call library functions, fabs() -- floating point absolute value a. Read 1 double input values, e.g. num1 b. Prompt the user for a real number in main() and use it for the parameter for this function call, "Encer a number (double): " c. Output the absolute value of numl with label "Absolute value: " d. You do not need a prototype for functions that you just use because any prototype is in the header that you might include, like <math>. e. You are also NOT writing the code for such functions. The function's code gets compiled into your code from libraries that are part of the compile process. The rest of these you need to write the functions yourself. I will provide lots of help with the code that goes inside the functions so that you can focus on calling and setting up the functions. You MUST put a prototype at the top of the file (or inside main()) aller your using namespace std; statement. Most of these functions return a value that your program outputs, except for the first function, which just prints something. 2. Write a function that prints a line as shown in the output examples. The function returns nothing; it just produces output, a. Prompt the Liser for a name in main() and use it for the parameter for this function call, "Enter a name: b. If the user enters 3i.-y, output "Billy uses and writes several functions !!!" c. prototype: void printHeader(string); 3. Write a function, called sumDigits(), that sumsup the digits of the number a. Prompt the user for a number in main() and use it for the parameter for this function call, "Enter a long number: b. Return the added up digits in the number, eg. for input 3679, you output 25 (because 3 - 6 + 7 + 9 = 25) w
e c. In a while loop, access each digit using mod (% 10), and cut off the last digit using integer division (10) d. prototype: int sumDigits (long val); e. cout for this must be in main() 4. Write a function called sumUp to add up the numbers from I to input, if the input is less than or equal to 111111. (You need an if statement in the function before you start the loop.) a. Again use the same number from #3 for the parameter b. Use a for loop in the function to add up the numbers. c. Return the added up numbers from 1 to the number entered, e.g. the sum for 22222 is 246919753; the sum for 10 is 55. d. If the input is above 111111, output "Too big!\n"and return 0 (You must use an if statement.) f. prototype: long sumUp(long value); cout for this must be in main() 5. Write a function called average30) that averages the 3 double values passed in as parameters and returns that average a. prototype: double average3(double num1, double num2, double num3); b. Prompt and read 3 double numbers in main() c. numl, num2 and num3 are not changed d. Retun the average value of numl + num2 - num3 by the function e. cout for this must be in main() 6. Write a function called up that returns the upper case letter of the value passed into it. If the parameter is NOT a lower case letter a-z, then the function returns the same value passed into the function, e.g parameter – 'c' returns "C", parameter - 'R' returns 'R', and parameter – '$ returns $. This should be a few lines of code using subtraction on the letter, not 26 il statements. a. prototype: char up(char letter); b. Prompt and read I char in main() letter not changed d. If the letter is a lowercase letter, convert it to uppercase and return it. If not, return it directly c. The cout for this must be in main C Example 1/0 (This shows 2 runs of the program.) Enter a number (double): -1.618 Absolute value: 1.6180 Enter a name : Joe Joe uses and writes several functions !!! Enter a long number: 898 Digits sum: 25 Sum up: 403651 Enter 3 numbers (doubles):20 30 40.3 The average value: 30.1000 Enter a letter (char): +
The uppercase: + second example ===================== Enter a number (double): 1.618 Absolute value: 1.6180 Enter a name : Jojo Jojo uses and writes several functions!!! Enter a long number: 99991 Digits sum: 37 Sum up: 704182740 Enter 3 numbers (doubles):20 30 25 The average value: 25.0000 Enter a letter (char): a The uppercase: A To get your going on this and make the assignment a reasonable size!), here is your main() program: // You need to add #includes, // using namespace std, and function prototypes. int main() { double numi, num2 num3, ab snuml, average; long inlong, sumd, sumup; char letter, letterl; string name; cout<< "Enter a number (double): " << fixed <<setprecision (4); cin>> numi; absnum1 = 7 // add function call #1 cout<< "Absolute value: " << absnuml << endl; cout << "prompt,"; cin >> ; printHeader > ; // #2 cout<< "\nEnter a long number: "; cin>> inlong; sumd = // add function call cout<< "Digits sum: <<sumd<<endl; #3 sumup = cout<< "Sum up: " // add function call #4 << sumup <<endl; cout<<"Enter 3 numbers (doubles): "; cin // read numbers to pass as parameters in next line
average = ; // add function call #5 cout<< "The average value: "<< average <<endl; cout<< "Enter a letter (char): "<<endl; cin>> letter; letterl = ; //add function call #6 cout<< "The uppercase: " << letter1 <<endl; return 0; 1, all of your function MUST be written down here, below main() You need to add #includes, using namespace, and prototypes. Then, you append the required functions below the main() function. Submit your program to Web-CAT For this assignment, Web-CAT will not only check the output of your program against the required output, the testing code will call your functions, check the return values, and check the output. If you do not correctly write the functions with the required parameters and return valucs, then your code may not even compile on Web-CAT even though your program runs perfectly fine on your computer. That is because my test code is expecting and requiring) the functions to match the assignment. If your code does not match the assignment, then my code and Web-CAT cannot compile, let along run your incorrect functions; it cannot "find" them.
I always give a positive rating! Language is C++ I know this looks really long, but this is actually pretty easy. Just f
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
I always give a positive rating! Language is C++ I know this looks really long, but this is actually pretty easy. Just f
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!