Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

18. Assume the declarations of the previous exercise. Write C++ statements that

ID: 2246387 • Letter: 1

Question

18. Assume the declarations of the previous exercise. Write C++ statements that do the following:

a. Store the following information in cs_course. Do not redeclare cs_course.

name: the string literal "Programming I" (hint: you cannot use ‘=’ to overwrite the previous value for the name member because c-strings are really character arrays and you cannot assign one array to another, so you must use a c-string function instead)

callNum : 40101

credits : 4

grade : 'A'

b. In the classList array initialize each id to 0.

c. Copy the first component of the array classList into cs_student.

d. Update the id of the last student in the array classList by adding 1000000 to its previous value.

19. Assume that you have the following definition of a struct:

  struct partType

  {

     string partName;

     int partNum;

     float price;

     int quantitiesInStock;

  };

Declare an array, inventory, of 100 components of type partType.

20. Assume the definition from the previous exercise:

a. Write C++ code that initializes each component of inventory as follows: partName to "?", partNum to 0, price to -1.0, and quantitiesInStock to 0.

b. Write C++ code that uses a loop to output the members of each element of inventory, with each member separated by a space character and each partType on its own line. Assume that the variable length indicates the number of elements in inventory which might be much less than 100.

Explanation / Answer

20) a.

#include <iostream> //Declares IO Stream
2.using namespace std; //Declares Namespace
3.
4.for (int i = 0; i < 100; i++) //Declares Counter
5.
6. {
7.
8. inventory[i].partName = ""; //Sets partName = to part
9.
10. inventory[i].partNum = -1; //Sets partNum counter = -1
11.
12. inventory[i].price = 0.0; //Sets price = 0.0
13.
14. inventory[i].quantitiesInStock = 0; //Sets counter for quantity to zero.
15.
16. }
17. for (int i = 0; i < length; i++)
18.
19. {
20.
21. cout << inventory[i].partName << endl; //Output for Part Number
22.
23. cout << inventory[i].partNum << endl; //Output for Part Number
24.
25. cout << inventory[i].price << endl; //Output for Price
26.
27. cout << inventory[i].quantitiesInStock << endl; //Output for quantities
28.
29. }
30. system "pause";
31. return 0;

b.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote