// C++ program to create an application for ordering a
book
#include <iostream>
#include <cctype>
#include <iomanip>
using namespace std;
int main() {
string title, author, isbn;
double price, tax;
int quantity;
bool fiction;
char fictionInput;
char genre;
double fee;
double subtotal;
// input of book details
cout<<"Enter book details : "<<endl;
// input of title
cout<<"Title : ";
getline(cin,title);
title = title.substr(0,title.length()-1); // remove
'\n' from the end
// input of author
cout<<"Author : ";
getline(cin,author);
author = author.substr(0,author.length()-1); // remove
'\n' from the end
// input of isbn
cout<<"ISBN : ";
cin>>isbn;
// validate the number of characters in isbn is 9 or
13
if(isbn.length() != 9 && isbn.length() !=
13)
{
cout<<"Invalid
ISBN"<<endl;
return 1;
}
// input of price
cout<<"Price : ";
cin>>price;
// validate price < 400
if(price >=400)
{
cout<<"Invalid
price"<<endl;
return 1;
}
// input of quantity
cout<<"Quantity : ";
cin>>quantity;
// validate quantity >0 and quantity < 100
if(quantity < 0 || quantity >= 100)
{
cout<<"Invalid
quantity"<<endl;
return 1;
}
// input of fiction
cout<<"Fiction(F) / Non-fiction(N) :";
cin>>fictionInput;
// validate fiction input
if((toupper(fictionInput) != 'F') &&
(toupper(fictionInput) != 'N'))
{
cout<<"Invalid Fiction
input"<<endl;
return 1;
}
// validate fiction input
if(fictionInput == 'F')
fiction = true;
else
fiction = false;
// input of genre
cout<<"Genre ('R'- romance, 'D' - drama, 'M' -
mystery) : ";
cin>>genre;
// validate the genre
if((toupper(genre) != 'R') && (toupper(genre)
!= 'D') && (toupper(genre) != 'M'))
{
cout<<"Invalid
Genre"<<endl;
return 1;
}
// calculate subtotal
subtotal = quantity*price;
// calculate tax
tax = subtotal*0.07;
// determine the fee
int feeIndicator = quantity/10;
switch(feeIndicator)
{
case 9:
fee = 50;
break;
case 8:
fee = 40;
break;
case 7:
fee = 30;
break;
case 6:
fee = 20;
break;
default:
fee = 10;
}
// if book is non-fiction and genre is romance then
remove the fee
if((!fiction) && (toupper(genre) ==
'R'))
fee = 0;
// output the details
cout<<fixed<<setprecision(2);
cout<<"Invoice : "<<endl;
cout<<title<<"
"<<author<<endl;
cout<<"ISBN : "<<isbn;
if(fiction)
cout<<" Fiction ";
else
cout<<" Non-Fiction ";
if(toupper(genre) == 'R')
cout<<"Romance";
else if(toupper(genre) == 'D')
cout<<"Drama";
else
cout<<"Mystery";
cout<<endl;
cout<<"Price : "<<price<<endl;
cout<<"Quantity :
"<<quantity<<endl;
cout<<"SubTotal :
"<<subtotal<<endl;
cout<<"Tax : "<<tax<<endl;
cout<<"Fees : "<<fee<<endl;
cout<<"Total :
"<<(subtotal+tax+fee)<<endl;
return 0;
}
//end of program
Output:
Write a C++ program that asks for the following information about a book order from the...
please use C++ write a program to read a textfile containing a list of books. each line in the file has tile, ... Question: Write a program to read a textfile containing a list of books. each line in the file has tile, ..... write a program to read a textfile containing a list of books. each line in the file has tile, ... Question: Write a program to read a textfile containing a list of books. Each line in...
MUST BE WRITTEN IN C++ Objective: Learn how to define structures and classes, create and access a vector of structures, use sort with different compare functions. Assignment: Your program will use the same input file, but you will print the whole book information, not just the title. And, most importantly, this time you will take an object oriented approach to this problem. Detailed specifications: Define a class named Collection, in which you will define a structure that can hold book...
MUST BE WRITTEN IN C++ Objective: Learn how to define structures and classes, create and access a vector of structures, use sort with different compare functions. Assignment: Your program will use the same input file, but you will print the whole book information, not just the title. And, most importantly, this time you will take an object oriented approach to this problem. Detailed specifications: Define a class named Collection, in which you will define a structure that can hold book...
Write a C++ program that will calculate the total amount of money for book sales at an online store. For each sale, your program should ask the number of books sold and then the price for each book and the shipping method (‘S’ for standard shipping and ‘E’ for expedited shipping). The program will produce a bill showing the subtotal, the sales tax, the discount, the shipping charge, and the final total for the sale. The program will continue processing...
Need a program in python. Asterix and Obelix want to store and process information about movies they are interested in. So, you have been commissioned to write a program in Python to automate this. Since they are not very computer literate, your program must be easy for them to use. They want to store the information in a comma separated text file. Using this they would need to generate a report – see all items AND show a bar chart...
Modify your Online Book Order program from week 4 to prompt the users for the number of books they are purchasing. Using a for loop, prompt the user for the cost of each book and store it into a subtotal. Use the subtotal and the number of books to pass to your method. No changes should be needed to your method or parameters. Output a receipt formatted as the following: Enter the number of books purchased: 4 Enter the book...
8. (15 marks) Write a complete C program, which uses an array of structures and two user defined functions. The program deals with a library database. The program will ask the user to input required information about each book and store it in a structure in a user defined function called get info. The second user defined function display_info will display database information on the screen. The output should look as follows: Book Title Book ld 123456 C Programming 10...
Write a C++ program that uses: .selection constructs (if, if else, and switch) .multiway branches .looping constructs (do and while loops) .Boolean expressions, bool and char types. 1. Develop a program that calculates charges for an Internet provider. The cost is determined by the amount of data used and the consumer plan. Package B (basic) is the most affordable if you plan on using < 20GB (20,000MB), however, if you consume more than 20GB (20,000MB) you are charged for each...
write a c++ program. A real estate broker sets fees for selling properties according to the property type as shown in the table. The broker wants you to write a program that prompts the user for the broker type, sale price of the property and the property code. If the user enters an invalid property code or broker code, the program should display an appropriate message and end the program. Allow the user to enter uppercase and lowercase letters. If...
. Use what you learned from our First Python Program to write a Python program that will carry out the following tasks. Ask user provide the following information: unit price (for example: 2.5) quantity (for example: 4) Use the following formula to calculate the revenue: revenue = unit price x quantity Print the result in the following format on the console: The revenue is $___. (for example: The revenue is $10.0.) . . Use the following formula to calculate the...