CMIS 102 Hands-On Lab Week 3 complete solutions correct answers key
- Vpqnrqhwk
- Rating : 40
- Grade : A+
- Questions : 2
- Solutions : 1079
- Blog : 0
- Earned : $19352.58
CMIS 102 Hands-On Lab Week 3 complete solutions correct answers key
CMIS 102 Hands-On Lab
// Week 3
Overview:
This hands-on lab allows you to follow and experiment with the critical steps of developing a program including the program description, analysis, test plan, design (using both flow chart and pseudocode visualization), and implementation with C code. The example provided uses sequential and selection statements.
Program Description:
This program will calculate the area of a right triangle. The program will ask the user to enter the base and height and then use these values to calculate and then print the area of the triangle. If the area of the triangle is greater than 100 square units, an additional message is printed stating the triangle is too large for the specification. However; if the triangle is less than or equal to 100 square units, the additional message will state the triangle is within specifications. The design step will include both pseudocode and flow chart visualization.
Analysis:
I will use sequential and selection programming statements.
I will define two float numbers for the base and height: base, height.
Float numbers were selected as opposed to integers to make sure triangles of all dimensions are possible and not just whole numbers.
Float number will store the area: area
The area will be calculated by this formula:
Area = ½ * (base * height)
For example if the base was 4.2 and the height was 5.3 the area would be calculated as:
Area = ½ * (4.2 * 5.3) = ½ * (22.26) = 11.13
The additional selection statement will be of this form:
If area > 100 then
print "Triangle is not within specifications"
Else
print "Triangle is within specifications"
End If
Test Plan:
To verify this program is working properly the following base and height values could be used for testing:
Test Case
Input
Expected Output
1
Base=10.1 Height = 12.2
Area = 61.61
Triangle is within specifications.
2
Base=2.67 Height = 3.23
Area = 4.31
Triangle is within specifications.
3
Base=100.0 Height = 400.0
Area =20000.0
Triangle is not within specifications.
Pseudocode:
// This program will calculate the area of a right triangle.
// Declare variables
Declare base, height, area as Float
// Ask User for Inputs
Write “Enter triangle base:”
Input base
Write “Enter triangle height:”
Input height
// Set value of area
Set area=1/2*(base * height)
// Print area
Print “Area of triangle is “ + area
// Selection statement
if area > 100
Print “Triangle is not within specifications.”
else
Print “Triangle is within specifications.”
Flow Chart:
C Code
The following is the C Code that will compile in execute in the online compilers.
// C code
// This program will calculate the area of a right triangle.
// Developer: Faculty CMIS102
// Date: Jan 31, 2014
#include <stdio.h>
int main ()
{
/* variable definition: */
float base, height, area;
/* Prompt user for base */
printf("Enter the base of the triangle: \n");
// Input the base
scanf("%f", &base);
/* Prompt user for height */
printf("Enter the height of the triangle: \n");
// Input the base
scanf("%f", &height);
// Calculate the Area
area= 0.5 * (base * height);
// Print the result
printf("Area is : %f\n", area);
// Selection logic
if (area > 100)
printf("Triangle is not within specifications.\n");
else
printf ("Triangle is within specifications.\n");
return 0;
}
Setting up the code and the input parameters in ideone.com:
Note the base and height (4.0 and 8.0) are entered in the enter input (stdin) field. You can change these values to any valid float values to match your test cases.
Results from running the programming at ideone.com:
Learning Exercises for you to try:
1. How would you change all the steps if you wanted to output the area of a rectangle as opposed to the area of a triangle? (Hint: What is the formula for the area of a rectangle?)
2. What is the line of code doing?
scanf("%f", &height);
How would you change this line if you wanted to input an Integer as opposed to a float?
3. Try at least 3 different test cases and check the output. How did you change the input values?
4. Can you see any advantages to asking the user for input as opposed to having it “hard-coded” in the C code?
5. Experiment with the C code to try variations and changes that interest you. Playing with the code is one of the best ways to learn.
[Solved] CMIS 102 Hands-On Lab Week 3 complete solutions correct answers key
- This solution is not purchased yet.
- Submitted On 18 Jan, 2017 10:08:41
- Vpqnrqhwk
- Rating : 40
- Grade : A+
- Questions : 2
- Solutions : 1079
- Blog : 0
- Earned : $19352.58