SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Bottom of Form
Create your own Function
Functions
For each discussion, provide a snipplet of pseudo-code for the
Main using an example call to the Function as well as the
pseudo-code for the Function.
For each discussion, do the problem you are assigned to as
described by the letters below.
Discussion 1 - Using Pseudocode, create a Function that accepts
one or more input Integer numbers and returns a float number.
You should name your function appropriately as to what it
does. Be sure to document your Function with header and in-
line comments.
Provide a snipplet of psuedo-code for the Main using an
example call to the Function.
Make sure the variable names in the Main are different that in
the Function. In the Main, provide the prompts and get the user
responses. Then pass the data into the Function. After the call
to the Function include a print statements that indicates the
returning value from the call to the Function.
Put Discussion 1 - problem no.X in the Subject area.
You are assigned the problem no. below as follows: If your Last
Name begins with:
A-B - do no. 1
C-F - do no. 2
G-H - do no. 3
I-K - do no. 4
L - do no. 5
M-P - do no. 6
Q-T - do no. 7
U-Z - do no. 8
1)Calculate the Area of a circle. Input: one number
2)Calculate the Circumference a circle. Input: one number
3)Convert the temperature from Celcius to Farenheit Input: one
number
4)Convert the temperature from Farenheit to Celcius. Input: one
number
5)Calculate 6 times a number squared. Input: one number
6)Calculate 3 times the (sum of three numbers). Input: three
numbers
7)Calculate the average of four numbers. Input: four numbers
8)Calculate 5 times the (difference of two numbers). Input two
numbers
You may do additional problems, if you want.
Discussion 2:
Convert Discussion 1 to C-code. Don't for get to prototype your
function before the main and to define your function after the
main. Put Discussion 2 - problem no.X in the Subject area and
submit a .txt (or .c) file for your code.
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, Design(program design, pseudocode),
Test Plan, 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 variables: 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
1
Program Design:
Main
· This program will provide options for a user to calculate the
square
· or cube of a positive Integer input by a user.
· Declare variables
· Initialize loop variable intValue to positive value to start loop
· Loop While input is a positive number
//Prompt user for a number //Get user response
// Only perform menu and function calls if integer is positive If
intValue > 0 Then
//Prompt user for selection Square or Cube
// "Enter 1 to calculate Square, 2 to Calculate Cube " If
menuSelect == 1 Then
// Call the Square Function //Print results
Else If menuSelect == 2 Then // Call the Cube function //Print
results
Else
//Print Invalid msg
End If //End of If menuSelect End If //End of If intValue > 0
//END While
End // End of Main program
· Square Function ------------------------------
//Calculates the square of an Integer
· Cube Function ------------------------------
//Calculates the cubeof an Integer
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
Square of 10 is 100
MenuSelect=1
2
IntValue=10
Cube of 10 is 1000
MenuSelect=2
3
intValue=-1
Program exits
2
MenuSelect=N/A
Pseudocode:
Main
· This program will provide options for a user to calculate the
square
· or cube of a positive Integer input by a user.
· 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
//Prompt user for a number
Print "Enter a positive Integer , Enter -1 to exit::”
Input intValue
// Only perform menu and function calls if integer is positive If
intValue > 0 Then
//Prompt user for selection Square or Cube
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 (“The sqaure of “ + intValue )
Print (“ is: “ + Results + <NL>)
Else If menuSelect == 2 Then // Call the Cube function set
Results = Cube(intValue)
Print (The cube of “ + intValue )
Print (“ is: “ + Results +<NL>)
Else
Print “Invalid menu item, only 1 or 2 is accepted”
End If //End of If menuSelect End If //End of If intValue > 0
END While
End // End of Main program
3
// Square Function ------------------------------
Function Square(Integer value) as Integer
//This function calculates the square of an integer //Input: value
//Output: Square
Set Square = value*value Return (Square)
End Function
// Cube Function ------------------------------
Function Cube(Integer value) as Integer
//This function calculates the cube of an integer //Input: value
//Output: Cube
Set Cube = value*value*value Return (Cube)
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, 2014
#include <stdio.h>
· -- the newer C compilers require that functions be prototyped
· -- this tells the compiler what the input and output datatypes
of the functions are
· -- the functions are later defined after the main.
· function prototypes
int Square ( int ); int Cube ( int );
int main ()
{
/* variable definition: */
int intValue, menuSelect, Results; intValue = 1;
// While a positive number while (intValue > 0)
4
{
printf ("Enter a positive Integer, Enter 0 or neg. no. to exit n:
"); 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");
} //End If (intValue >0) } //End WHile
return 0;
} //end of main
/*********************************************/ /*
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 1 10 2 -99
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 try:
1. Modify the original code and using the Square and Cube
functions as models, create a new function named Divide2 that
would take an Integer input and returns a Float value of the
input Integer divided by 2? Note this should be a float function.
Take care when you prototype youir function. Add this as menu
option 3 to the program to execute this function. Also include in
menu option 3, the display of the results from this function.
Make you have the datatypes correct for your variables. Support
your experimentation with screen captures of executing the new
code.
2. Modify the original code and create a new function of your
own choice. This function should be unique and something you
created for this assignment. Add this as menu option 4 to the
program to execute this function. Your new function should
have at least one argument input and return a calculated value to
the main. You should also in the main display that returning
value. Support your experimentation with screen captures of
executing the new code. Make sure your datatypes of the
variables/function are correct. Submit code as a separate .txt (or
.c )file that includes all four menu options.
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. What would happen if we didn’t have the following test
condition. I.e remove the following code from our design?
If intValue > 0 {
7
} //End IF intValue > 0
What happens if you entered a 0 for the menuSelect variable?
(Hint: You can try in the C code, or walk through it in the
Pseudocode to see what happens.)
8
Grading guidelines
Submission
Points
No 1. Modifies the original code and creates a new function
named Divide2
3
that takes an Integer and returns Float value of the input divided
by 2 .
Support your experimentation with screen captures of executing
the new
code.
No 2. Modifies the original code and adds a new unique
function of your
4
own choice. Adds this as menu option 4 to the program to
execute this
function. Support your experimentation with screen captures of
executing
the new code. Submits code as a separate .txt (or .c ) file.
No 3. Provides a new test table with at least 3 distinct test cases
listing
1
input and expected output for the code you created after step 2.
No 4. Describes what would happen if you removed the “if
intValue =0“
1
line was removed. And what happens if you entered a 0 for the
menuSelect variable. Support your argument with screen
captures of
executing the new code.
Document is well organized, and contains minimal spelling and
1
grammatical errors.
Total
10
9
// 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>
// -- the newer C compilers require that functions be prototyped
// -- this tells the compiler what the input and output datatypes
of the functions are
// -- the functions are later defined after the main.
// function prototypes
int Square ( int );
int Cube ( int );
int main ()
{
/* variable definition: */
int intValue, menuSelect,Results;
intValue = 1;
// While a positive number
while (intValue > 0)
{
// Prompt the user for number
printf ("Enter a positive Integern: ");
scanf("%d", &intValue);
// test for positive value input
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);
} //endif - menuSelect
else
printf("Invalid menu item, only 1 or 2 is
acceptedn");
}
} //EndWhile
return 0;
}
/*** Function defintions ***/
/* function returning the Square of a number */
// This function will return the square of the input value
// Input: value - input number
// Output: return - input number squared (x*x)
int Square(int value)
{
return value*value;
}
/* function returning the Cube of a number */
// This function will return the cube of the input value
// Input: value - input number
// Output: return - input number cubed (x*x*x)
int Cube(int value)
{
return value*value*value;
}

