Question

In: Computer Science

Online Store Project Assignment Four Introduction Project Four introduces the ability to read and write data...

Online Store Project Assignment Four

Introduction

Project Four introduces the ability to read and write data to files. This project will create an online store application circa 1990. The application you will build is a standard C++ console project (visual studios). The store will contain basic operations to shop for items, check out of the store, calculate taxes and totals.

All online store applications are “data driven” in that the contents of the store changes over time. In addition, shipping rates change over time. So this project will read shipping rates and tax rates in from a file. It assumes that these rates are based upon the zipcode provided by the user. The sample data for this file is located here:

90001 0.09000 1.55 1.65 1.72

90002 0.09000 1.55 1.65 1.72

90003 0.09000 1.55 1.65 1.72

9000411 0.09000 1.55 1.65 1.72

90005 0.09000 1.55 1.65 1.72

90006 9 1.55 1.65 1.72

90007 0.09000 1.55 1.65 1.72

90008 0.09000 1.55 1.65 1.72

90009 0.09000 1.55 1.65 -1.72

90010 0.09000 1.55 1.65 1.72

90011 0.09000 -1.55 1.65 1.72

90012 0.09000 1.55 1.65 1.72

90013AB 0.09000 1.55 1.65 1.72

90014 0.09000 1.55 1.65 1.72

90015 0.09000 1.55 1.65 1.72

90016 0.09000 1.55 1.65 1.72

90017 0.09000 1.55 1.65 1.72

90018 0.09000 1.55 1.65 1.72

90019 0.09000 1.55 1.65 1.72

90020 0.09000 1.55 1.65 1.72

90021 0.09000 1.55 1.65 1.72

90022 0.09000 1.55 1.65 1.72

90023 0.09000 1.55 1.65 1.72

90024 0.09000 1.55 1.65 1.72

90025 0.09000 1.55 1.65 1.72

90026 0.09000 1.55 1.65 1.72

90027 0.09000 1.55 1.65 1.72

90028 0.09000 1.55 1.65 1.72

90029 0.09000 1.55 1.65 1.72

90030 0.09000 1.55 1.65 1.72

90031 0.09000 1.55 1.65 1.72

90032 0.09000 1.55 1.65 1.72

90033 0.09000 1.55 1.65 1.72

90034 0.09000 1.55 1.65 1.72

90035 0.09000 1.55 1.65 1.72

90036 0.09000 1.55 1.65 1.72

90037 0.09000 1.55 1.65 1.72

90038 0.09000 1.55 1.65 1.72

90039 0.09000 1.55 1.65 1.72

90040 0.09000 1.55 1.65 1.72

90041 0.09000 1.55 1.65 1.72

90042 0.09000 1.55 1.65 1.72

90043 0.09000 1.55 1.65 1.72

90044 0.09000 1.55 1.65 1.72

90045 0.09000 1.55 1.65 1.72

90046 0.09000 1.55 1.65 1.72

90047 0.09000 1.55 1.65 1.72

90048 0.09000 1.55 1.65 1.72

90049 0.09000 1.55 1.65 1.72

90050 0.09000 1.55 1.65 1.72

90051 0.09000 1.55 1.65 1.72

90052 0.09000 1.55 1.65 1.72

90053 0.09000 1.55 1.65 1.72

90054 0.09000 1.55 1.65 1.72

When a consumer checks out of the store with their shopping cart, most eCommerce applications will email an invoice to the customer. Unfortunately, emailing receipts to customers is beyond the scope of this class! So you will need to write the invoice to a file. The format is described below. You will need to upload a sample output file along with the .cpp file.

Steps and Requirements

