1D Arrays program

Hey everyone I'm having trouble getting this program to compile and Im trying to figure out the last function can anyone give me a hand..??

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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
Sample Output:

*** start of 27610_Arrays04.cpp program ***

City             City Points
Belvidere        **********
Freeport         ********
Byron            ************
Stillman Valley  ***************
Rockford         *********

*** end of 27610_Arrays04.cpp program ***


Input:
   TODO #1: complete the coding of the points array
            An integer array of 5 numbers: 10, 8, 12, 15, 9

   TODO #2: complete the coding of the cities string array
      An string of 5 city names intialized to:
      "Belvidere", "Freeport", "Byron", "Stillman Valley", "Rockford"

      Compile-time arrays with initialization lists.


Processing & Output:
   TODO #3: complete the coding of the call to the printStars() function

   TODO #4: code the printStars() function

*/


#include <iostream>
#include <iomanip>
#include <string>
using namespace std;


int main(void)
{
   /* declarations ------------------------------------------------*/
   
   
   // constants
   const int SIZE = 5;

   // function prototype(s)
   // return by value is used
   void printStars(const int [], const string [], const int);

   // local data (other than arrays)

   // TODO #1: complete the coding of the points array
   //   replace ?? with the correct initialization list
   //    each array cell will store the number of stars for the
   //    corresponding city in the cities array below
    
   // STUDENT CODE BEGINS
   
   int points[SIZE] = {10, 8, 12, 15, 9};
   
   // STUDENT CODE ENDS                          ,




    // TODO #2: complete the coding of the cities string array

   // STUDENT CODE BEGINS
    string cities[SIZE] = {
                              "Belvidere",
                              "Freeport",
                              "Byron",
                              "Stillman Valley",
                              "Rockford"
                    



                          ,
                          };
   // STUDENT CODE ENDS                          
                          



   /* statements   ------------------------------------------------*/

    // start the program
    cout << "*** start of 276Arrays_Ex04.cpp program ***" << endl;
    cout << endl;



   // TODO #3: call display function, passing count array & size
   //   replace the three underlines with the correct parameters
   // STUDENT CODE BEGINS


   printStars(SIZE, string, SIZE);



   // STUDENT CODE ENDS    


   // terminate the program
   cout << endl;
   cout << "*** end of 276Arrays_Ex04.cpp program ***" << endl << endl;
   cin.get();

   return 0;
}   // end main()





/*--------------------------------------------------------------------//
// Function Name: printStars()
// Parameters:    points : const int[],
//                cities : const string[], 
//                SIZE   : const int
// Return:        void
//
// Purpose: to display cities and their points in a graph
//--------------------------------------------------------------------//
// TODO #4: code the display function
// Suggested Algorithm 

declare local variables (if needed)


Print row 1 of column headings (City             City Points)
Print row 2 of column headings (---------------  1---5----10---15---20)

// print one line for each iteration of the for loop
for each city in the cities array
   print the name of a city
   
   // print one star for each iteration of the for loop
   for the value for that city in the points array
      print a star
   end for loop
   move cursor to next line
End outer loop
move cursor to next line

*/

// STUDENT CODE BEGINS






// STUDENT CODE ENDS
1
2
3
4
5
6
7
8
   string cities[SIZE] = {
                              "Belvidere",
                              "Freeport",
                              "Byron",
                              "Stillman Valley",
                              "Rockford"
                           ,                        //<<<<TO BE DELETED>>>>
                          };


 
   printStars(SIZE, string, SIZE);

This was not implemented, so it would throw a compilation error. Also, you have to send as parameters (int[..], string, int), not (int, string, int).

Regarding the implementation of the function printStars, I didn't understand what exactly should the function do. Sorry, not a native english speeker :(.

rgds






So this is what my updated code looks like.., but can anyone help me with finishing up my for loop and printing the stars..?? I kinda have no idea how I could go about doing that on this program.../:

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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;


int main(void)
{
   /* declarations ------------------------------------------------*/
   
   
   // constants
   const int SIZE = 5;
   const int points = 0;

   // function prototype(s)
   // return by value is used
   void printStars(const int [], const string [], const int);

   // local data (other than arrays)

   // TODO #1: complete the coding of the points array
   //   replace ?? with the correct initialization list
   //    each array cell will store the number of stars for the
   //    corresponding city in the cities array below
    
   // STUDENT CODE BEGINS
   
   int points[SIZE] = {10, 8, 12, 15, 9};
   
   // STUDENT CODE ENDS                          ,




    // TODO #2: complete the coding of the cities string array

   // STUDENT CODE BEGINS
    string cities[SIZE] = {"Belvidere", "Freeport", "Byron", "Stillman Valley", "Rockford"};
   
    // STUDENT CODE ENDS                          
                          



   /* statements   ------------------------------------------------*/

    // start the program
    cout << "*** start of 276Arrays_Ex04.cpp program ***" << endl;
    cout << endl;



   // TODO #3: call display function, passing count array & size
   //   replace the three underlines with the correct parameters
   // STUDENT CODE BEGINS


   printStars(points, cities, SIZE);



   // STUDENT CODE ENDS    


   // terminate the program
   cout << endl;
   cout << "*** end of 276Arrays_Ex04.cpp program ***" << endl << endl;
   cin.get();

   return 0;
}   // end main()





/*--------------------------------------------------------------------//
// Function Name: printStars()
// Parameters:    points : const int[],
//                cities : const string[], 
//                SIZE   : const int
// Return:        void
//
// Purpose: to display cities and their points in a graph
//--------------------------------------------------------------------//
// TODO #4: code the display function
// Suggested Algorithm 

declare local variables (if needed)


Print row 1 of column headings (City             City Points)
Print row 2 of column headings (---------------  1---5----10---15---20)

// print one line for each iteration of the for loop
for each city in the cities array
   print the name of a city
   
   // print one star for each iteration of the for loop
   for the value for that city in the points array
      print a star
   end for loop
   move cursor to next line
End outer loop
move cursor to next line

*/

// STUDENT CODE BEGINS

void printStars(const int points [], const string cities [], const int SIZE)
{
   //declare variables
   int city = 0;
   int citypoints = 0;

   //column headings

   cout << "City";
   cout << " ";
   cout << "City Points";
   cout << " ";
   cout << endl;
   cout << "---------------";
   cout << "1---5----10---15---20";




// STUDENT CODE ENDS 


These are the 2 errors im getting as of now:

Error 1 error C2373: 'points' : redefinition; different type modifiers c:\users\ric\desktop\cis276\27610_arrays-1d\u10_arrayslab\u10_arrays04.cpp 83 1 U10_Arrays04
Error 2 error C1075: end of file found before the left brace '{' at 'c:\users\ric\desktop\cis276\27610_arrays-1d\u10_arrayslab\u10_arrays04.cpp(167)' was matched c:\users\ric\desktop\cis276\27610_arrays-1d\u10_arrayslab\u10_arrays04.cpp 187 1 U10_Arrays04
You've defined points twice (line 14 and 29). Once as a const int and once as an array. Which is it? It can't be both.

You're missing a } at line 127.

Topic archived. No new replies allowed.