This is a four part question please answer all four parts be
This is a four part question please answer all four parts becaue it is impossible to break it up into four questions.
The following is the C Code that will compile in execute in the online compilers.
// C code
// This program will provide options for a user to calculate the square
// or cube of a positive Integer input by a user.
// Developer: Faculty CMIS102
// Date: Jan 31, XXXX
#include <stdio.h>
// Function prototypes
int Square(int value);
int Cube(int value);
int main ()
{
/* variable definition: */
int intValue, menuSelect,Results;
intValue = 1;
// While a positive number
while (intValue > 0)
{
printf (\"Enter a positive Integer\ : \");
scanf(\"%d\", &intValue);
if (intValue > 0)
{
printf (\"Enter 1 to calculate Square, 2 to Calculate Cube \ : \");
scanf(\"%d\", &menuSelect);
4
if (menuSelect == 1)
{
// Call the Square Function
Results = Square(intValue);
printf(\"Square of %d is %d\ \",intValue,Results);
}
else if (menuSelect == 2)
{
// Call the Cube function
Results = Cube(intValue);
printf(\"Cube of %d is %d\ \",intValue,Results);
}
else
printf(\"Invalid menu item, only 1 or 2 is accepted\ \");
}
}
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;
}
Using the Code Above
1. Using the Square and Cube functions as models, Create an application that includes a function
named “Shrink” that would take an Integer and return the Integer divided by 2? (Hint: your
returned value should probably be a double type.) Support your experimentation with screen
captures of executing the new code.
2. Prepare a new test table with at least 3 distinct test cases listing input and expected output for
the code you created after step 1.
3. What would happen if you removed the following code from our design?
If intValue > 0
Support your argument with screen captures of executing the new code.
4. Modify the original code and add an additional function of your choice. The function should be
unique and something you created for this assignment. Support your experimentation with 7
screen captures of executing the new code. Prepare a test table with at least 3 distinct test cases
listing input and expected output for your unique function.
Do not cover the code with the screenshots!
Solution
1.
// C code
// This program will provide options for a user to calculate the square
// or cube or shrink of a positive Integer input by a user.
// Developer: Faculty CMIS102
// Date: Jan 31, XXXX
#include <stdio.h>
// Function prototypes
int Square(int value);
int Cube(int value);
int Shrink(int value);
int main ()
{
/* variable definition: */
int intValue, menuSelect,Results;
intValue = 1;
// While a positive number
while (intValue > 0)
{
printf (\"Enter a positive Integer\ : \");
scanf(\"%d\", &intValue);
if (intValue > 0)
{
printf (\"Enter 1 to calculate Square, 2 to Calculate Cube ,3 to Shrink\ : \");
scanf(\"%d\", &menuSelect);
if (menuSelect == 1)
{
// Call the Square Function
Results = Square(intValue);
printf(\"Square of %d is %d\ \",intValue,Results);
}
else if (menuSelect == 2)
{
// Call the Cube function
Results = Cube(intValue);
printf(\"Cube of %d is %d\ \",intValue,Results);
}
else if (menuSelect == 3)
{
// Call the Shrink function
Results = Shrink(intValue);
printf(\"Shrink of %d is %d\ \",intValue,Results);
}
else
printf(\"Invalid menu item, only 1 or 2 is accepted\ \");
}
}
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;
}
int Shrink(int value)
{
return value/2;
}
output:
Success time: 0 memory: 2172 signal:0
2
intValue Shrink(intValue)
66 33
75 37
49 24
3. If the statement if(intvalue > 0) is removed
the program will compute functions for negative values also
4 Add function
int Quarter(int value)
{
return value/4;
}
.Test cases
intValue Quarter(intValue)
7 1
87 21
56 14



