0

This is what I'm suppose to do:

"Create a while loop to read in the corporate sales data from the pgm3.dat file and create a report listing data for each division as well as some of the summary data described in Programming Challenge 12 in the textbook. Inside the loop, for each set of division data read in:
a. Call a function named getDivision to read in the data for one division. Pass the Division pointer to this function to store the data in the memory locations allocated for the struct. Return this pointer to the main program.
b. Call a function named printDivision to write a line to the report file to display the division name, four quarterly sales amounts and the total sales for the year for that division. Pass the pointer to the division structure to this function.
c. Call a function named addDivision to add this divisions sales amounts to the corporate sales amounts. Pass the pointer of both the division and corporate structures to this function."

Other then the fact that I'm completely lost and don't know what it's asking for; my biggest problem at the moment is how do I pass the pointer into the function when the pointer is pointing to a struct?

Thanks, SSR

1 #include <iostream>
2 #include <string>
3 #include <iomanip>
4 #include <cmath>
5 
6 using namespace std;
7
8 struct Division
9 {
10     string name;
11     double qs1;
12     double qs2;
13     double qs3;
14     double qs4;
15
16
17     Division(string n = "East", double q=100, double u =200, 
18 double a=300, double r = 400)
19        {
20        name = n;
21        qs1 = q;
22        qs2 = u;
23        qs3 = a;
24        qs4 = r;
25        }
26 };
27
28 struct Corporation
29 {
30     double tqs1;
31     double tqs2;
32     double tqs3;
33     double tqs4;
34     int numDiv;
35
36
37     Corporation(double t=500, double e =600, double s =700, 
38 double l = 800, int n =4)
39        {
40        tqs1 = t;
41        tqs2 = e;
42        tqs3 = s;
43        tqs4 = l;
44        numDiv = n;
45        }
46 };
47
48 int getDivision(int);
49 int printDivision(int);
50 void addDivision(int, int);
51 
52 int main()
53 {
54
55 int num = 0;
56
57 //Pointers
58 Division *ptrDiv = new Division;
59 Corporation *ptrCor = new Corporation;
60
61 while(num <5)
62 {
63 //Function calls
64 getDivision(*ptrDiv);
65 printDivision(*ptrDiv);
66 addDivision(*ptrDiv, *ptrCor);
67 num++;
68 }
69 
70   return 0;
71 }
72 
73//**************************************************
74//                          getDivision
75
76//**************************************************
77
78 int getDivision(Division *ptrDiv)
79 {
80    for (int a=0; a<6; a++)
81    {
82     getline(cin,  ptrDiv->name);
83    cin >> ptrDiv->qs1;
84    cin >> ptrDiv->qs2;
85    cin >> ptrDiv->qs3;
86    cin >> ptrDiv->qs4;
87    }
88 return ptrDiv;
89 }
90
91 //*************************************************
92 //                          printDivision
93 //**************************************************
94 int printDivision(Division *ptrDiv)
95     {
96     cout <<"        National Corporation Sales Report"<<endl;
97     cout <<"                    Your Name"<<endl;
98     cout <<"Division     Qtr1    Qtr2    Qtr3    Qtr4     Year" ;
99     cout <<"Total"<<endl;
100     for (int a=0; a<6; a++)
101          {
102          cout<<ptrDiv->name;
103          cout<<"   ";
104          cout<< ptrDiv->qs1;
105          cout<<"   ";
106          cout<< ptrDiv->qs2;
107          cout<<"   ";
108          cout << ptrDiv->qs3;
109          cout<<"   ";
110          cout << ptrDiv->qs4;
111
112          }
113      return ptrDiv;
114
115 }
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Ancient Dragon
0

>>my biggest problem at the moment is how do I pass the pointer into the function when the pointer is pointing to a struct?

Do it the same as you would do with any other data object, such as a pointer to an int

void foo( Divison* pDiv)
{
  // blabla
}

int main()
{
    Division d;
    foo( &d );
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.