The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
#include <stdio.h>
int main ()
{
/* variable definition: */
  int intValue, menuSelect,Results;
  intValue = 1;
  // While a positive number
while (intValue > 0)
{Â Â
    printf ("Enter a positive Integern: ");
    scanf("%d", &intValue);
  if (intValue > 0)
  {
    printf ("Enter 1 to calculate Square, 2 to Calculate Cube n: ");
    scanf("%d", &menuSelect);
    if (menuSelect == 1)
    {
      // Call the Square Function
      Results = Square(intValue);
      printf("Square of %d is %dn",intValue,Results);
    }
    else if (menuSelect == 2)
    {
      // Call the Cube function
      Results = Cube(intValue);
      printf("Cube of %d is %dn",intValue,Results);
    }
    else
      printf("Invalid menu item, only 1 or 2 is acceptedn");
    }   Â
  }   Â
return 0;
}
/* function returning the Square of a number */
int Square(int value)
{
  return value*value;
}
/* function returning the Cube of a number */
int Cube(int value)
{
  return value*value*value;
}
Â
1CMIS 102 Hands-On LabWeek 7OverviewThis hands-on lab allows you to follow and experiment with the critical steps of developing a programincluding the program description, analysis, test plan, design, and implementation with C code.Theexample provided uses sequential, repetition, selection statements and two user-defined function.Program DescriptionThis program will provide options for a user to calculate the square or cube of a positive Integer input bya user. The program will prompt the user to enter an Integer and then prompt the user if they want tocalculate the square of the cube of the number. Based on the inputs of the user, the program will outputthe square of the cube of the positive integer. The program will then print the Integer and square orcube of the integer based on the user’s original choice. The program will continue to prompt the user forIntegers and their calculation choice until the user enters a negative integer. The square and cubecalculations should be calculated using a function.AnalysisI will use sequential, selection, and repetition programming statements and functions for the cube andsquare calculations.I will define three Integer numbers: IntValue, MenuSelect, Results to store the Integer value input by theuser, the Menu selection (1 for Square, 2 for Cube) of the user, and the results of the Square or Cubefunctions.The Square function will take one Integer as input and return one Integer as the output. The calculationwithin the Square function is: Results = IntValue * IntValueFor example, if 10 was entered as the IntValue. Results = 10*10 = 100The Cube function will take one Integer as input and return one Integer as the output. The calculationwithin the Cube function is: Results = IntValue * IntValue*IntValueFor example, if 10 was entered as the IntValue. Results = 10*10*10 = 1000A repetition loop can be used to loop through iterations until a negative is entered:while(intValue > 0) (…End For
Attachments:
-----------