Weitere ähnliche Inhalte

Ähnlich wie Bottom of FormCreate your own FunctionFunctionsFor eac.docx

Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab neweyavagal
 
Presentation 2 (1).pdf
Presentation 2 (1).pdfPresentation 2 (1).pdf
Presentation 2 (1).pdfziyadaslanbey
 
Cmis 102 Effective Communication / snaptutorial.com
Cmis 102  Effective Communication / snaptutorial.comCmis 102  Effective Communication / snaptutorial.com
Cmis 102 Effective Communication / snaptutorial.comHarrisGeorg12
 
EC6612 VLSI Design Lab Manual
EC6612 VLSI Design Lab ManualEC6612 VLSI Design Lab Manual
EC6612 VLSI Design Lab Manualtamil arasan
 
Cmis 102 Enthusiastic Study / snaptutorial.com
Cmis 102 Enthusiastic Study / snaptutorial.comCmis 102 Enthusiastic Study / snaptutorial.com
Cmis 102 Enthusiastic Study / snaptutorial.comStephenson22
 
Cmis 102 Success Begins / snaptutorial.com
Cmis 102 Success Begins / snaptutorial.comCmis 102 Success Begins / snaptutorial.com
Cmis 102 Success Begins / snaptutorial.comWilliamsTaylorza48
 
CHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptxCHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptxGebruGetachew2
 
Bis 311 final examination answers
Bis 311 final examination answersBis 311 final examination answers
Bis 311 final examination answersRandalHoffman
 
Computer paper 3 may june 2004 9691 cambridge General Certificate of educatio...
Computer paper 3 may june 2004 9691 cambridge General Certificate of educatio...Computer paper 3 may june 2004 9691 cambridge General Certificate of educatio...
Computer paper 3 may june 2004 9691 cambridge General Certificate of educatio...Alpro
 
COMP 122 Entire Course NEW
COMP 122 Entire Course NEWCOMP 122 Entire Course NEW
COMP 122 Entire Course NEWshyamuopeight
 
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...bhargavi804095
 
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18HIMANSHU .
 
Mid term sem 2 1415 sol
Mid term sem 2 1415 solMid term sem 2 1415 sol
Mid term sem 2 1415 solIIUM
 

Ähnlich wie Bottom of FormCreate your own FunctionFunctionsFor eac.docx (20)

Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab new
 
P3
P3P3
P3
 
Presentation 2 (1).pdf
Presentation 2 (1).pdfPresentation 2 (1).pdf
Presentation 2 (1).pdf
 
Unit-III.pptx
Unit-III.pptxUnit-III.pptx
Unit-III.pptx
 
Cmis 102 Effective Communication / snaptutorial.com
Cmis 102  Effective Communication / snaptutorial.comCmis 102  Effective Communication / snaptutorial.com
Cmis 102 Effective Communication / snaptutorial.com
 
EC6612 VLSI Design Lab Manual
EC6612 VLSI Design Lab ManualEC6612 VLSI Design Lab Manual
EC6612 VLSI Design Lab Manual
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Chap 5 c++
Chap 5 c++Chap 5 c++
Chap 5 c++
 
Cmis 102 Enthusiastic Study / snaptutorial.com
Cmis 102 Enthusiastic Study / snaptutorial.comCmis 102 Enthusiastic Study / snaptutorial.com
Cmis 102 Enthusiastic Study / snaptutorial.com
 
Cmis 102 Success Begins / snaptutorial.com
Cmis 102 Success Begins / snaptutorial.comCmis 102 Success Begins / snaptutorial.com
Cmis 102 Success Begins / snaptutorial.com
 
CHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptxCHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptx
 
Chap 5 c++
Chap 5 c++Chap 5 c++
Chap 5 c++
 
Bis 311 final examination answers
Bis 311 final examination answersBis 311 final examination answers
Bis 311 final examination answers
 
Introduction to Procedural Programming in C++
Introduction to Procedural Programming in C++Introduction to Procedural Programming in C++
Introduction to Procedural Programming in C++
 
Computer paper 3 may june 2004 9691 cambridge General Certificate of educatio...
Computer paper 3 may june 2004 9691 cambridge General Certificate of educatio...Computer paper 3 may june 2004 9691 cambridge General Certificate of educatio...
Computer paper 3 may june 2004 9691 cambridge General Certificate of educatio...
 
COMP 122 Entire Course NEW
COMP 122 Entire Course NEWCOMP 122 Entire Course NEW
COMP 122 Entire Course NEW
 
Programming Fundamental handouts
Programming Fundamental handoutsProgramming Fundamental handouts
Programming Fundamental handouts
 
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
 
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18
 
Mid term sem 2 1415 sol
Mid term sem 2 1415 solMid term sem 2 1415 sol
Mid term sem 2 1415 sol
 

Mehr von AASTHA76

(APA 6th Edition Formatting and St.docx
(APA 6th Edition Formatting and St.docx(APA 6th Edition Formatting and St.docx
(APA 6th Edition Formatting and St.docxAASTHA76
 
(a) Thrasymachus’ (the sophist’s) definition of Justice or Right o.docx
(a) Thrasymachus’ (the sophist’s) definition of Justice or Right o.docx(a) Thrasymachus’ (the sophist’s) definition of Justice or Right o.docx
(a) Thrasymachus’ (the sophist’s) definition of Justice or Right o.docxAASTHA76
 
(Glossary of Telemedicine and eHealth)· Teleconsultation Cons.docx
(Glossary of Telemedicine and eHealth)· Teleconsultation Cons.docx(Glossary of Telemedicine and eHealth)· Teleconsultation Cons.docx
(Glossary of Telemedicine and eHealth)· Teleconsultation Cons.docxAASTHA76
 
(Assmt 1; Week 3 paper) Using ecree Doing the paper and s.docx
(Assmt 1; Week 3 paper)  Using ecree        Doing the paper and s.docx(Assmt 1; Week 3 paper)  Using ecree        Doing the paper and s.docx
(Assmt 1; Week 3 paper) Using ecree Doing the paper and s.docxAASTHA76
 
(Image retrieved at httpswww.google.comsearchhl=en&biw=122.docx
(Image retrieved at  httpswww.google.comsearchhl=en&biw=122.docx(Image retrieved at  httpswww.google.comsearchhl=en&biw=122.docx
(Image retrieved at httpswww.google.comsearchhl=en&biw=122.docxAASTHA76
 
(Dis) Placing Culture and Cultural Space Chapter 4.docx
(Dis) Placing Culture and Cultural Space Chapter 4.docx(Dis) Placing Culture and Cultural Space Chapter 4.docx
(Dis) Placing Culture and Cultural Space Chapter 4.docxAASTHA76
 
(1) Define the time value of money.  Do you believe that the ave.docx
(1) Define the time value of money.  Do you believe that the ave.docx(1) Define the time value of money.  Do you believe that the ave.docx
(1) Define the time value of money.  Do you believe that the ave.docxAASTHA76
 
(chapter taken from Learning Power)From Social Class and t.docx
(chapter taken from Learning Power)From Social Class and t.docx(chapter taken from Learning Power)From Social Class and t.docx
(chapter taken from Learning Power)From Social Class and t.docxAASTHA76
 
(Accessible at httpswww.hatchforgood.orgexplore102nonpro.docx
(Accessible at httpswww.hatchforgood.orgexplore102nonpro.docx(Accessible at httpswww.hatchforgood.orgexplore102nonpro.docx
(Accessible at httpswww.hatchforgood.orgexplore102nonpro.docxAASTHA76
 
(a) The current ratio of a company is 61 and its acid-test ratio .docx
(a) The current ratio of a company is 61 and its acid-test ratio .docx(a) The current ratio of a company is 61 and its acid-test ratio .docx
(a) The current ratio of a company is 61 and its acid-test ratio .docxAASTHA76
 
(1) How does quantum cryptography eliminate the problem of eaves.docx
(1) How does quantum cryptography eliminate the problem of eaves.docx(1) How does quantum cryptography eliminate the problem of eaves.docx
(1) How does quantum cryptography eliminate the problem of eaves.docxAASTHA76
 
#transformation10EventTrendsfor 201910 Event.docx
#transformation10EventTrendsfor 201910 Event.docx#transformation10EventTrendsfor 201910 Event.docx
#transformation10EventTrendsfor 201910 Event.docxAASTHA76
 
$10 now and $10 when complete Use resources from the required .docx
$10 now and $10 when complete Use resources from the required .docx$10 now and $10 when complete Use resources from the required .docx
$10 now and $10 when complete Use resources from the required .docxAASTHA76
 
#MicroXplorer Configuration settings - do not modifyFile.Versio.docx
#MicroXplorer Configuration settings - do not modifyFile.Versio.docx#MicroXplorer Configuration settings - do not modifyFile.Versio.docx
#MicroXplorer Configuration settings - do not modifyFile.Versio.docxAASTHA76
 
#include string.h#include stdlib.h#include systypes.h.docx
#include string.h#include stdlib.h#include systypes.h.docx#include string.h#include stdlib.h#include systypes.h.docx
#include string.h#include stdlib.h#include systypes.h.docxAASTHA76
 
$ stated in thousands)Net Assets, Controlling Interest.docx
$ stated in thousands)Net Assets, Controlling Interest.docx$ stated in thousands)Net Assets, Controlling Interest.docx
$ stated in thousands)Net Assets, Controlling Interest.docxAASTHA76
 
#include stdio.h#include stdlib.h#include pthread.h#in.docx
#include stdio.h#include stdlib.h#include pthread.h#in.docx#include stdio.h#include stdlib.h#include pthread.h#in.docx
#include stdio.h#include stdlib.h#include pthread.h#in.docxAASTHA76
 
#include customer.h#include heap.h#include iostream.docx
#include customer.h#include heap.h#include iostream.docx#include customer.h#include heap.h#include iostream.docx
#include customer.h#include heap.h#include iostream.docxAASTHA76
 
#Assessment BriefDiploma of Business Eco.docx
#Assessment BriefDiploma of Business Eco.docx#Assessment BriefDiploma of Business Eco.docx
#Assessment BriefDiploma of Business Eco.docxAASTHA76
 
#include stdio.h#include stdint.h#include stdbool.h.docx
#include stdio.h#include stdint.h#include stdbool.h.docx#include stdio.h#include stdint.h#include stdbool.h.docx
#include stdio.h#include stdint.h#include stdbool.h.docxAASTHA76
 

Mehr von AASTHA76 (20)

(APA 6th Edition Formatting and St.docx
(APA 6th Edition Formatting and St.docx(APA 6th Edition Formatting and St.docx
(APA 6th Edition Formatting and St.docx
 
(a) Thrasymachus’ (the sophist’s) definition of Justice or Right o.docx
(a) Thrasymachus’ (the sophist’s) definition of Justice or Right o.docx(a) Thrasymachus’ (the sophist’s) definition of Justice or Right o.docx
(a) Thrasymachus’ (the sophist’s) definition of Justice or Right o.docx
 
(Glossary of Telemedicine and eHealth)· Teleconsultation Cons.docx
(Glossary of Telemedicine and eHealth)· Teleconsultation Cons.docx(Glossary of Telemedicine and eHealth)· Teleconsultation Cons.docx
(Glossary of Telemedicine and eHealth)· Teleconsultation Cons.docx
 
(Assmt 1; Week 3 paper) Using ecree Doing the paper and s.docx
(Assmt 1; Week 3 paper)  Using ecree        Doing the paper and s.docx(Assmt 1; Week 3 paper)  Using ecree        Doing the paper and s.docx
(Assmt 1; Week 3 paper) Using ecree Doing the paper and s.docx
 
(Image retrieved at httpswww.google.comsearchhl=en&biw=122.docx
(Image retrieved at  httpswww.google.comsearchhl=en&biw=122.docx(Image retrieved at  httpswww.google.comsearchhl=en&biw=122.docx
(Image retrieved at httpswww.google.comsearchhl=en&biw=122.docx
 
(Dis) Placing Culture and Cultural Space Chapter 4.docx
(Dis) Placing Culture and Cultural Space Chapter 4.docx(Dis) Placing Culture and Cultural Space Chapter 4.docx
(Dis) Placing Culture and Cultural Space Chapter 4.docx
 
(1) Define the time value of money.  Do you believe that the ave.docx
(1) Define the time value of money.  Do you believe that the ave.docx(1) Define the time value of money.  Do you believe that the ave.docx
(1) Define the time value of money.  Do you believe that the ave.docx
 
(chapter taken from Learning Power)From Social Class and t.docx
(chapter taken from Learning Power)From Social Class and t.docx(chapter taken from Learning Power)From Social Class and t.docx
(chapter taken from Learning Power)From Social Class and t.docx
 
(Accessible at httpswww.hatchforgood.orgexplore102nonpro.docx
(Accessible at httpswww.hatchforgood.orgexplore102nonpro.docx(Accessible at httpswww.hatchforgood.orgexplore102nonpro.docx
(Accessible at httpswww.hatchforgood.orgexplore102nonpro.docx
 
(a) The current ratio of a company is 61 and its acid-test ratio .docx
(a) The current ratio of a company is 61 and its acid-test ratio .docx(a) The current ratio of a company is 61 and its acid-test ratio .docx
(a) The current ratio of a company is 61 and its acid-test ratio .docx
 
(1) How does quantum cryptography eliminate the problem of eaves.docx
(1) How does quantum cryptography eliminate the problem of eaves.docx(1) How does quantum cryptography eliminate the problem of eaves.docx
(1) How does quantum cryptography eliminate the problem of eaves.docx
 
#transformation10EventTrendsfor 201910 Event.docx
#transformation10EventTrendsfor 201910 Event.docx#transformation10EventTrendsfor 201910 Event.docx
#transformation10EventTrendsfor 201910 Event.docx
 
$10 now and $10 when complete Use resources from the required .docx
$10 now and $10 when complete Use resources from the required .docx$10 now and $10 when complete Use resources from the required .docx
$10 now and $10 when complete Use resources from the required .docx
 
#MicroXplorer Configuration settings - do not modifyFile.Versio.docx
#MicroXplorer Configuration settings - do not modifyFile.Versio.docx#MicroXplorer Configuration settings - do not modifyFile.Versio.docx
#MicroXplorer Configuration settings - do not modifyFile.Versio.docx
 
#include string.h#include stdlib.h#include systypes.h.docx
#include string.h#include stdlib.h#include systypes.h.docx#include string.h#include stdlib.h#include systypes.h.docx
#include string.h#include stdlib.h#include systypes.h.docx
 
$ stated in thousands)Net Assets, Controlling Interest.docx
$ stated in thousands)Net Assets, Controlling Interest.docx$ stated in thousands)Net Assets, Controlling Interest.docx
$ stated in thousands)Net Assets, Controlling Interest.docx
 
#include stdio.h#include stdlib.h#include pthread.h#in.docx
#include stdio.h#include stdlib.h#include pthread.h#in.docx#include stdio.h#include stdlib.h#include pthread.h#in.docx
#include stdio.h#include stdlib.h#include pthread.h#in.docx
 
#include customer.h#include heap.h#include iostream.docx
#include customer.h#include heap.h#include iostream.docx#include customer.h#include heap.h#include iostream.docx
#include customer.h#include heap.h#include iostream.docx
 
#Assessment BriefDiploma of Business Eco.docx
#Assessment BriefDiploma of Business Eco.docx#Assessment BriefDiploma of Business Eco.docx
#Assessment BriefDiploma of Business Eco.docx
 
#include stdio.h#include stdint.h#include stdbool.h.docx
#include stdio.h#include stdint.h#include stdbool.h.docx#include stdio.h#include stdint.h#include stdbool.h.docx
#include stdio.h#include stdint.h#include stdbool.h.docx
 

Kürzlich hochgeladen

Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 

Kürzlich hochgeladen (20)

Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 

Bottom of FormCreate your own FunctionFunctionsFor eac.docx

  • 1. Bottom of Form Create your own Function Functions For each discussion, provide a snipplet of pseudo-code for the Main using an example call to the Function as well as the pseudo-code for the Function. For each discussion, do the problem you are assigned to as described by the letters below. Discussion 1 - Using Pseudocode, create a Function that accepts one or more input Integer numbers and returns a float number. You should name your function appropriately as to what it does. Be sure to document your Function with header and in- line comments. Provide a snipplet of psuedo-code for the Main using an example call to the Function. Make sure the variable names in the Main are different that in the Function. In the Main, provide the prompts and get the user responses. Then pass the data into the Function. After the call to the Function include a print statements that indicates the returning value from the call to the Function. Put Discussion 1 - problem no.X in the Subject area. You are assigned the problem no. below as follows: If your Last Name begins with: A-B - do no. 1 C-F - do no. 2 G-H - do no. 3 I-K - do no. 4 L - do no. 5
  • 2. M-P - do no. 6 Q-T - do no. 7 U-Z - do no. 8 1)Calculate the Area of a circle. Input: one number 2)Calculate the Circumference a circle. Input: one number 3)Convert the temperature from Celcius to Farenheit Input: one number 4)Convert the temperature from Farenheit to Celcius. Input: one number 5)Calculate 6 times a number squared. Input: one number 6)Calculate 3 times the (sum of three numbers). Input: three numbers 7)Calculate the average of four numbers. Input: four numbers 8)Calculate 5 times the (difference of two numbers). Input two numbers You may do additional problems, if you want. Discussion 2: Convert Discussion 1 to C-code. Don't for get to prototype your function before the main and to define your function after the main. Put Discussion 2 - problem no.X in the Subject area and submit a .txt (or .c) file for your code. 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, Design(program design, pseudocode), Test Plan, and implementation with C code. The example provided uses sequential, repetition, selection statements and two user-defined function.
  • 3. 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 variables: 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
  • 4. 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 1 Program Design: Main · This program will provide options for a user to calculate the square · or cube of a positive Integer input by a user. · Declare variables · Initialize loop variable intValue to positive value to start loop · Loop While input is a positive number //Prompt user for a number //Get user response // Only perform menu and function calls if integer is positive If intValue > 0 Then //Prompt user for selection Square or Cube
  • 5. // "Enter 1 to calculate Square, 2 to Calculate Cube " If menuSelect == 1 Then // Call the Square Function //Print results Else If menuSelect == 2 Then // Call the Cube function //Print results Else //Print Invalid msg End If //End of If menuSelect End If //End of If intValue > 0 //END While End // End of Main program · Square Function ------------------------------ //Calculates the square of an Integer · Cube Function ------------------------------ //Calculates the cubeof an Integer 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
  • 6. Square of 10 is 100 MenuSelect=1 2 IntValue=10 Cube of 10 is 1000 MenuSelect=2 3 intValue=-1 Program exits 2 MenuSelect=N/A Pseudocode: Main · This program will provide options for a user to calculate the square · or cube of a positive Integer input by a user. · 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
  • 7. //Prompt user for a number Print "Enter a positive Integer , Enter -1 to exit::” Input intValue // Only perform menu and function calls if integer is positive If intValue > 0 Then //Prompt user for selection Square or Cube 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 (“The sqaure of “ + intValue ) Print (“ is: “ + Results + <NL>) Else If menuSelect == 2 Then // Call the Cube function set Results = Cube(intValue) Print (The cube of “ + intValue ) Print (“ is: “ + Results +<NL>) Else Print “Invalid menu item, only 1 or 2 is accepted” End If //End of If menuSelect End If //End of If intValue > 0
  • 8. END While End // End of Main program 3 // Square Function ------------------------------ Function Square(Integer value) as Integer //This function calculates the square of an integer //Input: value //Output: Square Set Square = value*value Return (Square) End Function // Cube Function ------------------------------ Function Cube(Integer value) as Integer //This function calculates the cube of an integer //Input: value //Output: Cube Set Cube = value*value*value Return (Cube) End Function C Code The following is the C Code that will compile in execute in the online compilers. · C code
  • 9. · 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, 2014 #include <stdio.h> · -- the newer C compilers require that functions be prototyped · -- this tells the compiler what the input and output datatypes of the functions are · -- the functions are later defined after the main. · function prototypes int Square ( int ); int Cube ( int ); int main () { /* variable definition: */ int intValue, menuSelect, Results; intValue = 1; // While a positive number while (intValue > 0) 4 {
  • 10. printf ("Enter a positive Integer, Enter 0 or neg. no. to exit n: "); 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"); } //End If (intValue >0) } //End WHile
  • 11. return 0; } //end of main /*********************************************/ /* 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 1 10 2 -99 You can change these values to any valid integer values to match your test cases. 5 Results from running the programming at ideone.com:
  • 12. 6 Learning Exercises for you to try: 1. Modify the original code and using the Square and Cube functions as models, create a new function named Divide2 that would take an Integer input and returns a Float value of the input Integer divided by 2? Note this should be a float function. Take care when you prototype youir function. Add this as menu option 3 to the program to execute this function. Also include in menu option 3, the display of the results from this function. Make you have the datatypes correct for your variables. Support your experimentation with screen captures of executing the new code. 2. Modify the original code and create a new function of your own choice. This function should be unique and something you created for this assignment. Add this as menu option 4 to the program to execute this function. Your new function should have at least one argument input and return a calculated value to the main. You should also in the main display that returning value. Support your experimentation with screen captures of executing the new code. Make sure your datatypes of the variables/function are correct. Submit code as a separate .txt (or .c )file that includes all four menu options. 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. What would happen if we didn’t have the following test condition. I.e remove the following code from our design? If intValue > 0 { 7
  • 13. } //End IF intValue > 0 What happens if you entered a 0 for the menuSelect variable? (Hint: You can try in the C code, or walk through it in the Pseudocode to see what happens.) 8 Grading guidelines Submission Points No 1. Modifies the original code and creates a new function named Divide2 3 that takes an Integer and returns Float value of the input divided by 2 . Support your experimentation with screen captures of executing the new code. No 2. Modifies the original code and adds a new unique function of your 4 own choice. Adds this as menu option 4 to the program to execute this function. Support your experimentation with screen captures of executing
  • 14. the new code. Submits code as a separate .txt (or .c ) file. No 3. Provides a new test table with at least 3 distinct test cases listing 1 input and expected output for the code you created after step 2. No 4. Describes what would happen if you removed the “if intValue =0“ 1 line was removed. And what happens if you entered a 0 for the menuSelect variable. Support your argument with screen captures of executing the new code. Document is well organized, and contains minimal spelling and 1 grammatical errors. Total 10 9
  • 15. // 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> // -- the newer C compilers require that functions be prototyped // -- this tells the compiler what the input and output datatypes of the functions are // -- the functions are later defined after the main. // function prototypes int Square ( int ); int Cube ( int );
  • 16. int main () { /* variable definition: */ int intValue, menuSelect,Results; intValue = 1; // While a positive number while (intValue > 0) { // Prompt the user for number printf ("Enter a positive Integern: "); scanf("%d", &intValue); // test for positive value input if (intValue > 0) { printf ("Enter 1 to calculate Square, 2 to Calculate Cube n: ");
  • 17. 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); } //endif - menuSelect else
  • 18. printf("Invalid menu item, only 1 or 2 is acceptedn"); } } //EndWhile return 0; } /*** Function defintions ***/ /* function returning the Square of a number */ // This function will return the square of the input value // Input: value - input number // Output: return - input number squared (x*x) int Square(int value) {
  • 19. return value*value; } /* function returning the Cube of a number */ // This function will return the cube of the input value // Input: value - input number // Output: return - input number cubed (x*x*x) int Cube(int value) { return value*value*value; }