Follow the steps below to create your program.

  • Display a welcome statement to the user. Come up with a creative name for the store – such as “Hot Tub Time Machine Parts and Supplies”.
  • The main() function should have a loop that displays a menu of shopping options. This is the control loop for the entire program. Once the user decides to check out or exit the store, the loop can stop.
  • The main function will also need to define all of the variables to be passed to the functions listed below. This includes the
    • Customer name, address, city, zipcode
    • Shopping cart/catalog array – the simplest way to track a catalog of items is to define a structure which will contain the item description, the price of the item, the quantity purchased, and the weight of the item. The weight of items can be in ounces or grams (pick one). Then define an array of structures to track the item quantities.
  • Create the following functions and place the function calls at the appropriate spots in the main() program.
    • loadShipping() - load the shipping rates and tax rates from the sample data file. This function should be called once at the beginning of main().
      • This function will receive an array of structures as input. You need to use a structure to save each rate for later use. Define the structure at the top of the program. There will be multiple lines in the file. The function does not have to return anything.
      • The layout of the file is
        • Zipcode taxrate USPSrate UPSrate FedexRate
      • Your function should validate the input data from the file. If data is invalid, skip over that line and proceed to the next line of the file. Things to check for include
        • Zipcode longer than 5 digits
        • Negative or invalid tax and shipping rate values. In project one, you hardcoded a shipping rate for each carrier. The file will now contain the rate (as a real number). When you look at the text file you will see some Los Angeles zipcodes with invalid data. Do NOT fix the data. Your code should handle these problems by displaying an error message and skipping that row of data.
        • The sample file contains all zip codes for California. This is over 2600 zip codes. Your array needs to be at least this big.
        • Hint – Make a copy of the zip code file and delete all lines after line 15. This will create a much smaller set of zip codes to test your program. Once you get everything working, use the main zip code list from Canvas.
    • displayMenu() –It displays the menu options. It does not need any input parameters. It returns the menu choice that the user selected. It should clear the screen each time it is called (hint – one option is to use system(“cls”)). It should validate the user input to make sure they have selected a valid option. The menu should have the following choices:
      • Create Customer Account
      • Shop for Items
      • Proceed to Check Out
      • Exit Store (without buying)
    • createCustomer() – This function prompts for the user’s name and address and saves the results. Input parameters include the name, address, city, and zip. If you choose to use string data types, then you will need to pass by reference. This function does not return anything.
    • maintainCart() – This function allows the user to add an item into their shopping cart. The shopping “cart” is represented by an array. This array is an input parameter to the cart function. Prompt the user with a catalog of items to purchase. You can make up your own list of items with prices that you want to sell (have at least 4-5 items). The user will choose a specific item. Validate the choice. Once a valid choice is made, then ask the user for the quantity to purchase. Save the quantity into the correct array slot. For example,
      • cart[0] – Hut Tub Cover, Price = $150.00
      • cart[1] – Pool Chemicals, Price = $12.00
      • cart[2] – Bubbles, Price = $18.00
      • cart[3] – Time Machine, Price = $4000.00
    • checkOut() – This function will “process” the customer order. In a true eCommerce application, you would charge a credit card and calculate shipping. For this application, the check out consists of calling the following functions. The input parameters are the zipcode, the quantity array. If the zipcode is empty (in the case where the user did not enter their customer info), prompt the user to enter a zipcode at this point.
      • displayReceipt() – This function should loop through all items in the cart and display the item, quantity, price, and extended amounts (price & quantity). This function returns the subtotal of all the items purchased.
      • calculateShipping() – Add up the total weight of all products ordered (quantity > 0). Prompt the user for the shipping method (USPS, UPS, or FEDEX). Based upon their zipcode, find the appropriate rate. Use the following table to calculate the shipping amount. Return this amount from the function.

Weight

Modifier

1-10

1x

11-50

5x

> 50

10x

For example, total weight = 50 ounces shipped via USPS to 90001, results in amount = 5 * 1.55 = $7.55

  • calculateTax() – This function should receive the location of the customer (zipcode) and the subtotal of the order as parameters. Look up the zipcode in the zipcode array to get the tax rate. Calculate the tax amount = subtotal * rate. It should return the tax amount.
  • calculateTotal() – This function should receive the subtotal, shipping amount, and tax amount. It then returns the total. It should verify that the input amounts are valid.

After calling the above functions, the checkOut() routine should display the subtotal, tax, and total amounts to the screen. It should save the invoice or receipt to a file. You should print out the customer name at the top. Follow this with the item descriptions, price, quantity and extended price. Then print the subtotal, tax, shipping, and grand total (on separate lines of the file). Name the file “invoice.txt”.

    • Make sure not to print out any items that may not have been ordered (quantity = 0) from the cart.
  • Extra Credit One (2 points) – Use the C++ date functions to print out the current date in the saveInvoice function. This can be tricky to get formatting correct.
  • Extra Credit Two (4 points) – For the saveInvoice function, save the file in .html format. Use basic tags such as header <h1>, paragraph <p>, lists <ul> to format the invoice. With the HTML format, the grader should be able to double click on the file and have it launch to a browser.

Solutions

Expert Solution

