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 =...
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.
I want to indent this c++ program #include<iostream> using namespace std; class Rectangle{ private: double width;...
I want to indent this c++ program #include<iostream> using namespace std; class Rectangle{ private: double width; double length; public: void setWidth(double); void setLength(double); double getWidth() const; double getLength() const; double getArea() const; double getPerimeter() const; bool isSquare() const; }; void Rectangle::setWidth(double w){ width = w; } void Rectangle::setLength(double l){ length = l; } double Rectangle::getWidth() const{ return width; } double Rectangle::getLength() const{ return length; } // Added Method definitions double Rectangle::getArea() const{ return (width * length); } double Rectangle::getPerimeter() const{...
Debug please. It's in C++ #include<iostream> #include<string> using namespace std; template <class T> double half(int x)...
Debug please. It's in C++ #include<iostream> #include<string> using namespace std; template <class T> double half(int x) { double h = x / 2; return h; } class TuitionBill { friend ostream& operator<<(ostream, TuitionBill); private: string student; double amount; public: TuitionBill(string, double); double operator/(int); }; TuitionBill::TuitionBill(string student, double amt) { student = student; amount = amt; } double TuitionBill::operator/(int factor) { double half = amount / factor; return hafl; } ostream& operator<<(ostream& o, TuitionBill) { o << t.student << " Tuition:...
#include <iostream> #include <string> #include <fstream> #include <vector> #include <sstream> using namespace std; int main() {...
#include <iostream> #include <string> #include <fstream> #include <vector> #include <sstream> using namespace std; int main() { ifstream infile("worldpop.txt"); vector<pair<string, int>> population_directory; string line; while(getline(infile, line)){ if(line.size()>0){ stringstream ss(line); string country; int population; ss>>country; ss>>population; population_directory.push_back(make_pair(country, population)); } } cout<<"Task 1"<<endl; cout<<"Names of countries with population>=1000,000,000"<<endl; for(int i=0;i<population_directory.size();i++){ if(population_directory[i].second>=1000000000){ cout<<population_directory[i].first<<endl; } } cout<<"Names of countries with population<=1000,000"<<endl; for(int i=0;i<population_directory.size();i++){ if(population_directory[i].second<=1000000){ cout<<population_directory[i].first<<endl; } } } can u pls explain the logic behind this code up to 10 lines pls, many thanks
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT