NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

///////////////////////////////////////////////////////////////////////////////
//
// Name: FILE-NAME-GOES-HERE
// Author: AUTHOR-NAME GOES HERE
// Course: CMPSC 101/121
// Purpose: DESCRIPTIVE-PURPOSE-GOES-HERE.
//
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
// Header Files...
///////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>

///////////////////////////////////////////////////////////////////////////////
// Namespaces used....
///////////////////////////////////////////////////////////////////////////////
using namespace std;

///////////////////////////////////////////////////////////////////////////////
// Function Prototypes....
///////////////////////////////////////////////////////////////////////////////
void pause();
// causes the program to pause until the user presses ENTER...
double inputVolume();
// input a volume from the user and returns it.
void inputVolumes(double volumes[], int num);
// inputs a series of volumes from the user
string inputName();
// inputs the name from the user and returns it
int howManyPopped(double volumes[], int num);
// returns the number of volumes that exceed the "max" value.
void outputNumPopped (string name, double volumes[], int num);
// outputs a message to the user indicating the number of "popped" balloons


///////////////////////////////////////////////////////////////////////////////
//
// FUNCTION NAME: howManyPopped
// PARAMETERS: volumes[], num
// RETURN TYPE: int
// PURPOSE: returns number of volumes that exceed "max" value
///////////////////////////////////////////////////////////////////////////////
int howManyPopped(double volumes[], int num)
{
// declare a variable to store the number of "popped" balloons...
int num_popped = 0;
for (int i = 0; i < num; i++) {
// check the next volume...
if (volumes[i] > 120.30) {
// add one to the count...
num_popped++;
}
}
// return the number that popped...
return num_popped;
}
///////////////////////////////////////////////////////////////////////////////
//
// FUNCTION NAME: inputName
// PARAMETERS: None
// RETURN TYPE: string
// PURPOSE: Prompts the user for a name and returns the user input
// to the calling function
///////////////////////////////////////////////////////////////////////////////

string inputName()
{
// declare a variable to store the return value...
string name;
// prompt the user...
cout << "Please enter your name: ";
// get the input...
getline(cin, name);
//return the user input...
return name;
}

///////////////////////////////////////////////////////////////////////////////
//
// FUNCTION NAME: inputVolume()
// PARAMETERS: None
// RETURN TYPE: double
// PURPOSE: Inputs and returns a volume from the user.
//
///////////////////////////////////////////////////////////////////////////////


double inputVolume()
{
// declare a variable to store the user input...
double volume = 0.0;
// declare a flag variable...
bool is_valid = false;
do
{
// input the volume
cin >> volume;
if (cin.fail())
{
// no, tell the user
cout << "ERROR! The volume must be a real number > 0."
<< "nPlease try again.nn";
// clear the flags...
cin.clear();
//ignore the buffer contents
cin.ignore(500, 'n');
}
else if (volume <= 0.0) {
// no, tell the user...
cout << "ERROR! The volume must be > 0. Please try again.nn";
}
else {
// set the flag...
is_valid = true;
}
}
while (!is_valid);
// return the input...
return volume;
}


///////////////////////////////////////////////////////////////////////////////
//
// FUNCTION NAME: inputVolumes
// PARAMETERS: volumes[], num
// RETURN TYPE: void
// PURPOSE: Inputs a series of balloon volumes from the user.
//
///////////////////////////////////////////////////////////////////////////////

void inputVolumes(double volumes[], int num)
{
// prompt the user...
cout << "Please enter " << num << " balloon volumes (in cubic inches) "
<< "separated by spaces:n";
for (int i = 0; i < num; i++) {
// input the next volume...
volumes[i] = inputVolume();
}
}

///////////////////////////////////////////////////////////////////////////////
//
// FUNCTION NAME: outputNumPopped
// PARAMETERS: name, volumes[], num
// RETURN TYPE: int
// PURPOSE: Outputs a message to the user indicating the number
// of "popped" balloons.
///////////////////////////////////////////////////////////////////////////////


void outputNumPopped(string name, double volumes[], int num)
{
// tell the user...
cout << endl << name << " - "
<< howManyPopped(volumes,num)
<< " of your balloon exceed(s) the maximum volume of 120.30 "
<< "cubic inches and therefore must have popped!"
<< endl;
}
///////////////////////////////////////////////////////////////////////////////
//
// FUNCTION NAME: main
// PARAMETERS: none
// RETURN TYPE: int
// PURPOSE: Entry for the program
//
///////////////////////////////////////////////////////////////////////////////

int main()
{
// storage for the volumes...
double volumes[5];
// storage for the name...
string name;
// get the name...
name = inputName();
// get the volumes...
inputVolumes(volumes,5);
// output the results...
outputNumPopped(name, volumes, 5);

/*
NOTE: Do not modify the main() function below this line...
*/

// pause the program...
pause();

// exit the program with success (0 == success)
return 0;
}
// y
///////////////////////////////////////////////////////////////////////////////
//
// FUNCTION NAME: pause
// PARAMETERS: None
// RETURN TYPE: void
// PURPOSE: Causes the program to wait before moving on.
//
///////////////////////////////////////////////////////////////////////////////

void pause()
{
// flush the buffer...
cin.sync();
// alert the user...
cout << "nPress any key to continue...n";
// get the next character...
cin.get();
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.