#include<iostream>
#include<cstdlib>
#include<string>
#include<fstream>
#include<vector>


using namespace std;

// tax with corresponding data
class TAXRATE {
   //Zipcode taxrate USPSrate UPSrate FedexRate
private:
   int zipcode;
   float taxrate;
   float USPSrate;
   float USPrate;
   float FedexRate;
public:
   // default constructor
   TAXRATE() {}
   void setZipCode(int i) { zipcode = i; }
   void setTaxRate(float f) { taxrate = f; }
   void setUSPSRate(float f) { USPSrate = f; }
   void setUPSRate(float f) { USPrate = f; }
   void setFedexRate(float f) { FedexRate = f; }

   int getZipCode() { return(zipcode); }
   float getTaxRate() { return(taxrate); }
   float getUSPSRate() { return(USPSrate); }
   float getUPSRate() { return(USPrate); }
   float getFedexRate() { return(FedexRate); }
};

vector<TAXRATE> taxList;// contail all tax list


struct CART {
   string Prd;
   string dec;
   float Price;
   float Qnty;
   int weight;
};


// load from file
void loadFromFile(string s) {
   ifstream out(s.c_str());
  
   int a;
   float b, c, d, e;

   bool type = false;
   string tmp;

   while (!out.eof()) {
       type = false;
       out >> tmp;
       a = stoi(tmp);// string to int
       if (a < 10000) { type = true; }
      

       out >> b;
       if (b > .1 || b<0) { type = true; }
      
      
       out >> c;
       if (c <0) { type = true; }
      
      
       out >> d;
       cout << d << " | ";
       if (d <0) { type = true; }
      
      
       out >> e;
       if (e <0) { type = true; }

       // if any error skip to load
       // type = true mean error
       if (type == false) {
          
           TAXRATE tr;
           tr.setZipCode(a);
           tr.setTaxRate(b);
           tr.setUSPSRate(c);
           tr.setUPSRate(d);
           tr.setFedexRate(e);

           taxList.push_back(tr);
       }
   }

   out.close();
  
}

// memu list
int displayMenu() {
   int ret = 0;
  
   while (true) {
       system("cls");
       cout << "Hot Tub Time Machine Parts and Supplies";
       cout << "\n 1) Create Customer Account";
       cout << "\n 2) Shop for Items";
       cout << "\n 3) Proceed to Check Out";
       cout << "\n 4) Exit Store";
       cout << "\n User Choice : ";

       int i;

       cin >> i;
       if (i >= 1 && i <= 4) {
           ret = i;
           break;
       }
   }
   return(ret);
}

// customer name

void createCustomer(string &a,string &b,string &c,int &d) {
  
   cout << "\nName : "; cin >> a;
   cout << "\nAddress : "; cin >> b;
   cout << "\nCity : "; cin >> c;
   cout << "\nZIPCODE : "; cin >> d;
}


void maintainCart(CART *carts) {
  
   // cart list display for choose
   while (true) {
       cout << "\n 1) "<<carts[0].Prd<<" {$" << carts[0].Price << "}";
       cout << "\n 2) " << carts[1].Prd << " {$" << carts[1].Price << "}";
       cout << "\n 3) " << carts[2].Prd << " {$" << carts[2].Price << "}";
       cout << "\n 4) " << carts[3].Prd << " {$" << carts[3].Price << "}";
       cout << "\n 5) " << carts[4].Prd << " {$" << carts[4].Price << "}";
       cout << "\n 6) " << carts[5].Prd << " {$" << carts[5].Price << "}";
       cout << "\n Your choice : ";

       int i;
       cin >> i;
       if (i >= 1 && i <= 6) {

           cout << "\nEnter qualtity : ";
           float qty;
           cin >> qty;
           // add quantiti
           carts[i-1].Qnty = qty;
           break;
       }
      
   }  
}


float priceAndQuantity(float a,float b) {
   return(a*b);
}

