program 2
Download
Skip this Video
Download Presentation
Program 2

Loading in 2 Seconds...

play fullscreen
1 / 12

Program 2 - PowerPoint PPT Presentation


  • 60 Views
  • Uploaded on

Program 2. Pseudo Code Read NumOfSongs of 1 st CD (Prime Read!) While not end of file Process CD Read NumOfSongs for next CD. Program 2. Pseudo Code Read NumOfSongs of 1 st CD While not end of file loopCount = 0 While loopCount < NumOfSongs

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Program 2' - troy-baird


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
program 2
Program 2

Pseudo Code

Read NumOfSongs of 1st CD (Prime Read!)

While not end of file

Process CD

Read NumOfSongs for next CD

program 21
Program 2

Pseudo Code

Read NumOfSongs of 1st CD

While not end of file

loopCount = 0

While loopCount < NumOfSongs

Process one song

loopCount ++

Read NumOfSongs for next CD

using functions for program 2
Using Functions for Program 2

int main()

{

...

cin >> numSongs;

while (!cin.eof())

{

loopCount = 0;

while (loopcount < numSongs)

{

ProcessOneSong();

loopCount ++;

}

cin >> numSongs;

}

DisplayResult();

return 0;

}

Pseudo Code

Read NumOfSongs of 1st CD

While not end of file

loopCount = 0

While loopCount < NumOfSongs

Process one song

loopCount ++

Read NumOfSongs for next CD

slide4

int main()

{

. . .

countCD = 0;

cin >> numSongs;

while (!cin.eof())

{

countCD ++;

totalSeconds = 0;

CDHeader(countCD);

loopCount = 0;

while (loopcount < numSongs)

{

ProcessOneSong(totalSeconds);

loopCount ++;

}

DisplayCDTime(countCD, totalSeconds);

grandTotal += totalSeconds;

cin >> numSongs;

}

DisplayResult(countCD, grandTotal);

return 0;

}

slide5

int main()

{

int countCD = 0, grandTotal = 0;

int numSongs;

cin >> numSongs;

while (!cin.eof())

{

ProcessOneCD(numSongs, countCD, grandTotal);

cin >> numSongs;

}

DisplayResult(countCD, grandTotal);

return 0;

}

slide6

void ProcessOneCD(int numSongs,

int& countCD, int& grandTotal)

{

int totalSeconds = 0, loopCount = 0;

countCD ++;

DisplayCDHeader(countCD);

while (loopCount < numSongs)

ProcessOneSong(loopCount, totalSeconds);

DisplayCDResult(countCD, totalSeconds);

grandTotal += totalSeconds;

return;

}

program 3
Program 3

Must Use Functions!

Required functions

Other functions of your own

Each function has at most 30 lines!

Function description!

In, Out and InOut Parameters!

program 31
Program 3

Required Functions

int GetIntegerValue(string inputPrompt,

string errMessage,

int lowLimit, int highLimit);

int NumberOfBoxes(int numTiles);

void DisplayResults(int tiles, int boxes,

int extra);

You must call function GetIntegerValue to get all input values, one at a time. Otherwise, you will lose five points.

slide9
Function Design

Good Functions

Focusing on one thing

Function name tells what it does

sqrt(val)

pow(base, exp)

cin.eof()

cin.get(ch)

slide10
Function Design

Good Functions

int NumberOfBoxes(int numTiles);

float GrossPay(float payRate, float hours);

void DisplayResult(float avg, float max,

float min);

void GetInput(float& payRate,

float& hoursWorked);

void DisplayMenu();

void UpdateMaxMin(float value, float& max,

float& min);

slide11
Bad Functions

float GetRate(float rate)

{

cout << “Enter the rate: ”;

cin >> rate;

return rate;

}

// Why use parameter?

// Use local variable!

float GetRate()

{

float rate;

cout << “Enter the rate: ”;

cin >> rate;

return rate;

}

ad