modular programming notes

# modular programming notes - Int j=5 Hello(j since this is a...

This preview shows pages 1–3. Sign up to view the full content.

Modular Programming Thursday, October 07, 2010 10:43 AM 1. Void a. With value parameters b. With reference parameters 2. Value-Returning a. With value parameters b. With reference parameters (not recommended) Function Example Return-type name (list of parameters) { Executable } Void function(); (declares a prototype function) Function(); - runs a function Void displayAnswers(double area, double circ) { Cout<<fixed; Cout << "C is " << setprescision(2)<< circ << endl; } Void functions Void functionname ("list of paramters) { "Body of function" } Program example: Void hello (int count)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
{ Int I; For(i=1; I <= count'; i++) Cout << "Hello world" << endl; } Int main()
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { Int j=5; Hello(j); // since this is a void function, it can not return a value Return 0; } Value Returning Functions //Example for a function that converts Fahrenheit to Celsius Double fToC (double degF) { Return 5*(degF-32)/9; //Return statement gives value to "fToC" (required for value returning function) } Int main() { Int j=5; Double ans; Hello(j); // from above Ans =fToC(32); Cout << ans; Return 0; } //For a factorial Int factorial(int n) { If(n==0) Return 1; Int I, prod = 1; For(i=1;i<=n;i++) Prod=prod*I; Return prod; } Will return the factorial of a number...
View Full Document

## This note was uploaded on 06/20/2011 for the course CSC 1253 taught by Professor Staff during the Fall '08 term at LSU.

### Page1 / 3

modular programming notes - Int j=5 Hello(j since this is a...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online