// calculate shipping
float calculateShipping(int zip, CART *a) {
   float ret = 0;

   while (true) {
       cout << "\n Choose shipping method";
       cout << "\n 1) USPS";
       cout << "\n 2) UPS";
       cout << "\n 3) FEDES";
       cout << "\n User choice :";
       int i;
       cin >> i;
      
       if (i == 1) {
           for (int a = 0; a < taxList.size(); a++) {
               if (taxList.at(a).getZipCode() == zip) {
                   ret = taxList.at(a).getUPSRate();
                   break;
               }
           }
           break;
       }
       if (i == 2) {
           for (int a = 0; a < taxList.size(); a++) {
               if (taxList.at(a).getZipCode() == zip) {
                   ret = taxList.at(a).getUSPSRate();
                   break;
               }
           }

           break;
       }
       if (i == 3) {
           for (int a = 0; a < taxList.size(); a++) {
               if (taxList.at(a).getZipCode() == zip) {
                   ret = taxList.at(a).getFedexRate();
                   break;
               }
           }
           break;
       }
   }

   int sum = 0;
   for (int x = 0; x < 6; x++) {
       sum += a[x].weight;
   }

   if (sum < 10){ret = ret;}
   if (sum >10 && sum<=50) { ret = 5*ret; }
   if (sum > 50) { ret = 10*ret; }

   return(ret*sum);
}

// calculate tax
float calculateTax(int zip,int subtotal) {
   float ret = 0;

   for (int a = 0; a < taxList.size(); a++) {
       if (taxList.at(a).getZipCode() == zip) {
           ret = taxList.at(a).getTaxRate();
           break;
       }
   }
   return(ret*subtotal);
}

// calculate total
float calculateTotal(float a,float b,float c) {
   return(a+b+c);
}

// receipt
void displayReceipt(int zip,CART *a,float &x,float &y,float &z) {
   float sum = 0;

   for (int i = 0; i < 6; i++) {
       if (a[i].Qnty != 0) {
           cout << "\n" << a[i].Prd << " [ unit price : $" << a[i].Price << " , Quantity : " << a[i].Qnty << " ] $" << priceAndQuantity(a[i].Price, a[i].Qnty);
           sum += priceAndQuantity(a[i].Price, a[i].Qnty);
       }
   }
   float czip = calculateShipping(zip,a);
   cout << "\nShipping Cost : $" << czip;
   float tzip = calculateTax(zip, sum);
   cout << "\nTax : $" << tzip;
   cout << "\nTotal Cost : $" << calculateTotal(sum, tzip, czip);
   x = sum;
   y = czip;
   z = tzip;
}

// check out
void checkOut(int zipcode, CART *a) {

   if (zipcode == 0) {
       while (true) {
           cout << "\nEnter zipcode : ";
           int zip;
           cin >> zip;
           if (zip >= 10000) {
               break;
           }
       }
   }

   float x, y, z;

   displayReceipt(zipcode,a,x,y,z);

   ofstream out("invoice.txt");

   out << x;
   out << endl;
   out << y;
   out << endl;
   out << z;
   out << endl;
   out << calculateTotal(x,y,z);

   out.close();
}

int main() {
  
   string Customer_name;
   string address;
   string city;
   int zipcode;

   CART carts[6];


   // each cart details

   carts[0].Prd = "Product A";
   carts[1].Prd = "Product B";
   carts[2].Prd = "Product C";
   carts[3].Prd = "Product D";
   carts[4].Prd = "Product E";
   carts[5].Prd = "Product F";

   carts[0].dec = "Description A";
   carts[1].dec = "Description B";
   carts[2].dec = "Description C";
   carts[3].dec = "Description D";
   carts[4].dec = "Description E";
   carts[5].dec = "Description F";

   carts[0].Price = 345.50;
   carts[1].Price = 200.50;
   carts[2].Price = 634.30;
   carts[3].Price = 123.00;
   carts[4].Price = 698.60;
   carts[5].Price = 583.80;

   carts[0].Qnty = 0;
   carts[1].Qnty = 0;
   carts[2].Qnty = 0;
   carts[3].Qnty = 0;
   carts[4].Qnty = 0;
   carts[5].Qnty = 0;

   carts[0].weight = 4;
   carts[1].weight = 5;
   carts[2].weight = 3;
   carts[3].weight = 1;
   carts[4].weight = 4;
   carts[5].weight = 1;
  

   cout << "Enter file name : ";
   string file;
   cin >> file;
   loadFromFile(file);

   cout << "\nData loaded";

   for (;;) {
       int ret = displayMenu();

       if(ret==1){
           createCustomer(Customer_name, address, city, zipcode);
       }
       if(ret==2){
           maintainCart(carts);
       }
       if(ret==3){
           checkOut(zipcode, carts);
           break;
       }
       if (ret == 4) {
           break;
       }
   }
  
   cout << endl;

   system("pause");

   return(0);
}


Related Solutions

Assignment - Store Design and code a HTML/CSS/JS based web application for your online store. Assignment...
Assignment - Store Design and code a HTML/CSS/JS based web application for your online store. Assignment Specification · Minimum of SIX web pages are required for this assignment: § One Landing/Container Page ( a page with logo) § One Home Page § Three or more Product Line Pages (pages with product and it information ) § One Order Page (for customer to order a product after view the profuct on the product page) · Build internal CSS style sheets in...
Writing Assignment for Managerial Accounting Introduction: Having the ability to effectively communicate is one of the...
Writing Assignment for Managerial Accounting Introduction: Having the ability to effectively communicate is one of the most important skills a business executive can possess. As French businesswoman and author Mirelle Guilliano has said, “Intelligence, knowledge or experience are important and might get you a job, but strong communication skills are what will get you promoted.” My own business experience supports this statement. By the time individuals have a few years of experience, they have great technical skills and can assemble,...
Write the introduction for the car showroom project?
Write the introduction for the car showroom project?
Write a C program that will read different data types from the following file and store...
Write a C program that will read different data types from the following file and store it in the array of structures. Given file: (This file have more than 1000 lines of similar data): time latitude longitude depth mag magType nst gap dmin 2020-10-19T23:28:33.400Z 61.342 -147.3997 12.3 1.6 ml 12 84 0.00021 2020-10-19T23:26:49.460Z 38.838501 -122.82684 1.54 0.57 md 11 81 0.006757 2020-10-19T23:17:28.720Z 35.0501667 -117.6545 0.29 1.51 ml 17 77 0.1205 2020-10-19T22:47:44.770Z 38.187 -117.7385 10.8 1.5 ml 15 100.22 0.049 2020-10-19T22:42:26.224Z...
JAVA Assignment: Project File Processing. Write a program that will read in from input file one...
JAVA Assignment: Project File Processing. Write a program that will read in from input file one line at a time until end of file and output the number of words in the line and the number of occurrences of each letter. Define a word to be any string of letters that is delimited at each end by either whitespace, a period, a comma or the beginning or end of the line. You can assume that the input consists entirely of...
Frederick Douglass believed that knowledge, and the ability to read and write in particular, was the...
Frederick Douglass believed that knowledge, and the ability to read and write in particular, was the pathway from slavery to freedom. First, I'd like you to discuss the varying ways that Douglass uses this tool over the course of his lifetime to help slaves gain their freedom. Then, explain whether or not you agree with this assessment of Douglass given in the film that he was "an important figure in the coming of the civil war and in the way...
This assignment is about creating a online movie rental store. Use arrays and loops for this...
This assignment is about creating a online movie rental store. Use arrays and loops for this assignment. 1) Create a web page containing a list of movie names available for rent (at least 10 movies), so that each time you visit the home page, you see a different order of movies in the list. The movie names are required, all other information is optional.) 2) The rental price for each movie ranges between $1.99 to $7.99.             • Create an...
introduction: C PROGRAMMING For this assignment you will write an encoder and a decoder for a...
introduction: C PROGRAMMING For this assignment you will write an encoder and a decoder for a modified "book cipher." A book cipher uses a document or book as the cipher key, and the cipher itself uses numbers that reference the words within the text. For example, one of the Beale ciphers used an edition of The Declaration of Independence as the cipher key. The cipher you will write will use a pair of numbers corresponding to each letter in the...
PURPOSE The purpose of this assignment is to develop learners’ ability to analyse data and discuss...
PURPOSE The purpose of this assignment is to develop learners’ ability to analyse data and discuss the differences between the types of statistics. REQUIREMENT The following data represent the marks of the Statistic subject obtained by 25 students in mid semester examination. Use this data to answer the following questions: 1 2 4 4 5 6 7 9 9 12 5 12 15 17 20 21 23 23 25 26 27 27 28 29 29 Based on the information from...
1. INTRODUCTION The goal of this programming assignment is for students to write a Python program...
1. INTRODUCTION The goal of this programming assignment is for students to write a Python program that uses repetition (i.e. “loops”) and decision structures to solve a problem. 2. PROBLEM DEFINITION  Write a Python program that performs simple math operations. It will present the user with a menu and prompt the user for an option to be selected, such as: (1) addition (2) subtraction (3) multiplication (4) division (5) quit Please select an option (1 – 5) from the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT