Question: I need some help with my school project for my C++ class. I can't seem to wrap my head around pointers, and the curriculum isn't
I need some help with my school project for my C++ class. I can't seem to wrap my head around pointers, and the curriculum isn't that great at explaining. Here is the assignment details: *********
1. For the quantities, use a pointer to the first item of an array of int.
2. For the products, use an array of pointers to strings, and dynamically allocate space for each of the strings. To fill in the products array, read one product name from the user, check the length, and then allocate memory based on the length of the entered word.
********** Here is my code so far :
#include
#include
#include
#include
#include "customerclass.h"
using namespace std;
//****** Start of my CustomerInfo Class
#pragma once
#include using namespace std;
class CustomerInfo {
private: string custName;
string custAddress;
public:
CustomerInfo(string name, string userAddress) : custName(name), custAddress(userAddress) {}
void setName(string);
void setAddress(string);
string getName();
string getAddress();
CustomerInfo();
};
// Defining setName
void CustomerInfo::setName(string name) { custName = name; }
// Defining setAddress
void CustomerInfo::setAddress(string userAddress) {
custAddress = userAddress;
}
// Defining getName
string CustomerInfo::getName() { return custName;
}
// Defining getAddress
string CustomerInfo::getAddress() { return custAddress;
}
inline CustomerInfo::CustomerInfo() { }
// ****** End of my CustomerInfo class
//***** Functions to calculate the price of multiple items *****
void finalPrice(int itemQuantity[]) {
float price; for (int i = 0; i < 3; i++) {
price = itemQuantity[i] * 3.00, itemQuantity[i] * 2.5, itemQuantity[i] * 1.25;
}
cout << "Your total is $" << price << endl; cout << "Thank you for using my shop" << endl; exit(0);
} //***** End of functions that calculate price of multiple items *****
int main(void) {
char selection = ' ';
string lname = "";
string luserAddress;
int totalItemQuantity[3];
string arrayProducts[3];
int itemQuantity;
string orderFinalized;
cout << "Hello, welcome to my online shop! What is your name? " << endl;
cin >> lname;
cout << " And what is your shipping address? " << endl;
cin >> luserAddress;
cout << lname + ", nice to meet you. Here is a list of my products. Enter the number that corresponds to the item you want to purchase." << endl;
do {
// Displaying menu
cout << "Products ";
cout << "1 - Chocolate candy bar - $3.00" << endl;
cout << "2 - Sour hard candy - $2.50" << endl;
cout << "3 - Mints - $1.25" << endl;
cout << "4 - Exit" << endl << endl;
cout << "Enter selection ";
// Reading User Selection
cin >> selection; switch (selection) {
case '1': cout << "You've chosen a Chocolate candy bar. How many would you like? ";
cin >> itemQuantity;
cout << "Ok, will this finalize your order? Type and enter either 'Yes' or 'No' " << endl;
cin >> orderFinalized;
if (orderFinalized == "Yes" || orderFinalized == "yes" || orderFinalized == "YES") {
cout << lname + " your items will be shipped to " << luserAddress << endl;
cout << "Printing your receipt now..." << endl;
totalItemQuantity[0] += itemQuantity;
cout << finalPrice;
//finalPrice1(itemQuantity,3.00);
}
break;
case '2':
cout << "You've chosen Sour hard candy. How many would you like? ";
cin >> itemQuantity;
cout << "Ok, will this finalize your order? Type and enter either 'Yes' or 'No' " << endl;
cin >> orderFinalized; if (orderFinalized == "Yes" || orderFinalized == "yes" || orderFinalized == "YES") {
cout << lname + " your items will be shipped to " << luserAddress << endl;
cout << "Printing your receipt now..." << endl;
totalItemQuantity[1] += itemQuantity; //finalPrice2(itemQuantity);
}
break;
case '3':
cout << "You've chosen Mints. How many would you like? ";
cin >> itemQuantity;
cout << "Ok, will this finalize your order? Type and enter either 'Yes' or 'No' " << endl;
cin >> orderFinalized;
if (orderFinalized == "Yes" || orderFinalized == "yes" || orderFinalized == "YES") {
cout << lname + " your items will be shipped to " << luserAddress << endl;
cout << "Printing your receipt now..." << endl;
totalItemQuantity[2] += itemQuantity;
//finalPrice3(itemQuantity);
}
break;
case '4': cout << "Thank you for using my shop. " << endl;
break;
default:
cout << "Invalid selection. Please try again"; } cout << endl << endl;
}
while (selection != '4');
finalPrice(totalItemQuantity);
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
