Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

programming language must be in c++ .Learn to declare &create void and non-void functions with or without input parameters. e Learn to call different type

programming language must be in c++ image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
.Learn to declare &create void and non-void functions with or without input parameters. e Learn to call different type of fucntions from main0 program Coding . Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc) * Keep identifiers to a reasonably short length . Use upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for all other identifiers (variables, methods, objects) . Use tabs or spaces to indent code within blocks (code surrounded by braces). This includes classes, methods, and code associated with ifs, switches and loops. Be consistent with the number of spaces or tabs that you use to indent. Use white spac Use comments properly before or after the ending brace of classes, methods, and blocks to identify to which block it belongs. e to make your program more readable File provided (right-click on it to download) Lab8.cpp (this is the skeleton of the program, right-click to download) . NestedForLoopepp (used as reference to design function #2) 1. Lab Description In order to write a "good" modular program, it is important that the program be composed of useful, well-defined functions. There are two types of C++ functions . System defined functions, such as the sqrt0, pow and randO funtions we learned and used in Lab #3 and #4 . User-defined functions. User defined functions can be further divided into two groups depending on whether a function does or does not return a value. void function no value is returned e non-void function: one value is returned Another topic of this lab is function parameters, some functions has none (0) parameters, where others may have one or more parameters. In C++, parameters are used to pass information into a function. For this lab, you are given the skeleton of Lab8cpp file, inside you will need to declare and create 4 different functions and call them from the main) by plugging in the actual parameters. Right click to download Lab8.cpp, be sure to name the file Lab&.cpp (again, no empty spaces and special characters are allowed, follow the naming conventions) For documentation purpose, at the beginning of each programming lab/assignment, you must have a comment block with the following information inside // FILENAME: Lab8.cpp AUTHOR: your name / ASU ID your 10 digits ASU ID I SPECIFICATION: short description of the program Besides the two libraries we included already, you need to include the sstream library as follows: #include sstream stands for String Stream, this library is used to get everything user entered from keyboard as a string first, then convert them into the corresponding correct data type (int double, char, etc) accordingly. We use it here to avoid reading in last line stroke which may cause the submission problem on Linux server. The general way to use it, for example, as the following segment of codes show, we want to get a double value from keyboard and save it inside a variable num. double num; //declare a string variable string userInput"" //user prompt cout >num; The C++ compiler requires specific information related to all functions activated in the program. To provide this information to the compiler, we must use a function declaration statement (or function prototype declaration). The syntax for declaring the function prototype is: return_data_type functionName (formal_parameterlist) . reture data type the type of the value returned by the function. When no value is returned, the type is "void function-name: the identifier of the function. By naming convention, normally we use verbs. formal parameter_list: a list of parameters with their types used in the function. When no parameters are used, i.e., the list is empty, just include the open and closed parentheses. don't forget the semicolon"at the end Example: A function named displayMenu that does not return a value, and does not require formal parameters can be declared as the following: void displayMenu(); //function #1 Besides below described: above function #1, in this lab, you need to declare three more other functions as Function#2: declare a function called showTriangle which takes a postive integer as input parameter and show, for example, if the integer entered is 8, the function should print the following triangle shape on screen. i.e. this function has no value to return and its return data type should be void 5 6 78 3 45 6 78 2 3 45678 1 2 3 45 6 78 Function#3: declare a function called printLetterGrade which takes two input parameters, the first one is a string represents a student's name, the second one is his/her test score, then the function should calculate and print the student's corresponding letter grade, for example, print the following message on screen (user input is in bold). According to the description here, this function has no value to return and its return data type should be void. Please enter the student's name: John Smith Enter the student's test score: 92.7 John Smith's letter grade is: A Function:4 declare a function called are a Triangle which takes a triangle's base and height as input parameter and returns the triangle's area. For this function, it has one return value and the value's data type should be double Enter the base & height of the triangle: 6.5 3.7 The area of the triangle is: 12.03 The function definition is a listing of the actual instructions that should be executed in the function. For example, in above step #2, we had a function called displayMenu, this function will display the following menu on screen and it should contain several cout ASU CSE100 Lab #8 - Functions 1. Show a triangle of numbers 2. Check student's letter grade 3. Compute a triangle's area 4. Quit the Program The function definition is composed of two parts: the function header and a function body The function body appears as follows: [local variable declarations] / a phrase in means "optional" executable statements; [return II- //optional NOTE: The function header does not end with a semicolon! The function header closely resembles the function prototype! . The function body: o requires a ''at the beginning and a '' at the end. o may or may not require declare local variables. If variables are needed in the function then these variables should be declared at the beginning of the function body o if the function is a non-void function, then there will always be the return statement(s) somewhere inside the fucntion. For function displayMenu, since it takes no input parameter and return no value, its header will be: void displayMenu ) Its body will simply contains a set of cout statements as follows: = "; cout

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions