Question

In: Computer Science

#include <iostream> using namespace std; double print_instructions() { cout << "WELCOME TO BandN book stores" <<...

#include <iostream>

using namespace std;

double print_instructions() {
cout << "WELCOME TO BandN book stores" << endl;
cout << "Today we have a deal on e-books. Customers will receive a discount off their entire order.." << endl;
cout << "The discount is 15% off your total order and cost per book is 8.99." << endl;
cout << "Customers who buy 20 or more e-books will receive 20% off instead." << endl;
cout << endl;
return 0;
}

int no_of_books() {
string s;
cout << "Write yes if you wish to shop : ";
cin >> s;
int n = 0;
if (s == "yes" || s == "YES") {
cout << "Numbers of Books you wish to buy: ";
cin >> n;
cout << endl;
}
return n;
}

double sub_total(int n) {
double s_total = 8.99 * n;
return s_total;
}

double discount(double s_total) {
double dis = s_total * 0.15;
return dis;
}

double total_cost(double s_total, double dis) {
double t_cost = s_total - dis;
return t_cost;
}

double print_results(int n, double s_total, double dis, double t_cost) {
cout << " Amount of books wish to download : " << n << endl;
cout << " The subtotal for books is : " << s_total << endl;
cout << " The discount given is : " << dis << endl;
cout << " The final cost of book is : " << t_cost << endl;
return 0;
}

int main() {
print_instructions();
int n = no_of_books();
if (n > 0)
{
double s_total = sub_total(n);
double dis = discount(s_total);
double t_cost = total_cost(s_total, dis);
print_results(n, s_total, dis, t_cost);
}

else {
cout << "Invalid Number of books!" << endl;
}
return 0;
}

IS THERE ANY OTHER WAY TO WRITE THIS CODE? DIFFERENT FUNCTIONS?? WHAT CHANGES COULD I MAKE?

Solutions

Expert Solution

Hello, Student I hope you are doing good and well in lockdown.

Your Program is fine enough in case of coding which meets the functionalities and achieved So I think you should not need anything in this above code but Yes you should work on its UI and try to add more features if you want to implement in it.

I had modified this in terms of UI and created some changes, you can ask me more in comment section if you needed anything, I am always happy to help.

Please upvote <3

#include <iostream>

using namespace std;

double print_instructions() {
cout << "\n\t\t\t\t\t\tWELCOME TO BandN book stores\n" << endl;
cout<<"\t\t\t\t\t-----------------------------------------------\n"<<endl;
cout <<"\t\tToday we have a deal on e-books. Customers will receive a discount off their entire order.." << endl;
cout << "\t\tThe discount is 15% off your total order and cost per book is 8.99." << endl;
cout << "\t\tCustomers who buy 20 or more e-books will receive 20% off instead." << endl;
cout << endl;
return 0;
}

int no_of_books() {
string s;
cout << "Write yes if you wish to shop [yes/No] : ";
cin >> s;
int n = 0;
if (s == "yes" || s == "YES") {
cout << "\nNumbers of Books you wish to buy: ";
cin >> n;
cout << endl;
} else{
    cout<<"\n\t\t\t\t\tThanks for Visiting BandN book stores"<<endl;
}
return n;
}

double sub_total(int n) {
double s_total = 8.99 * n;
return s_total;
}

double discount(double s_total) {
double dis = s_total * 0.15;
return dis;
}

double total_cost(double s_total, double dis) {
double t_cost = s_total - dis;
return t_cost;
}

double print_results(int n, double s_total, double dis, double t_cost) {
cout << " Amount of books wish to download : " << n << endl;
cout << " The subtotal for books is : " << s_total << endl;
cout << " The discount given is : " << dis << endl;
cout << " The final cost of book is : " << t_cost << endl;
cout<< "\n\n\t\t\t\t\tThanks for Purchasing with us!! See you soon Again\n\n";
return 0;
}

int main() {
print_instructions();
int n = no_of_books();
if (n > 0)
{
double s_total = sub_total(n);
double dis = discount(s_total);
double t_cost = total_cost(s_total, dis);
print_results(n, s_total, dis, t_cost);
}

return 0;
}

Screenshots: -

Please upvote or hit that thumbs-up button, it really motivates me<3

And Again feel free to ask in comment section .

Thank you!!

Have a nice day:)


Related Solutions

