Need help with a C program The requirements are To write a C

Need help with a C++ program.

The requirements are:

To write a C++ program that:
Builds upon and reinforces our work in project 3
Utilizes programmatic abstraction; breaking down a program into smaller tasks and building those tasks into functions
Use Void functions
Use Boolean functions
Getting input via functions
Functions calling other functions
Using functions in conditions
Prep Readings:
Problem Solving with C++, Chapters 2, 3, 4 and 5.
Program Description :
Write a C++ program that performs the following tasks:
1. This program should meet ALL of the requirements of project 3. If you did not complete project 3, or your project 3 did not meet all the requirements on the grading rubric, review it and complete it. If it is easier for you to start from scratch on this project you may, as long as all of the project 3 requirements are met.
2. Create a void function called get_package(). This function has the following requirements:
a. This function gets the package from the user and assigns it to a global variable.
b. It should do NOTHING other than that
3. Create a void function called get_comics(). This function has the following requirements:
a. This function gets the number of comics from the user and assigns it to a global variable.
b. It should do NOTHING other than that
4. Create a bool function called validate_input(). This function has the following requirements:
a. This function should call get_package() and get_comics()
b. It should employ a switch.
c. If the package and number of comics are valid, the function should return true, otherwise, it should return false
5. Create a function called calculate_package_cost(). This function has the following requirements:
a. It takes in 2 parameters:
i. the number of comics which is an integer
ii. the package selected which is a char
b. it has a return type of double
i. the double returned is the cost of the package
c. it calculates the cost of the package
i. ex: if the user selects package A and 44 comics, the function should return 77.95
6. Create a void function called display_cost(). This function has the following requirements:
a. This function should call calculate_package_cost()
b. It should output the cost of the package to the console
7. Create a function called compare_packages()
a. It takes 2 parameters:
i. The calculated cost of the package selected which is a double
ii. The calculated cost of the package you\'re comparing it to which is a double.
iii. Ex: if you select package A with 5 comics and wanted to compare it to package B, the parameters would be 9.95 and 19.95
b. It has a return type of double
i. The double returned is the difference between plans
ii. In the above example, the return value would be -10.
c. This function should only compare TWO plans. Do not try to compare all 3 plans in the same function at the same time since there can only be one return value.
8. Create a void function called display_alternatives(). This function has the following requirements:
a. This function should call calculate_package_cost()
b. This function should also call compare_packages()
c. It should output the cost savings of the alternative package to the console
9. Display_cost() and display_alternatives should only run if validate_input is true. If the input is invalid, the program should ask for new input, as in projects 3 and 4
10. All functions must be declared at the top of your program and defined at the bottom of your program.
Implementation Notes:
Sometimes you can skip a step and rather than assigning the result of a function to a variable and then using that variable in a condition, you can simply use the function itself in the condition.
It is always good programming practice to write programs in small functional steps, testing each step as you go. Generally this is called Iterative/Incremental development. In that light here is a possible strategy to complete this assignment:
1. Write the get_package function from step 2
2. Test the function (myvar = get_package(); cout << myvar;) if the output to the console is the same as what you type in, then you know that function works.
3. Write the get_comics function
4. Test that function
5. Write the validate_input function.
At first, write the function with static values: \'A\' and 3 for example
Does it return true? If so, you know it works.
Change the values to \'S\' and 3. Does it return false? Then it works
Change the values to \'C\' and -10. Does it return true or false?
When you know it works with the various values, then change the code to use function calls to get_package() and get_comics instead.
Does it still work? If so, you can move to the next function
6. Keep doing this for every function. When you know each function works by itself, then you can write a main function that utilizes all of the other functions. The idea of abstraction is to simplify your program. Each function performs a single simple task. If you find your project is significantly longer than your previous project, you are probably over-thinking it and over-complicating it.
Sample Run:
Which package are you shopping for? (enter A, B, C, or Q to quit)? A How many comics? 5 The charges are $9.95. Which package are you shopping for? (enter A, B, C, or Q to quit)? A How many comics? 300 The charges are $589.95 By switching to Package B you would save $290.00 By switching to Package C you would save $550.00 Which package are you shopping for? (enter A, B, C, or Q to quit)? B
How many comics? 120 The charges are $119.95 By switching to Package C you would save $80.00 Which package are you shopping for? (enter A, B, C, or Q to quit)? f Enter only A, B, C, or Q. Which package are you shopping for? (enter A, B, C, or Q to quit)? 5 Enter only A, B, C, or Q. Which package are you shopping for? (enter A, B, C, or Q to quit)? a How many comics? -12 Enter a number greater than 0. Which package are you shopping for? (enter A, B, C, or Q to quit)? Q Thank you for using this program. Goodbye.

