Homework # 4: CS 109 0 FALL. 2017/COMPUTER SCIENCE Alabama A&M; University DUE D
ID: 3607147 • Letter: H
Question
Homework # 4: CS 109 0 FALL. 2017/COMPUTER SCIENCE Alabama A&M; University DUE DATE: Wednesday, 10/18/2017 Each stadent must submit this work by due date SUBMIT ONLINE 2. Define a function Print that takes an integer N as imput, and prints (displays) a square of stars keeping N rows and N columns. ic. if N -3, the display should look like Answer cach question a) Suppose you have two fiunction definitions with the following fimction declarations: IrN - 4, then i should kook like double Scorefdouble time, double distance) int Score(double points) Which function definition would be used in the following function call and why it be the one used double x; ch>>x final score Scoretx) Now modify the function so that instead of printing a star, it should print an user specificd character chl. and send that variable as an input to the fanction Call this function from main properly, so that takes only one input N and displays the stars property b) What's wrong with the following function? vold Sqwarefint x) 3. In cold weather, meteorologists report an index called the windchill factor that takes into ntyx" return y account the wind speed and the temperature. The index provides a measure of the chilling effect of wind at a given air temperature. Windchill may be approximated by the formala: W 13.12 0.62151-11.37 VH+0.39651v Where c) In the following function title, which parameters are value parameters and which are reference v wind speed in m/s void ExamPrep(string&name;, int age, float& salary, char level) both double variable and a character variable opType, and returns a double valuC a Boolean value TRUE or FALSE depending on if the number is even or odd. To test temperabure in degree Celsius t must be less than or equal to 10 to use this formala W windchill index (in degrces Celsms) d) Declare a fanction named MathOp that takes three imputs as parameters: a and b Wnite a fanction dhat takes v and t as inputs and retums the windchill index W. Your code should ensure that the restriction on the tenaperature is not violated c) Define function lsEven(number) which takes an integer number as input and tetras if the mumber is even, find out if the remainder is 0 when divided by 2Explanation / Answer
Hi,
I have answered from a till e questions.
Ans a) The function which is used in the function call in below code is-
int Score(double points);
This is because function "int Score" is called with one parameter. Out of two given function definitions given above, the function "double Score" expects two arguments but "int Score" expects one argument. As while calling the function only one argument "x" is passed, hence int Score wil be called.
Ans b) The function "Square" is written with return type as "void" which mean it will not return anything. But we could see that inside its definitionm it is returning "y" value which is integer type. Hence, to correct the code, we need to chnage the return type as "int".
Ans c)
reference parameters - string & name, float &salary
value parameters - int age, char level
When the values are passed as reference, we need to have an amparsand(&) symbol at the beginning of the variable.
If the parameter does not have an "&" symbol in the beginning, it will be referred as call by value parameter.
Ans d) double MathOp(double a, double b, char opType);
Ans e) boolean IsEven(int x)
{
if(x%2==0)
return TRUE;
else
return FALSE;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.