#include "IntVariableTable.h" #include "Tokens.h" #include <assert.h> #include <iostream> #include <iomanip> using std::cout; using std::endl; using std::left;...
#include "IntVariableTable.h" #include "Tokens.h" #include <assert.h> #include <iostream> #include <iomanip> using std::cout; using std::endl; using std::left; using std::right; using std::setw; using std::string; // The IntVariableTable constructor dynamically allocates the fixed size array of integer variables. IntVariableTable::IntVariableTable() { int_variable_table = new IntVariableEntry[MAX_INT_VARIABLES]; } // The IntVariableTable destructor deallocates the integer variable array. IntVariableTable::~IntVariableTable() { delete[] int_variable_table; } // Returns the number of variables added to the integer variable table. int IntVariableTable::numVariables() const { return num_int_variables; } // Returns the index of...
#include<iostream> #include<cmath> using namespace std; int p = 7; void main() { extern double var ;...
#include<iostream> #include<cmath> using namespace std; int p = 7; void main() { extern double var ; int p = abs(-90); cout << ::p + p - var << endl; system("pause"); } double var = 5.5;
c++ #include <iostream> #include <string> #include <ctime> using namespace std; void displayArray(double * items, int start,...
c++ #include <iostream> #include <string> #include <ctime> using namespace std; void displayArray(double * items, int start, int end) { for (int i = start; i <= end; i++) cout << items[i] << " "; cout << endl; } //The legendary "Blaze Sort" algorithm. //Sorts the specified portion of the array between index start and end (inclusive) //Hmmm... how fast is it? /* void blazeSort(double * items, int start, int end) { if (end - start > 0) { int p...
Can anyone change it to double linked list #include<stdio.h> #include<stdlib.h> #include <iostream> using namespace std; struct...
Can anyone change it to double linked list #include<stdio.h> #include<stdlib.h> #include <iostream> using namespace std; struct Node {     int data;     struct Node* next; }; void printMiddle(struct Node *head) {     struct Node *slow_ptr = head;     struct Node *fast_ptr = head;     if (head!=NULL)     {         while (fast_ptr != NULL && fast_ptr->next != NULL)         {             fast_ptr = fast_ptr->next->next;             slow_ptr = slow_ptr->next;         }         printf("The middle element is [%d]\n\n", slow_ptr->data);     } } void...
#include <iostream> #include <string> #include <ctime> using namespace std; void displayArray(double * items, int start, int...
#include <iostream> #include <string> #include <ctime> using namespace std; void displayArray(double * items, int start, int end) { for (int i = start; i <= end; i++) cout << items[i] << " "; cout << endl; } //The legendary "Blaze Sort" algorithm. //Sorts the specified portion of the array between index start and end (inclusive) //Hmmm... how fast is it? /* void blazeSort(double * items, int start, int end) { if (end - start > 0) { int p =...
#include <iostream> #include <string> #include <ctime> using namespace std; void displayArray(double * items, int start, int...
#include <iostream> #include <string> #include <ctime> using namespace std; void displayArray(double * items, int start, int end) { for (int i = start; i <= end; i++) cout << items[i] << " "; cout << endl; } //The legendary "Blaze Sort" algorithm. //Sorts the specified portion of the array between index start and end (inclusive) //Hmmm... how fast is it? /* void blazeSort(double * items, int start, int end) { if (end - start > 0) { int p =...
--- TURN this Code into Java Language --- #include <iostream> #include <string> using namespace std; //...
--- TURN this Code into Java Language --- #include <iostream> #include <string> using namespace std; // constants const int FINAL_POSITION = 43; const int INITIAL_POSITION = -1; const int NUM_PLAYERS = 2; const string BLUE = "BLUE"; const string GREEN = "GREEN"; const string ORANGE = "ORANGE"; const string PURPLE = "PURPLE"; const string RED = "RED"; const string YELLOW = "YELLOW"; const string COLORS [] = {BLUE, GREEN, ORANGE, PURPLE, RED, YELLOW}; const int NUM_COLORS = 6; // names...
***Convert the C++ to Python*** #include <iostream> using std::cout; using std::cin; using std::endl; int charClass; char...
***Convert the C++ to Python*** #include <iostream> using std::cout; using std::cin; using std::endl; int charClass; char lexeme[100]; char str[200]; char nextChar; const int LETTER = 0; const int DIGIT   = 1; const int UNKNOWN = -1; const int OPAREN = 2; const int CPAREN = 3; const int PLUS = 4; const int MINUS = 5; const int MUL = 6; const int DIV = 7; const int ID_CODE = 100; const int PLUS_CODE = 101; const int MINUS_CODE =...
using only loops, no functions and no arrays. with the heading: #include <iostream> using namespace std;...
using only loops, no functions and no arrays. with the heading: #include <iostream> using namespace std; "Write a program that asks the user to enter an odd positive integer. The program reads a value (n) entered by the user and prints an n x n grid displaying a large letter X. The left half should be made up of pluses (+) and the right half should be made with the character "x" and the very center should be an asteric...
Using only loops, no functions and no arrays. with the heading: #include <iostream> using namespace std;...
Using only loops, no functions and no arrays. with the heading: #include <iostream> using namespace std; "Write a program that asks the user to enter an integer between 1 and 20. If the user enters an illegal number, the program repeatedly asks the user to enter the correct one. If the user has not entered a correct number after 10 attempts, the program chooses the number 10 as the user's number. The program prints the cube of the user's number.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT