> number >> quantity; switch ( : Notes">

NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#include <iostream>

using namespace std;

int main()
{
double sum = 0;
int number = 0;
int quantity;
while (number != -1)
{
cout << "Enter product number and quantity sold for next product (-1 0 to exit): ";
cin >> number >> quantity;
switch (number)
{
case 1:
sum += 2.98 * quantity;
break;
case 2:
sum += 4.50 * quantity;
break;
case 3:
sum += 9.98 * quantity;
break;
case 4:
sum += 4.49 * quantity;
break;
case 5:
sum += 6.87 * quantity;
break;
}
}
cout << "Total value is: " << sum << endl;
}

---

#include <iostream>
#include "GradeBook.h" // include definition of class GradeBook
using namespace std;

// constructor initializes courseName with string supplied as argument;
// initializes counter data members to 0
GradeBook::GradeBook( string name )
{
setCourseName( name ); // validate and store courseName
aCount = 0; // initialize count of A grades to 0
bCount = 0; // initialize count of B grades to 0
cCount = 0; // initialize count of C grades to 0
dCount = 0; // initialize count of D grades to 0
fCount = 0; // initialize count of F grades to 0
} // end GradeBook constructor

// function to set the course name; limits name to 25 or fewer characters
void GradeBook::setCourseName( string name )
{
if ( name.length() <= 25 ) // if name has 25 or fewer characters
courseName = name; // store the course name in the object
else // if name is longer than 25 characters
{ // set courseName to first 25 characters of parameter name
courseName = name.substr( 0, 25 ); // select first 25 characters
cout << "Name "" << name << "" exceeds maximum length (25).n"
<< "Limiting courseName to first 25 characters.n" << endl;
} // end if...else
} // end function setCourseName

// function to retrieve the course name
string GradeBook::getCourseName()
{
return courseName;
} // end function getCourseName

// display a welcome message to the GradeBook user
void GradeBook::displayMessage()
{
// this statement calls getCourseName to get the
// name of the course this GradeBook represents
cout << "Welcome to the grade book forn" << getCourseName() << "!n"
<< endl;
} // end function displayMessage

// input arbitrary number of grades from user; update grade counter
void GradeBook::inputGrades()
{
int grade; // grade entered by user

cout << "Enter the letter grades." << endl
<< "Enter the EOF character to end input." << endl;

// loop until user types end-of-file key sequence
while ( ( grade = cin.get() ) != EOF )
{
// determine which grade was entered
switch ( grade ) // switch statement nested in while
{
case 'A': // grade was uppercase A
case 'a': // or lowercase a
++aCount; // increment aCount
break; // necessary to exit switch

case 'B': // grade was uppercase B
case 'b': // or lowercase b
++bCount; // increment bCount
break; // exit switch

case 'C': // grade was uppercase C
case 'c': // or lowercase c
++cCount; // increment cCount
break; // exit switch

case 'D': // grade was uppercase D
case 'd': // or lowercase d
++dCount; // increment dCount
break; // exit switch

case 'F': // grade was uppercase F
case 'f': // or lowercase f
++fCount; // increment fCount
break; // exit switch

case 'n': // ignore newlines,
case 't': // tabs,
case ' ': // and spaces in input
break; // exit switch

default: // catch all other characters
cout << "Incorrect letter grade entered."
<< " Enter a new grade." << endl;
break; // optional; will exit switch anyway
} // end switch
} // end while
} // end function inputGrades

// display a report based on the grades entered by user
void GradeBook::displayGradeReport()
{
// output summary of results
cout << "nnNumber of students who received each letter grade:"
<< "nA: " << aCount // display number of A grades
<< "nB: " << bCount // display number of B grades
<< "nC: " << cCount // display number of C grades
<< "nD: " << dCount // display number of D grades
<< "nF: " << fCount // display number of F grades
<< "nGrade-point average: " << static_cast<double>((aCount * 4 + bCount * 3 + cCount*2 + dCount))
/ (aCount + bCount + cCount + dCount + fCount)
<< endl;
} // end function displayGradeReport

---

#include <string> // program uses C++ standard string class
using namespace std;

// GradeBook class definition
class GradeBook
{
public:
GradeBook( string ); // constructor initializes course name
void setCourseName( string ); // function to set the course name
string getCourseName(); // function to retrieve the course name
void displayMessage(); // display a welcome message
void inputGrades(); // input arbitrary number of grades from user
void displayGradeReport(); // display a report based on the grades
private:
string courseName; // course name for this GradeBook
int aCount; // count of A grades
int bCount; // count of B grades
int cCount; // count of C grades
int dCount; // count of D grades
int fCount; // count of F grades
}; // end class GradeBook

---

#include "GradeBook.h" // include definition of class GradeBook

int main()
{
// create GradeBook object
GradeBook myGradeBook( "CS101 C++ Programming" );

myGradeBook.displayMessage(); // display welcome message
myGradeBook.inputGrades(); // read grades from user
myGradeBook.displayGradeReport(); // display report based on grades
} // end main
     
 
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.