Program it is based on is:

#include <iostream>

using namespace std;

int main()
{
   //these constants were used because thats what was given in the project description
   const double PKGA = 9.95;
   const double PKGAEXTRA = 2.00;
   const double PKGB = 19.95;
   const double PKGBEXTRA = 1.00;
   const double PKGC = 39.95;

   char package;//used char because using a switch statement
   int comics = 0;//used int because all input are whole numbers
   int comicTotalA;//same as comics
   int comicTotalB;
   int comicTotalC;
   double pkgTotal = 0.00;//used double because these is a price also set to 0.00

   do//used to loop until q is selected
   {
      cout << \"Hello and welcome to the discount virtual comic book store.\ \";
      cout << \"We have three packages to choose from.\ \";
      cout << \"Package A: costs $9.95 for 10 comics, and $2.00 for each additional comic download.\ \";
      cout << \"Package B: costs $19.95 for 20 comics, and $1.00 for each additional comic download.\ \";
      cout << \"Package C: costs $39.95 for unlimited comic book downloads.\ \";
      cout << \"If you would like to quit please enter Q.\ \";
    
      cout << \"Which package would you like to purchase?\ \";
      cin >> package;
    
      switch (package)
      {
         case \'a\':
         case \'A\':
            cout << \"You choose package A.\ \";
            cout << \"How many comic books are you planning to get today?\ \";
            cin >> comics;
       
            if(comics <= 10)//check to see if comics are less than 10
            {
               cout << \"The total is: $\" << PKGA <<\".\ \";
            }
            else
            {
               comicTotalA = comics - 10;//used to isolate numbers greater then 10
               pkgTotal = PKGA + comicTotalA * PKGAEXTRA;//used to get price just for package A
          
               cout << \"Your total cost for now is: $\" << pkgTotal <<\".\ \";
               //shows the saving if any by choosing package B or C based on the number of comics
               cout << \"Because you choose to download \" << comics << \" comics.\ \";
               if(pkgTotal - (PKGB + comicTotalA * PKGBEXTRA)<= 0)
               {
                  cout << \"If you change to package B you will not save any money.\ \";
               }
               else
               {
                  cout << \"If you change your package to B you would save $\" << (pkgTotal - (PKGB + comicTotalA * PKGBEXTRA)) << \".\ \";
               }
                if((pkgTotal - PKGC)<= 0)
               {
                  cout << \"If you change to package C you will not save any money.\ \";
               }
               else
               {
                  cout << \"If you change your package to C you would save $\" << (pkgTotal - PKGC) << \".\ \";
               }
              // cout << \"Because you choose to download \" << comics << \" comics, if you change your package to B you would save $\"
                 // << (pkgTotal - (PKGB + comicTotalA * PKGBEXTRA)) << \".\ \";
              // cout << \"If you change your package to C you would save $\" << pkgTotal - PKGC << \".\ \";
            }
          
            break;
       
         case \'b\':
         case \'B\':
            cout << \"You choose package B.\ \";
            cout << \"How many comic books are you planning to get today?\ \";
            cin >> comics;
       
            if(comics <= 20)//checking if less than or equal to 20
            {
               cout << \"The total is: $\" << PKGB <<\".\ \";
            }
            else
            {
               comicTotalB = comics - 20;//used to isolate numbers greater then 20
               pkgTotal = PKGB + comicTotalB * PKGBEXTRA;//used to get total just for package B
          
               cout << \"Your total cost for now is: $\" << pkgTotal <<\".\ \";
               //gives savings if switched to package C
                  if((pkgTotal - PKGC)<= 0)
               {
                  cout << \"If you change to package C you will not save any money.\ \";
               }
               else
               {
                  cout << \"If you change your package to C you would save $\" << (pkgTotal - PKGC) << \".\ \";
               }
              // cout << \"Because you choose to download \" << comics << \" comics, if you change your package to C you would save $\"
                   // << pkgTotal - PKGC << \".\ \";
            }
          
            break;
       
         case \'c\':
         case \'C\':
            cout << \"You choose package C.\ \";
            cout << \"How many comic books are you planning to get today?\ \";
            cin >> comics;
       
            if(comics >= 30)
            {
               cout << \"The total is: $\" << PKGC <<\".\ \";
            }
            else if(comics < 30)//used to suggest package A or B if comics are less then 30
            {
               cout << \"We suggest you choose package A or package B.\ \";
            }
             
            break;
          
         //used to exit program if q or Q is entered
         case \'q\':
         case \'Q\':
            {
               cout << \"Thank you good bye.\";
             
            }
          
      }
   }

   while(package != \'Q\' && package != \'q\');


   return 0;
}

current attempt:

#include <iostream>
using namespace std;


//these constants were used because thats what was given in the project description
const double PKGA = 9.95;
const double PKGAEXTRA = 2.00;
const double PKGB = 19.95;
const double PKGBEXTRA = 1.00;
const double PKGC = 39.95;

char package;//used char because using a switch statement
int comics = 0;//used int because all input are whole numbers
int comicTotalA;//same as comics
int comicTotalB;
int comicTotalC;
double pkgTotal = 0.00;//used double because these is a price also set to 0.00

void get_package();
void get_comics();
void display_cost();
void display_alternatives();
bool validate_input();
double calculate_package_cost();
double compare_packages();

int main()
{

//do//used to loop until q is selected
   //{
      cout << \"Hello and welcome to the discount virtual comic book store.\ \";
      cout << \"We have three packages to choose from.\ \";
      cout << \"Package A: costs $9.95 for 10 comics, and $2.00 for each additional comic download.\ \";
      cout << \"Package B: costs $19.95 for 20 comics, and $1.00 for each additional comic download.\ \";
      cout << \"Package C: costs $39.95 for unlimited comic book downloads.\ \";
      cout << \"If you would like to quit please enter Q.\ \";

      //get_package();
      //cout << package <<\"\ \";
    
      //get_comics();
      //cout << comics <<\"\ \";
    
      validate_input();
   //}

   return 0;
}
void get_package()
{
   cout << \"Which package would you like to purchase?\ \";
   cin >> package;
}

void get_comics()
{
   cout << \"How many comic books are you planning to get today?\ \";
   cin >> comics;
}

bool validate_input()
{
   get_package();
   get_comics();


   switch (package)
      {
         case \'a\':
         case \'A\':
            cout << \"You choose package A.\ \";
            //cout << \"And \" << comics << \" comics.\ \";
            //cout << \"How many comic books are you planning to get today?\ \";
            //cin >> comics;
            /*if(package == \'A\',\'a\')
            {
               return true;
            }
            else
            {
               return false;
            }
          
            if(comics > 0)
            {
               return true;
            }
            else
            {
               return false;
            }*/
          
    
      break;
    
         case \'b\':
         case \'B\':
            cout << \"You choose package B.\ \";
            /*cout << \"How many comic books are you planning to get today?\ \";
            //cin >> comics;
                        if(package == \'B\',\'b\')
            {
               return true;
            }
            else
            {
               return false;
            }*/
          
      break;
    
         case \'c\':
         case \'C\':
            cout << \"You choose package C.\ \";
            /*cout << \"How many comic books are you planning to get today?\ \";
            //cin >> comics;
            if(package == \'C\',\'c\')
            {
               return true;
            }
            else
            {
               return false;
            }*/
    
      break;
    
         case \'q\':
         case \'Q\':
            cout << \"Thank you good bye.\";
            /*if(package == \'Q\',\'q\')
            {
               return true;
            }
            else
            {
               return false;
            }*/
   
      }
          
}

double calculate_package_cost()
{

}

void display_cost()
{

}

double compare_packages()
{

}

void display_alternatives()
{

}

Solution

#include <iostream>
using namespace std;

//these constants were used because thats what was given in the project description
const double PKGA = 9.95;
const double PKGAEXTRA = 2.00;
const double PKGB = 19.95;
const double PKGBEXTRA = 1.00;
const double PKGC = 39.95;

char package;//used char because using a switch statement
int comics = 0;//used int because all input are whole numbers
int comicTotalA;//same as comics
int comicTotalB;
int comicTotalC;

void get_package();
void get_comics();
bool validate_input();
double calculate_package_cost();
void display_cost();
double compare_packages();
void display_alternatives()

int main()
{
     do//used to loop until q is selected
     {
       cout << \"Hello and welcome to the discount virtual comic book store.\ \";
       cout << \"We have three packages to choose from.\ \";
       cout << \"Package A: costs $9.95 for 10 comics, and $2.00 for each additional comic download.\ \";
       cout << \"Package B: costs $19.95 for 20 comics, and $1.00 for each additional comic download.\ \";
       cout << \"Package C: costs $39.95 for unlimited comic book downloads.\ \";
       cout << \"If you would like to quit please enter Q.\";
       validate_input();
    }while(package!=\"q\"||package!=\"Q\")

    return 0;
}
void get_package()
{
    cout << \"Which package would you like to purchase?\ \";
    cin >> package;
}

void get_comics()
{
    cout << \"How many comic books are you planning to get today?\ \";
    cin >> comics;
}

bool validate_input()
{
    get_package();
    get_comics();
    if(package==\"a\"||package==\"A\"||package==\"b\"||package==\"B\"||package==\"c\"||package==\"C\")
        if(comics>0)
            return true;
    retutn false;
}
double calculate_package_cost()
{
    get_package();
    get_comics();

    if(package=\"a\"||package=\"A\")
    {
             cout << \"You choose package A.\ \";
             if(comics <= 10)//check to see if comics are less than 10
             {
                return PKGA;
             }
             else
             {
                comicTotalA = comics - 10;//used to isolate numbers greater then 10
                pkgTotal = PKGA + comicTotalA * PKGAEXTRA;//used to get price just for package A

                cout << \"Your total cost for now is: $\";
                return pkgTotal;
             }
    }
    else if(package=\"B\"||package=\"B\")
    {
             cout << \"You choose package B.\ \";
             if(comics <= 20)//checking if less than or equal to 20
             {
                return PKGB;
             }
             else
             {
                comicTotalB = comics - 20;//used to isolate numbers greater then 20
                pkgTotal = PKGB + comicTotalB * PKGBEXTRA;//used to get total just for package B

                cout << \"Your total cost for now is: $\";
                return pkgTotal;
             }
    }
    else if(package=\"c\"||package=\"C\")
    {
             cout << \"You choose package C.\ \"
             return PKGC;
    }

}

void display_cost()
{
    double pkgTotal=calculate_package_cost();
    cout<<pkgTotal;
}

double compare_packages();
{
    switch (package)
       {
          case \'a\':
          case \'A\':
             if(comics <= 10)//check to see if comics are less than 10
             {
                return;
             }
             else
             {
                comicTotalA = comics - 10;//used to isolate numbers greater then 10
                pkgTotal = PKGA + comicTotalA * PKGAEXTRA;//used to get price just for package A

                cout << \"Your total cost for now is: $\" << pkgTotal <<\".\ \";
                //shows the saving if any by choosing package B or C based on the number of comics
                cout << \"Because you choose to download \" << comics << \" comics.\ \";
                if(pkgTotal - (PKGB + comicTotalA * PKGBEXTRA)<= 0)
                {
                   cout << \"If you change to package B you will not save any money.\ \";
                }
                else
                {
                   cout << \"If you change your package to B you would save $\"
                   diff=(pkgTotal - (PKGB + comicTotalA * PKGBEXTRA));
                }
                break;

          case \'b\':
          case \'B\':
             cout << \"You choose package B.\ \";

             if(comics <= 20)//checking if less than or equal to 20
             {
                cout << \"The total is: $\" << PKGB <<\".\ \";
             }
             else
             {
                comicTotalB = comics - 20;//used to isolate numbers greater then 20
                pkgTotal = PKGB + comicTotalB * PKGBEXTRA;//used to get total just for package B

                cout << \"Your total cost for now is: $\" << pkgTotal <<\".\ \";
                //gives savings if switched to package C
                   if((pkgTotal - PKGC)<= 0)
                {
                   cout << \"If you change to package C you will not save any money.\ \";
                }
                else
                {
                   cout << \"If you change your package to C you would save $\";
                   diff=(pkgTotal - PKGC) << \".\ \";
                }
             }
             break;
       }
       return diff;
}

void display_alternatives()
{
    void display_cost();
    double diff=compare_packages();
    cout<<diff;
}

Need help with a C++ program. The requirements are: To write a C++ program that: Builds upon and reinforces our work in project 3 Utilizes programmatic abstract
Need help with a C++ program. The requirements are: To write a C++ program that: Builds upon and reinforces our work in project 3 Utilizes programmatic abstract
Need help with a C++ program. The requirements are: To write a C++ program that: Builds upon and reinforces our work in project 3 Utilizes programmatic abstract
Need help with a C++ program. The requirements are: To write a C++ program that: Builds upon and reinforces our work in project 3 Utilizes programmatic abstract
Need help with a C++ program. The requirements are: To write a C++ program that: Builds upon and reinforces our work in project 3 Utilizes programmatic abstract
Need help with a C++ program. The requirements are: To write a C++ program that: Builds upon and reinforces our work in project 3 Utilizes programmatic abstract
Need help with a C++ program. The requirements are: To write a C++ program that: Builds upon and reinforces our work in project 3 Utilizes programmatic abstract
Need help with a C++ program. The requirements are: To write a C++ program that: Builds upon and reinforces our work in project 3 Utilizes programmatic abstract
Need help with a C++ program. The requirements are: To write a C++ program that: Builds upon and reinforces our work in project 3 Utilizes programmatic abstract
Need help with a C++ program. The requirements are: To write a C++ program that: Builds upon and reinforces our work in project 3 Utilizes programmatic abstract

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site