cmis102 full course (discussions+assignments+homework) latest 2016 October

Discussion 1
Your favorite Programming Language
You may have had a chance to try other programming languages. Or maybe, you are interested in learning a language you have read about.
What programming language would you like to use on a regular basis in your job?
What features are interesting and attracting to you about this programming language?
Discussion 2
Software Development Jobs
Pick your favorite job search site (monster, dice ...) and conduct some research on software development jobs you might be interested in applying.
Share one or two qualifications listed in the job description that you want to work on for this course or your major you are currently pursuing.
Discussion 3
BLS - Software Development Salary Ranges
Review the BLS (bls.gov) descriptions for Software development salary ranges, demographics and information.
Share an interesting fact that you found about software development while reviewing the bls site.
Discussion 4
Provide a new example in C programming
We have studied several basic concepts in C. However; the C language is huge and we have only touched the surface.
Conduct some research on other libraries, features and functions and provide a short description and a fully functional piece of code using this feature.
You should pick a topic that we have not covered in the class as part of the readings or examples this semester.
Start a New Thread
Assignment 1
Lab on hand
Overview
This hands-on lab demonstrate a simple sequential print statements using an online C compiler such as
ideone.com. You should follow the instructions to complete the lab as well as perform the learning
exercises at the end of this lab.
Instructions
a. Open up any online C compiler (e.g ideone.com).
b. Be sure the C Language is selected.
c. Enter the code below into the editor. (Note: LEO doesn’t let you just copy and paste from this
document so you can either download the document and then copy and paste or just go to the
Code for HelloWorld link for this week and copy and paste from there.)
d. Click the submit, or run button.
e. Try the additional learning exercises on the next page.
Here is what Hello, World! Looks like using ideone.com after it has successfully run
Hello, World C code
#include <stdio.h>
int main(void) {
printf("Hello, World!");
return 0;
}
2
Learning Exercises for you to complete
1. Remove the semi-colon (;) at the end of this statement:
printf("Hello, World!");
Describe what happens. Why is the semi-colon needed?
2. What happens if you add another printf statement such as:
printf("Goodbye");
after the printf("Hello, World!"); line?
Describe the new output. Be sure to support your description with screen captures of executing
the new code.
3. Experiment by adding additional printf statements to your code such as:
printf("Goodbye \n");
printf("Hello, again! \n");
What does the "\n" do to the output?
Be sure to experiment by adding several printf statements and describe the resulting output. Be
sure to support your description and experimentation with screen captures of executing the
new code.
Submission
Submit a neatly organized word (or PDF) document that demonstrates you successfully
executed the Hello,World on your machine using an online compiler. You should provide a
screen capture of the resulting output.
Also, provide the answers, associated screen captures, C Code and descriptions of your
successful completion of learning exercises 1, 2 and 3.
The answers to the learning exercises, screen captures, C code and descriptions can be included
in the same neatly organized document you prepared as you ran the Hello, World application.
Note the code can be embedded in the word document. However; be sure all code compiles and
runs perfectly before submitting the document.
Submit your document no later than the due date listed in the syllabus or calendar.
Homework 1
Homework 1 – Software Engineering Code of Ethics
The following is the short version of the Software Engineering Code of Ethics and Professional Practice available from the URL:
http://www.acm.org/about/se-code
************************************* Software engineers shall commit themselves to making the analysis, specification, design, development, testing and maintenance of software a beneficial and respected profession. In accordance with their commitment to the health, safety and welfare of the public, software engineers shall adhere to the following Eight Principles:
1. PUBLIC - Software engineers shall act consistently with the public interest.
2. CLIENT AND EMPLOYER - Software engineers shall act in a manner that is in the best interests of their client and employer consistent with the public interest.
3. PRODUCT - Software engineers shall ensure that their products and related modifications meet the highest professional standards possible.
4. JUDGMENT - Software engineers shall maintain integrity and independence in their professional judgment.
5. MANAGEMENT - Software engineering managers and leaders shall subscribe to and promote an ethical approach to the management of software development and maintenance.
6. PROFESSION - Software engineers shall advance the integrity and reputation of the profession consistent with the public interest.
7. COLLEAGUES - Software engineers shall be fair to and supportive of their colleagues.
8. SELF - Software engineers shall participate in lifelong learning regarding the practice of their profession and shall promote an ethical approach to the practice of the profession.
**********************************************************************
Using the above Code of Ethics, Pick at least 2 of the 8 principles and describe what these principles mean to you. In your write-up, summarize the principles you selected in your own words and provide at least one example of an activity or action you could take that would support each principle and one example of an activity or action that you believe would violate each principle. Be sure your document is well-written with minimal grammatical and spelling issues.
Submit your word or PDF file to your assignments folder no later than the due date.
Grading guidelines
Submission Points Accurately summarized two of the eight principles in your own words. 2 Provided and explained examples that support each of the two principles you selected. 1 Provided and explained examples that violate each of the two principles you selected. 1 Document is well-organized, and contains minimal spelling and grammatical errors. 1 Total 5
Assignment 2
CMIS 102 Hands-On Lab
Week 2 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, and implementation with C code.
Program Description
This program will sum two integer numbers to yield a third integer number. Once the calculations are made the results of all the numbers will be printed to the output screen.
Analysis
We will use sequential programming statements. We will define 3 integer numbers: a, b, c. c will store the sum of a and b.
Test Plan
To understand this program the following input numbers could be used for testing:
a = 10 b = 20 c = a + b = 10 + 20 = 30
In table format the following results are expected:
Run # Input a Input b Expected Output 1 10 20 30 2 0 0 0 3 124 356 480 4 -30 -90 -120
Design using Pseudocode
// This program will sum two integer numbers to yield a third integer number. // It will also divide two float numbers to yield a third float number.
// Declare variables Declare a,b,c as Integer
// Set values of Integers Set a=10 Set b=20 Set c= a + b
// Print a, b, c Print a,b,c
2
C Code
The following is the C Code that will compile in execute in the online compilers.
// C code // This program will sum two integer numbers to yield a third integer number. // Developer: Faculty CMIS102 // Date: Jan 31, XXXX
#include <stdio.h> int main () { /* variable definition: */ int a, b, c;
/* variable initialization */ a = 10; b = 20; c = a + b; printf("Integers (a,b) and sum (c) are : %d,%d,%d \n", a,b,c); return 0; }
Results from running the programming at ideone.com:
3
Learning Exercises for you to complete
1. Change the C code to calculate the product of two integers as opposed to the sum of two integers. Then run the new code. Support your experimentation with a screen capture of the code and a screen capture of the successful execution of the new code.
2. Prepare a new test table with at least 3 distinct test cases listing input and expected output for the product of two integers. Include screen shots of the executions of all text table values working properly.
3. Change the C code to calculate the quotient (e.g. a/b) of two floats (e.g. 2.3/1.5).Hint: Use float variable types as opposed to integers. What happens if the denominator is 0.0? Support your experimentation with screen captures of executing the new code
4. Prepare a new test table with at least 3 distinct test cases listing input and expected output for the quotient of two floats.
Submission
Submit a neatly organized word (or PDF) document that demonstrates you successfully executed this lab on your machine using an online compiler. You should provide a screen capture of the resulting output.
Also, provide the answers, associated screen captures, C Code and descriptions of your successful completion of learning exercises 1, 2, 3 and 4.
The answers to the learning exercises, screen captures, C code and descriptions can be included in the same neatly organized document you prepared as you ran this lab. Note the code can be embedded in the word document. However; be sure all code compiles and runs perfectly before submitting the document.
Submit your document no later than the due date listed in the syllabus or calendar.
4
Grading guidelines
Submission Points Successfully demonstrates execution of this lab with online compiler. Includes a screen capture of the code and the output from successful runs. 3 Successfully modifies the code to calculate the product of two integers. 2 Provides a new test table with at least 3 distinct test cases listing input and expected output for the product of two integers. 1 Modifies the code to calculate the quotient of two floats. Describes what happens if the denominator is 0.0? Support your experimentation with screen captures of executing the new code. 2
Provides a new test table with at least 3 distinct test cases listing input and expected output for the quotient of two floats.
1
Document is well-organized, and contains minimal spelling and grammatical errors.
1
Total 10
Assignment 3
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, pseudocode visualization, and implementation with C code. The example provided uses mathematical operators and variable types.
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. The design step will include pseudocode.
Analysis
I will use sequential 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
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 2 Base=2.67 Height = 3.23 Area = 4.31 3 Base=100.0 Height = 400.0 Area =20000.0
2
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
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, XXXX #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); return 0; }
3
Setting up the code and the input parameters in ideone.com:
Note the base and height (10.1 and 12.2) are entered in the enter input (stdin) field. You can change these values to any valid float values to match your test cases.
4
Learning Exercises for you to complete
1. Change the C code to calculate the perimeter of a triangle. Support your experimentation with a screen capture 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 perimeter of a triangle.
3. What is this 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?
4. What are the values of f and g after executing the following C?
#include <stdio.h>
int main(void) { int i,j; float f,g; i = 5; j = 2; f = 3.0; f = f + j / i; g = (f + j )/i;
printf("value of f,g is %f,%f\n", f,g); return 0; }
Describe specifically, and in your own words, why are the values of f and g different? Support your experimentation with a screen capture of executing the code.
Submission
Submit a neatly organized word (or PDF) document that demonstrates you successfully executed this lab on your machine using an online compiler. You should provide a screen capture of the resulting output.
Also, provide the answers, associated screen captures, C Code and descriptions of your successful completion of learning exercises 1, 2, 3 and 4.
The answers to the learning exercises, screen captures, C code and descriptions can be included in the same neatly organized document you prepared as you ran this lab. Note the code can be embedded in the word document. However; be sure all code compiles and runs perfectly before submitting the document.
Submit your document no later than the due date listed in the syllabus or calendar.
5
Grading guidelines
Submission Points Successfully demonstrates execution of this lab with online compiler. Includes a screen capture. 3 Provides a new test table with at least 3 distinct test cases listing input and expected output for the perimeter of a triangle. 2 Accurately describes the purpose of the scanf code. Accurately describes how to modify the code to input an integer as opposed to a float. 2 Accurately describe why are the values of f and g different for the provided code? Supports your experimentation with screen captures of executing the code. 2 Document is well-organized, and contains minimal spelling and grammatical errors. 1 Total 10
Assignment 4
CMIS 102 Hands-On Lab
Week 4
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 pseudocode), and implementation with C code. The example provided uses sequential and selection statements.
Program Description
This program will calculate the sum of 5 integers. The program will ask the user to 5 integers. If the sum of the numbers is greater than 100, a message is printed stating the sum is over 100. The design step will include both pseudocode.
Analysis
I will use sequential, and selection programming statements. I will define six integer numbers: value1, value2, value3, value4, value5 and sum. The value1, value2, value3, value4 and value5 variables will store the integers input by the user. The sum will store the sum of the 5 values. The sum will be calculated by this formula: sum = value1 + value2 + value3 + value4 + value5 For example, if the first values entered were value 1=1, value 2=1, value 3=2,value 4=2 and value 5=3 respectively: sum = 1 + 1 + 2 + 2 + 3 = 9
The additional selection statement will be of this form:
If sum > 100 then print "Sum is over 100" End If
Test Plan
To verify this program is working properly the input values could be used for testing:
Test Case Input Expected Output 1 value1=1 value2=1 value3=1 value4=0 Value5=2 Sum = 5 2 value=100 value=100 value=100 value=100 value=200 Sum = 600 Sum is over 100.
2
3 value= -100 value= -100 value= -200 value = 0 value= 200
Sum = -200
Pseudocode
// This program will calculate the sum of 5 integers.
// Declare variables Declare value1, value2, value3, value4, value5, sum as Integer
//Initialize Sum to 0 Set sum = 0
// Enter values Print “Enter an nteger for value1” Input value1 Print “Enter an nteger for ale” Input value2 Print “Enter an nteger for ale” Input value3 Print “Enter an nteger for ale” Input value4 Print “Enter an nteger for ale” Input value5
// Calculate sum sum = value1 + value2 + value3 + value4 + value5
// Print results and messages Print “ is “ + s If (sum > 100) Printf “ is oer ” End if
C Code
The following is the C Code that will compile in execute in the online compilers.
// C code
// This program will calculate the sum of 5 integers.
// Developer: Faculty CMIS102
// Date: Jan 31, XXXX
#include <stdio.h>
int main ()
3
{
/* variable definition: */
int value1,value2,value3,value4,value5,sum;
/* Initialize sum */
sum = 0;
printf("Enter an Integer for value1\n"); scanf("%d", &value1); printf("Enter an Integer for value2\n"); scanf("%d", &value2); printf("Enter an Integer for value3\n"); scanf("%d", &value3); printf("Enter an Integer for value4\n"); scanf("%d", &value4); printf("Enter an Integer for value5\n"); scanf("%d", &value5);
sum = value1 + value2 + value3 + value4 + value5;
printf("Sum is %d\n " , sum );
if (sum >100)
printf("Sum is over 100\n");
return 0;
}
Setting up the code and the input parameters in ideone.com:
Note the input integer values are 100, 100, 100, 200 and 100, for this test case. You can change these values to any valid integer values to match your test cases.
4
Results from running within ideone
5
Learning Exercises for you to complete
1. Change the C code to sum 10 integers as opposed to 5? (Hint: Please don’t use arrays or Loops for this. We will be using those features in another week.) Support your experimentation with a screen capture of executing the new code
2. Using the code you create in step 1, modify the code to print an additional statement if the sum of the value is negative (Hint: Consider modifying the existing selection statement) Support your experimentation with a screen capture of executing the new code.
3. Prepare a new test table with at least 3 distinct test cases listing input and expected output for the code you created after step 2.
4. Create your own C code implementation of one of the following mathematical formulas:
a. y = mx + b; (slope of a line) Assume the user will be prompted to input m, x and b and the program will calculate y. If the value of y is greater than 10, inform the user the value is greater than 10. b. a = PI * r*r; (area of circle). Assume the user will be prompted to input the radius r. You can define PI as 3.1416. . If the value of a is greater than 10, inform the user the value is greater than 10. c. v = 4/3 PI r*r*r; (volume of sphere) Assume the user will be prompted to input the radius r. You can define PI at 3.1416. If the value of v is greater than 10, inform the user the value is greater than 10.
Be sure you provide not only the C code but a test table with at least 3 distinct test cases listing input and expected output your mathematical formula.
Submission
Submit a neatly organized word (or PDF) document that demonstrates you successfully executed this lab on your machine using an online compiler. You should provide a screen capture of the resulting output. Submit all C code you created in files.
Also, provide the answers and any associated screen captures of your successful completion of exercises 1, 2, 3 and 4.
Submit your document no later than the due date listed in the syllabus or calendar.
6
Grading guidelines
Submission Points Successfully demonstrates execution of this lab with online compiler. Includes a screen capture. 2 Modifies the C code to sum 10 integers as opposed to 5. Supports your experimentation with screen captures of executing the code. 2 Using the code created in step 1, modifies the code to print an additional statement if the sum of the value is negative Supports your experimentation with a screen capture of executing the new code. 2 Provides a new test table with at least 3 distinct test cases listing input and expected output for the code you created after step 2. 1 Creates your own unique C code implementation of one of the provided mathematical formulas. Provides a new test table with at least 3 distinct test cases listing input and expected output your mathematical formula. Supports your experimentation with a screen capture of executing the new code. 2 Document is well-organized, and contains minimal spelling and grammatical errors. 1 Total 10
Assignment 5
CMIS 102 Hands-On Lab
Week 5
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 pseudocode), and implementation with C code. The example provided uses sequential, selection and repetition statements.
Program Description
This program will calculate the average of 10 positive integers. The program will ask the user to 10 integers. If any of the values entered is negative, a message will be displayed asking the user to enter a value greater than 0. The program will use a loop to input the data.
Analysis
I will use sequential, selection and repetition programming statements. I will define two integer numbers: count, value and sum. count will store how many times values are entered. value will store the input. Sum will store the sum of all 10 integers. I will define one double number: avg. avg will store the average of the ten positive integers input.
The sum will be calculated by this formula: sum = sum + value For example, if the first value entered was 4 and second was 10: sum = sum + value = 0 + 4 sum = 4 + 10 = 14 Values and sum can be input and calculated within a repetition loop: while count <10 Input value sum = sum + value End while
Avg can be calculated by: avg = value/count
A selection statement can be used inside the loop to make sure the input value is positive.
If value >= 0 then count = count + 1
Else input value End If
2
Test Plan
To verify this program is working properly the input values could be used for testing:
Test Case Input Expected Output 1 value=1 value=1 value=1 value=0 value=1 value=2 value=0 value=1 value=3 value=2 Average = 1.2 2 value=100 value=100 value=100 value=100 value=100 value=200 value=200 value=200 value=200 value=200 Average = 150.0 3 value=100 value=100 value=100 value=100 value=-100 value = 100 value=200 value=200 value=200 value=200 Input a positive value average is 140.0
Pseudocode
// This program will calculate the average of 10 positive integers.
// Declare variables Declare count, value, sum as Integer Declare avg as double
//Initialize value Set count=0
3
Set sum = 0 set avg = 0.0;
// Loop through 10 integers While count < 10 Print “Enter a Positive Integer” Input value if (value >=0) sum = sum + value count=count+1 else Print (“Value must be positive”); End if End While
// Calculate average avg = sum/count // Print results Print “Average is “ + avg
C Code
The following is the C Code that will compile in execute in the online compilers.
// C code
// This program will calculate the sum of 10 positive integers.
// Developer: Faculty CMIS102
// Date: Jan 31, XXXX
#include <stdio.h>
int main ()
{
/* variable definition: */
int count, value, sum; double avg;
/* Initialize */
count = 0;
sum = 0; avg = 0.0;
// Loop through to input values
while (count < 10)
{
printf("Enter a positive Integer\n");
4
scanf("%d", &value); if (value >= 0) { sum = sum + value; count = count + 1; } else { printf("Value must be positive\n"); }
}
// Calculate avg. Need to type cast since two integers will yield an integer
avg = (double) sum/count;
printf("average is %lf\n " , avg );
return 0;
}
Setting up the code and the input parameters in ideone.com:
Note the input integer values are 1, 1, 1, 0, 1, 2, 0, 1, 3, 2 for this test case. You can change these values to any valid integer values to match your test cases. You should also test with a negative number to make sure the positive integer logic works properly.
5
Results from running the programming at ideone.com
Learning Exercises for you to complete
1. Change the code to average 20 integers as opposed to 10. 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 happens if you entered a value other than an integer? (For example a float or even a string). Support your experimentation with screen captures of executing the code.
4. Modify the code to allow the user to enter an unspecified number of positive integers and calculate the average. In other words, the user could enter number of positive integers. (Hint: You can prompt the user for how many they want to enter. Or; you could use a sentinel value to trigger when the user has completed entering values). You may need to conduct some research on your own to solve this problem. Prepare a new test table with at least 3 distinct test cases listing input and expected output for the code you created. Support your experimentation with screen captures of executing the new code.
6
Grading guidelines
Submission Points Successfully demonstrates execution of this lab with online compiler. Includes a screen capture. 2 Modifies the C code average 20 integers as opposed to 10. Support your experimentation with screen captures of executing the new code. 2 Provides a new test table with at least 3 distinct test cases listing input and expected output for the code you created after step 1. 1 Describes what happens if you entered a value other than an integer? Support your experimentation with screen captures of executing the code. 1 Modifies the C code to allow the user to enter an unspecified number of positive integers and calculate the average. Provides a new test table with at least 3 distinct test cases listing input and expected output for the code you created. Support your experimentation with screen captures of executing the new code. 3 Document is well-organized, and contains minimal spelling and grammatical errors. 1 Total 10
Assignment 6
1
CMIS 102 Hands-On Lab
Week 6
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 and implementation with C code. The example provided uses sequential, repetition statements and nested repetition statements.
Program Description
This program will calculate the average of 3 exams for 5 students. The program will ask the user to enter 5 student names. For each of the students, the program will ask for 3 exam scores. The average exam score for each student will be calculated and printed.
Analysis
I will use sequential and repetition programming statements. I will define one String to store the student name: StudentName. I will define three Float numbers: Examvalue, Sum, Avg to store exam values the sum of the exams and the average of the exams. The sum will be calculated by this formula: Sum = Sum + Examvalue For example, if the first value entered was 80.0 and second was 90.0 and the third exam was 100.0: sum = sum + Examvalue = 0.0 + 80.0 sum = 80.0 + 90.0 = 170.0 sum = 170.0 + 100.0 = 270.0 Avg is then calculated as: Avg = sum/3.0 For example 270.0/3.0 = 90.0 A nested repetition loop can be used to loop through each of the 5 students and each of the 3 exams: For (students=0; students <5; students++) For (exams=0;exams<3;exams++) End For End For Sum values will need to be reset for each student to ensure only one student data is used for calculations each time.
Test Plan
To verify this program is working properly the input values could be used for testing:
Test Case Input Expected Output 1 Studentname=Chris Examvalue1=80.0 Examvalue2=90.0 Examvalue3=100.0 Average for Chris is 90.0 Average for John is 80.0 Average for Sally is 100.0
2
Studentname=John Examvalue1=70.0 Examvalue2=90.0 Examvalue3=80.0 Studentname=Sally Examvalue1=100.0 Examvalue2=100.0 Examvalue3=100.0 Studentname=Pat Examvalue1=50.0 Eexamvalue2=70.0 Examvalue3=60.0 Studentname=Sam Examvalue1=90.0 Examvalue2=95.0 Examvalue3=100.0
Average for Pat is 60.0 Average for Sam is 95.0
Pseudocode
// This program will calculate the average of 3 exams for 5 students
// Declare variables Declare StudentName as String Declare ExamValue, Sum, Avg as Float
// Loop through 5 Students For (students=0; students <5 ; students++) // reset Sum to 0 Set Sum =0.0 Print “Enter Student Name” Input StudentName // Nested Loop for Exams For (exams=0; exams < 3; exams++) Print “Enter ea grae: \n” Input ExamValue Set Sum = Sum + ExamValue End For Set Avg = Sum/3.0 Print “Aerage for “ + tentae + “ is “ + Ag End For
3
C Code
The following is the C Code that will compile in execute in the online compilers.
// C code
// This program will calculate the average of 3 exams for 5 students.
// Developer: Faculty CMIS102
// Date: Jan 31, XXXX
#include <stdio.h>
int main ()
{
/* variable definition: */
char StudentName[100];
float ExamValue, Sum, Avg;
int students,exams;
// Loop through 5 Students
for (students=0; students <5 ; students++)
{
// reset Sum to 0
Sum =0.0;
printf("Enter Student Name \n");
scanf("%s", StudentName);
// Nested Loop for Exams
for (exams=0; exams < 3; exams++)
{
printf ("Enter exam grade: \n");
scanf("%f", &ExamValue);
Sum += ExamValue;
}
Avg = Sum/3.0;
printf( "Average for %s is %f\n",StudentName,Avg);
}
return 0;
}
4
Setting up the code and the input parameters in ideone.com:
Note the Student and ExamValues for this run were: John: 90.0 80.0 100.0 Jim: 80.0 70.0 90.0 Joe: 70.0 100.0 100.0 Sally: 100.0 95.0 91.0 Sam: 30.0 54.0 68.0 You can change these values to any valid integer values to match your test cases.
5
Results from running the programming at ideone.com
Learning Exercises for you to complete
1. Modify the code to be able to input an undetermined number of students. You will still only have 3 exams for each student. 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 is the line of code doing?
char StudentName[100];
(Hint: We haven’t covered arrays, but a String can be thought of as an array of characters) ?
6
4. What would happen if you moved the Set Sum = 0.0 from inside the for loop to right after the declaration. For example:
// Declare variables Declare StudentName as String Declare ExamValue, Sum, Avg as Float
// Initialize Sum Set Sum = 0.0;
Support your experimentation with screen captures of executing the new code.
Grading guidelines
Submission Points Successfully demonstrates execution of this lab with online compiler. Includes a screen capture. 3 Modifies the code to be able to input an undetermined number of students. Support your experimentation with screen captures of executing the new code. 2 Provides a new test table with at least 3 distinct test cases listing input and expected output for the code you created after step 1. 1 Describes what the char array line is doing. 1 Describes what would happen if you moved the Set Sum = 0.0 from inside the for loop to right after the declaration. Be sure to provide screen captures to document your analysis and results. 2 Document is well-organized, and contains minimal spelling and grammatical errors. 1 Total 10
Assignment 7
CMIS 102 Hands-On Lab
Week 7
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, and implementation with C code. The example provided uses sequential, repetition, selection statements and two user-defined function.
Program Description
This program will provide options for a user to calculate the square or cube of a positive Integer input by a user. The program will prompt the user to enter an Integer and then prompt the user if they want to calculate the square of the cube of the number. Based on the inputs of the user, the program will output the square of the cube of the positive integer. The program will then print the Integer and square or cube of the integer based on the user’s original choice. The program will continue to prompt the user for Integers and their calculation choice until the user enters a negative integer. The square and cube calculations should be calculated using a function.
Analysis
I will use sequential, selection, and repetition programming statements and functions for the cube and square calculations. I will define three Integer numbers: IntValue, MenuSelect, Results to store the Integer value input by the user, the Menu selection (1 for Square, 2 for Cube) of the user, and the results of the Square or Cube functions. The Square function will take one Integer as input and return one Integer as the output. The calculation within the Square function is: Results = IntValue * IntValue For example, if 10 was entered as the IntValue. Results = 10*10 = 100 The Cube function will take one Integer as input and return one Integer as the output. The calculation within the Cube function is: Results = IntValue * IntValue*IntValue For example, if 10 was entered as the IntValue. Results = 10*10*10 = 1000
A repetition loop can be used to loop through iterations until a negative is entered: while(intValue > 0) ( … End For
2
Test Plan
To verify this program is working properly the input values could be used for testing:
Test Case Input Expected Output 1 IntValue=10 MenuSelect=1 Square of 10 is 100 2 IntValue=10 MenuSelect=2 Cube of 10 is 1000 3 intValue=-1 MenuSelect=N/A Program exits
Pseudocode
// This program will provide options for a user to calculate the square
// or cube of a positive Integer input by a user. // Start Main program Main
// Declare variables Declare intValue, menuSelect,Results as Integer
// Set intValue to positive value to start loop Set intVal = 1;
// Loop While input is a positive number
While intValue > 0
Print "Enter a positive Integer:” Input intValue
// Only perform menu and function calls is integer is positive If intValue > 0 Then Print "Enter 1 to calculate Square, 2 to Calculate Cube " Input menuSelect
If menuSelect == 1 Then // Call the Square Function Set Results = Square(intValue) Print intValue,Results Else If menuSelect == 2 Then // Call the Cube function set Results = Cube(intValue) Print intValue,Results Else Print “Invalid menu item, only 1 or 2 is accepted” End If End If
END While
// End of Main program End Program
3
// Square Function Function Square(value) as Integer Set Square = value*value End Function
// Cube Function Function Cube(value) as Integer Set Cube = value*value*value End Function
C Code
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\n: ");
scanf("%d", &intValue);
if (intValue > 0)
{
printf ("Enter 1 to calculate Square, 2 to Calculate Cube \n: ");
scanf("%d", &menuSelect);
4
if (menuSelect == 1)
{
// Call the Square Function
Results = Square(intValue);
printf("Square of %d is %d\n",intValue,Results);
}
else if (menuSelect == 2)
{
// Call the Cube function
Results = Cube(intValue);
printf("Cube of %d is %d\n",intValue,Results);
}
else
printf("Invalid menu item, only 1 or 2 is accepted\n");
}
}
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;
}
Setting up the code and the input parameters in ideone.com:
Note the Input values for this run were: 10
5
1 10 2 -99 You can change these values to any valid integer values to match your test cases.
6
Results from running the programming at ideone.com:
Learning Exercises for you to complete
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.
Grading guidelines
Submission Points Successfully demonstrates execution of this lab with online compiler. Includes a screen capture. 2 Modifies the code to create an application that includes a function named “Shrink” that would take an Integer and return the Integer divided by 2 Support your experimentation with screen captures of executing the new code. 2 Provides a new test table with at least 3 distinct test cases listing input and expected output for the code you created after step 1. 1 Describes what would happen if you removed the “if intValue = 0“ line was removed. Support your argument with screen captures of executing the new code. 1 Modifies the original code and adds an additional unique function of your choice. Supports your experimentation with screen captures of executing the new code. Prepares a test table with at least 3 distinct test cases listing input and expected output for your unique function. 3 Document is well-organized, and contains minimal spelling and grammatical errors. 1 Total 10
Assignment 8
CMIS 102 Hands-On Lab
Week 8
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, and implementation with C code. The example provided uses sequential, repetition, selection statements, functions, strings and arrays.
Program Description
This program will input and store meteorological data into an array. The program will prompt the user to enter the average monthly rainfall for a specific region and then use a loop to cycle through the array and print out each value. The program should store up 5 years of meteorological data. Data is collected once per month. The program should provide the option to the user of not entering any data.
Analysis
I will use sequential, selection, and repetition programming statements and an array to store data. I will define a 2-D array of Float number: Raindata[][] to store the Float values input by the user. To store up to 5 years of monthly data, the array size should be at least 5*12 = 60 elements. In a 2D array this will be RainData[5][12]. We can use #defines to set the number of years and months to eliminate hard- coding values. A float number (rain) will also be needed to input the individual rain data. A nested for loop can be used to iterate through the array to enter Raindata. A nested for loop can also be used to print the data in the array.
A array of strings can be used to store year and month names. This will allow a tabular display with labels for the printout.
Functions will be used to separate functionality into smaller work units. Functions for displaying the data and inputting the data will be used.
A selection statement will be used to determine if data should be entered.
Test Plan
To verify this program is working properly the input values could be used for testing:
Test Case Input Expected Output 1 Enter data? = y 1.2 2.2 3.3 2.2 10.2 12.2 2.3 0.4 0.2 1.1 2.1 year month rain 2011 Jan 1.20 2011 Feb 2.20 2011 Mar 3.30 2011 Apr 2.20 2011 May 10.20 2011 Jun 12.20 2011 Jul 2.30 2011 Aug 0.40 2011 Sep 0.20 2011 Oct 1.10 2011 Nov 2.10 2011 Dec 0.40
2
0.4 1.1 2.2 3.3 2.2 10.2 12.2 2.3 0.4 0.2 1.1 2.1 0.4 1.1 2.2 3.3 2.2 10.2 12.2 2.3 0.4 0.2 1.1 2.1 0.4 1.1 2.2 3.3 2.2 10.2 12.2 2.3 0.4 0.2 1.1 2.1 0.4 1.1 2.2 3.3 2.2 10.2 12.2 2.3 0.4 0.2 1.1 2.1 0.4
2012 Jan 1.10 2012 Feb 2.20 2012 Mar 3.30 2012 Apr 2.20 2012 May 10.20 2012 Jun 12.20 2012 Jul 2.30 2012 Aug 0.40 2012 Sep 0.20 2012 Oct 1.10 2012 Nov 2.10 2012 Dec 0.40 2013 Jan 1.10 2013 Feb 2.20 2013 Mar 3.30 2013 Apr 2.20 2013 May 10.20 2013 Jun 12.20 2013 Jul 2.30 2013 Aug 0.40 2013 Sep 0.20 2013 Oct 1.10 2013 Nov 2.10 2013 Dec 0.40 2014 Jan 1.10 2014 Feb 2.20 2014 Mar 3.30 2014 Apr 2.20 2014 May 10.20 2014 Jun 12.20 2014 Jul 2.30 2014 Aug 0.40 2014 Sep 0.20 2014 Oct 1.10 2014 Nov 2.10 2014 Dec 0.40 2015 Jan 1.10 2015 Feb 2.20 2015 Mar 3.30 2015 Apr 2.20 2015 May 10.20 2015 Jun 12.20 2015 Jul 2.30 2015 Aug 0.40 2015 Sep 0.20 2015 Oct 1.10 2015 Nov 2.10 2015 Dec 0.40 Please try the Precipitation program again.
2 Enter data? = n
No data was input at this time.
3
Please try the Precipitation program again.
C Code
The following is the C Code that will compile in execute in the online compilers.
// C code // This program will input and store meteorological data into an array. // Developer: Faculty CMIS102 // Date: Jan 31, XXXX #define NUMMONTHS 12 #define NUMYEARS 5 #include <stdio.h>
// function prototypes void inputdata(); void printdata();
// Global variables // These are available to all functions float Raindata[NUMYEARS][NUMMONTHS]; char years[NUMYEARS][5] = {"2011","2012","2013","2014","2015"}; char months[NUMMONTHS][12] ={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}; int main () { char enterData = 'y'; printf("Do you want to input Precipatation data? (y for yes)\n"); scanf("%c",&enterData); if (enterData == 'y') { // Call Function to Input data inputdata(); // Call Function to display data printdata(); } else { printf("No data was input at this time\n"); } printf("Please try the Precipitation program again. \n"); return 0; } // function to inputdata void inputdata() { /* variable definition: */ float Rain=1.0; // Input Data for (int year=0;year < NUMYEARS; year++) { for (int month=0; month< NUMMONTHS; month++) { printf("Enter rain for %d, %d:\n", year+1, month+1); scanf("%f",&Rain); Raindata[year][month]=Rain;
4
} } } // Function to printdata void printdata(){ // Print data printf ("year\t month\t rain\n"); for (int year=0;year < NUMYEARS; year++) { for (int month=0; month< NUMMONTHS; month++) { printf("%s\t %s\t %5.2f\n", years[year],months[month],Raindata[year][month]); } } }
Setting up the code and the input parameters in ideone.com:
You can change these values to any valid integer values to match your test cases.
5
Results from running the programming at ideone.com
6
Learning Exercises for you to complete
1. Modify the program to add a function to sum the rainfall for each year. (Hint: you need to sum for each year. You can do this using a looping structure). Support your experimentation with screen captures of executing the new code.
2. Enhance the program to allow the user to enter another meteorological element such as windspeed (e.g. 2.4 mph). Note, the user should be able to enter both rainfall and windspeed in your new implementation. Support your experimentation with screen captures of executing the new code.
3. Prepare a new test table with at least 2 distinct test cases listing input and expected output for the code you created after step 2.
4. What happens if you change the NUMMONTHS and NUMYEARS definitions to other values? Be sure to use both lower and higher values. Describe and implement fixes for any issues if errors results. Support your experimentation with screen captures of executing the new code.
Grading guidelines
Submission Points Successfully demonstrates execution of this lab with online compiler. Includes a screen capture. 2 Modifies the code to add a function to sum the rainfall for each year. Support your experimentation with screen captures of executing the new code 2 Enhances the program to allow the user to enter another meteorological element such as windspeed (e.g. 2.4 mph). Support your experimentation with screen captures of executing the new code. 2
Provides a new test table with at least 2 distinct test cases listing input and expected output for the code you created after step 2.
1
Describes what would happen if you change the NUMMONTHS and NUMYEARS definitions to other values? Applies both lower and higher values. Describes and implements fixes for any issues if errors results. Support your experimentation with screen captures of executing the new code.
2
Document is well-organized, and contains minimal spelling and grammatical errors.
Homework 2
Homework 2 – Test Case Creation
Using the following pseudocode, provide 3 unique test cases that would help validate your algorithm. Be sure to place the test cases in a table showing the input values, and expected output for each test case.
Write "Enter the price in dollars:"
Input Price
Write "Enter state sales tax(e.g. .06) :"
Input SalesTax
Set Price = Price + (Price * SalesTax)
Write "Price with Tax is" + Price
Submit your word or PDF file to your assignments folder no later than the due date.
Grading guidelines
Submission Points A minimum of 3 test cases were provided. 2 Input provided and explained for each test case. 1 Expected output provided and explained for each test case. 1 Test cases represent a wide variety of possible input values (e.g. large numbers, small numbers (0), negative, or unexpected non-number entries). 1 Total 5
Homework 3 – Create your own Loop application
Create your own unique While-End or (For End) repetition C code. You decide the theme. Be sure to provide an overview of what your repetition structure is doing. Please keep the design simple for this exercise. Just a few lines of code is all that is needed for this response. This should be code you wrote for an application that is interesting to you. In other words, make it your own and have fun with it.
Provide the C code and a screen capture showing the results of testing your code in an online compiler. Be sure to test your code with several test cases and show your test case table.
Submit your word or PDF file to your assignments folder no later than the due date.
Grading guidelines
Submission Points Unique C code for simple While or For loop was provided and compiles without issue. 2 Screen captures provided showing test results for each test case. 2 Test cases represent a wide variety of possible input values (e.g. large numbers, small numbers (0), negative, or unexpected non-number entries). 1 Total 5
Homework 4 – Create your own Function
Create your own function in C that accepts one input parameter and returns a float number. You decide the theme.
You should provide both your C code and an example call to the C code function. Be sure to provide an overview of what your function is doing.
Provide a screen capture showing the results of testing your code in an online compiler.
Be sure to test your code with several test cases and show your test case table.
Submit your word or PDF file to your assignments folder no later than the due date.
Grading guidelines
Submission Points Unique C code for simple function that accepts one input parameter and returns a float number was provided and compiles without issue. 2 C code provided that correctly calls your simple function. 1 Screen captures of test cases represent a wide variety of possible input values (e.g. large numbers, small numbers (0), negative, or unexpected non-number entries). 2 Total 5

-
Rating:
5/
Solution: umuc cmis102 full course (discussions+assignments+homework) latest 2016 October