Pointers

Can someone explain how I would complete this:
For the quantities, use a pointer to the first item of an array of int. An example of the declaration code may look like the following:
int * numbers;
numbers = new int [n];
For the products, use an array of pointers to strings, and dynamically allocate space for each of the strings. An example of the declaration code may look like the following:
char Temp[100]; // to hold the entry
char * products [100]; // to hold the products
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. The following code is provided as an example:
cin >> Temp; // to get the product
int len = strlen(Temp) +1 ; // to determine the length of the product name
char* newProduct = new char[len]; // to allocate memory
strcpy(newProduct, Temp); // to copy the entry to a new product
products[0] = newProduct; // to save in the array
Use the previous structure to provide the same functionality that was provided in Week 4.
By the end of Week 5, your application should work as follows:
Ask the customer to enter his or her details (e.g., name and address).
Print a welcome message that includes the customer’s name.
Provide a list of available products with descriptions.
Ask the customer to select products and quantities.
Save the provided details in the new data structure.
Read from the arrays to print the order summary (e.g., the products, quantities, and total price for each product).
Calculate and print total price for the order.
Release the allocated memory.
Add comments to your code.


Using this code that I currently have?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
int main()
{

	customer_info cust = WelcomeCustomer();
	int final;
	final = 0; // setting values to final and brands
	int type[6] = { 55, 60, 90, 80, 100, 100 }; // array for shoe type prices
	int quantity[6]; // creating array for the summary
	int size[6]; // creating an array for size
	char input[6]; //creating array for inputs
	int total[6]; //creating array for total


	cout << "Nike Running Shoes, sizes 8-13, blue/grey, $60" << endl;
	cout << "Skechers Shape ups, Women's sizes 3-10, pink/green, $55" << endl; // two different athletic shoe options
	cout << "Reebok Track shoes with .5 inch spikes, sizes 8-13, red/white/silver, $90" << endl;
	cout << "Adidas Long Distance Track shoes with .25 inch spikes, sizes 8-13, green/gold, $80" << endl; // two different track shoe options
	cout << "Vans, sizes 8-13, white, $100" << endl;
	cout << "Converse, sizes 8-13, black/white, $100" << endl; // two different casual shoe options

	cout << "Do you want Nike Running Shoes? Y/N" << endl; // asks user about each type of shoe
	cin >> input[0];
	if (input[0] == 'Y') { // if the answer is yes (Y), the function asks the user how many and what size the user wants
		cout << "How many pair do you want? Enter a number:" << endl;
		cin >> quantity[0];
		cout << "What size do you want? Enter a number:" << endl;
		cin >> size[0];
	} // if the answer is no (N), the function moves on to the next type of shoe
	cout << "Do you want Skechers Shape ups? Y/N" << endl;
	cin >> input[1];
	if (input[1] == 'Y') {
		cout << "How many pair do you want? Enter a number:" << endl;
		cin >> quantity[1];
		cout << "What size do you want? Enter a number:" << endl;
		cin >> size[1];
	}
	cout << "Do you want Reebok Track shoes? Y/N" << endl;
	cin >> input[2];
	if (input[2] == 'Y') {
		cout << "How many pair do you want? Enter a number:" << endl;
		cin >> quantity[2];
		cout << "What size do you want? Enter a number:" << endl;
		cin >> size[2];
	}
	cout << "Do you want Adidas Long Distance Track shoes? Y/N" << endl;
	cin >> input[3];
	if (input[3] == 'Y') {
		cout << "How many pair do you want? Enter a number:" << endl;
		cin >> quantity[3];
		cout << "What size do you want? Enter a number:" << endl;
		cin >> size[3];
	}
	cout << "Do you want Vans? Y/N" << endl;
	cin >> input[4];
	if (input[4] == 'Y') {
		cout << "How many pair do you want? Enter a number:" << endl;
		cin >> quantity[4];
		cout << "What size do you want? Enter a number:" << endl;
		cin >> size[4];
	}
	cout << "Do you want Converse? Y/N" << endl;
	cin >> input[5];
	if (input[5] == 'Y') {
		cout << "How many pair do you want? Enter a number:" << endl;
		cin >> quantity[5];
		cout << "What size do you want? Enter a number:" << endl;
		cin >> size[5];
	}
	
	cout << "You are ordering:" << endl; // the function is creating an order summary based on whether or not the user replied yes to wanting a type of shoe
	if (input[0] == 'Y') {
		total[0] = quantity[0] * type[0];
		cout << quantity[0] << " Pair of Nike Running shoes, size " << size[0] << " for $" << total[0] << endl;
	} // if the user did not want a type of shoe, the type is skipped and the function moves on to the next shoe
	if (input[1] == 'Y') {
		total[1] = quantity[1] * type[1];
		cout << quantity[1] << " Pair of Skechers Shape ups, size " << size[1] << " for $" << total[1] << endl;
	}
	if (input[2] == 'Y') {
		total[2] = quantity[2] * type[2];
		cout << quantity[2] << " Pair of Reebok Track shoes, size " << size[2] << " for $" << total[2] << endl;
	}
	if (input[3] == 'Y') {
		total[3] = quantity[3] * type[3];
		cout << quantity[3] << " Pair of Adidas Long Distance Track Shoes, size " << size[3] << " for $" << total[3] << endl;
	}
	if (input[4] == 'Y') {
		total[4] = quantity[4] * type[4];
		cout << quantity[4] << " Pair of Vans, size " << size[4] << " for $" << total[4] << endl;
	}
	if (input[5] == 'Y') {
		total[5] = quantity[5] * type[5];
		cout << quantity[5] << " Pair of Converse, size " << size[5] << " for $" << total[5] << endl;
	}

	if (input[0] == 'Y') { // the function is putting together a total, based on whether the user wanted the shoe or not
		final = final + total[0];
	} // if the user did not want the shoe it is skipped in the total, that way total(variable) does not have to be initialized if it is never used
	if (input[1] == 'Y') {
		final = final + total[1];
	}
	if (input[2] == 'Y') {
		final = final + total[2];
	}
	if (input[3] == 'Y') {
		final = final + total[3];
	}
	if (input[4] == 'Y') {
		final = final + total[4];
	}
	if (input[5] == 'Y') {
		final = final + total[5];
	} // after the total is finished being calculated the program sends the final message, including the total cost of the shoes
	cout << "Your total purchase today is $" << final << ". Thank you for shopping with us, " << cust.firstname << " " << cust.lastname << ". Your shoes will be shipped in 3-5 business days." << endl;
	return 0;
}
Hi,

If you need any help, email me at sparkprogrammer@gmail.com

Joe
Topic archived. No new replies allowed.