Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program to run any 4 of the following methods; problem #6 OR #7 is requi

ID: 3862708 • Letter: W

Question

Write a program to run any 4 of the following methods; problem #6 OR #7 is required (included as part of the four). Pay close attention to the requirements of the problem (i.e., return types and parameters). [25 Points each] Show all function calls using literals.

1)   A method that takes in user input via parameter [1, 4] and then returns the appropriate value for printing.  The following table displays the input/output combinations.  Use an if/else if or switch statement within the method for determining the return value.

Input

Return value

1

Roast beef

2

Bologna sandwich

3

Chocolate ice cream

4

Chocolate Chip cookie dough ice cream

Any other integer

Invalid choice but Bon appetit!

2) Write a method that takes in a teacher’s last name and exam number via parameters. Ask the teacher (using her name) to tell you the highest score on that exam. Your question should look something like “Ms. Jones, what was the highest grade on test two?” Return the value of the highest grade to the calling method.


3) Write a function called MinOfThree that takes in three numbers and returns the smallest.


4) Write a function named Summation that takes in two numbers: a start, and an end. The function should return the sum of the numbers between the start and the end. For example, passing this function a 3 and a 7, the function should return 25 (because 3+4+5+6+7=25).


5) Write a function that takes in a number, and prints out that many numbers of dashes. For example, if you pass this function a 17, it will print out 17 dashes.


6) A parking lot charges a minimum fee of $5 to park for 2 hours, and then $1 for each additional hour. The maximum charge is $10.00 per day. Write a function named Fee that takes in the number of hours parked, and returns the amount of money owed.

7) Write a function that takes in a user’s hourly rate and hours worked. Calculate and return the user’s gross pay. The user gets time and one half for any time worked over 40 hour.

Input

Return value

1

Roast beef

2

Bologna sandwich

3

Chocolate ice cream

4

Chocolate Chip cookie dough ice cream

Any other integer

Invalid choice but Bon appetit!

Explanation / Answer

The following code is for question1,

#include <stdio.h>

char* retPrint(int choice)
{
   char* retVal[5]={"Roast beef","Bologna sandwich","Chocolate ice cream","Chocolate Chip cookie dough ice cream","Invalid choice but Bon appetit!"};
       if(1==choice)
           return retVal[0];
       else if (2==choice)
           return retVal[1];
       else if (3==choice)
           return retVal[2];
       else if (4==choice)
           return retVal[3];
       else
           return retVal[4];
}

int main()
{

//finding return value for choice 1 as literal
   printf("%s ",retPrint(1));
}

The following code is for question3,

#include <stdio.h>

int minOfThree(int v1,int v2,int v3)
{

   if(v1<v2 && v1<v3)
       return v1;
   else if(v2<v3 && v2<v1)
       return v2;
   else if(v3<v2 && v3<v1)
       return v3;
}

void main()
{
   //finding min value of 7, 3 and 11 as literal
   printf("Min of three values is: %d ",minOfThree(7,3,11));
}
#endif

The following code is for question4,

#include <stdio.h>

float Summation(int start,int end)
{
   float sum=((end-start+1)/(float)2) * (start + end);   //sum of n consecutive integers is given by the formula n(a+l)/2
   return(sum);
}
void main()
{
   //finding sum value of 3 to 7 as literals
   printf("Sum: %d ",(int)Summation(3,7));
}

The following code is for question6,

int Fee(int hours)
{
   int fees;
   if(hours<2)   //if parked for less than 2 hours
       fees=5;
   else
   {
       fees=5+(hours-2);
       if(fees>10)
           fees=10;
   }
   return fees;
}

void main()
{
   //finding Fees value for 5 hours parking
   printf("Fees: %d ",(int)Fee(5));
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote