Doing homework for a class I'm not enrolled in

Hello! I'm trying to learn C++ by having my friend in class send me his homework and me just doing it on my own, I've been able to keep up until now, I have no idea how to do this:

https://imgur.com/a/qykyQ

I know what a structure/class is, I know arrays, but I just don't understand what the assignment wants me to do, it's written in such a complicated way.

I'm not asking for the solution, just some guidance on where to even begin, or some hints on how to solve it.

Thank you!
Can you do the first 4 things? Show your code. What about the 5th one (the 2D array and initializing it)?
Heres the code I wrote so far

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
#include <iostream>
#include <string>

enum Section
{
    ORCHESTRA,
    FRONT,
    MIDDLE,
    BACK,
    double const cdaPrice[3] = {150,100,75,50}

};

struct Date
{
public:
    int iDay, iMonth, iYear;

};

struct Seat
{
public:
    char cRow;
    int iColumn;
    Section SeatPrice;
    bool bAssigned;
    std::string sName;
    Date Day;
};


int main()
{


    return 0;
}


I did something wrong with the const double, the compiler is getting confused at that part.
Last edited on
You need a semi-colon at the end of line 10. But you also have only allocated an array of size 3, yet you are trying to give it 4 elements. Replace the 3 with a 4.

You can created a 2-dimensional array like so:

Seat seats[26][50];

To learn about functions, I suggest the tutorial on the site
http://www.cplusplus.com/doc/tutorial/functions/

However, arrays can be annoying to pass, it's a bit unintuitive, so here's an example of passing a 2D array:
1
2
3
4
5
6
7
8
9
10
11
void func(int arr[][50])
{
    arr[5][10] = 42;
}

int main()
{
  int arr[26][50];
  
  func(arr);
}


You can also add named constants to keep track of what those numbers actually mean:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

const int NumColumns = 50;
const int NumRows = 26;

void func(int arr[][NumColumns])
{
    
}

int main()
{
  int arr[NumRows][NumColumns];
  
  func(arr);
}
Last edited on
Is that so? I thought arrays were counted from 0, so 4 elements means it should be 3?

Adding the semicolon did not fix the error. I thought they all had to end with a comma?

I know how to use functions and declare arrays, I just don't understand what the assignment wants me to do,


and 2) how I can pass an array of the Seat Structure to a function? It's obviously not the same way as passing a regular array of like ints or something.

all help appreciated, thanks
See my edit for passing a 2d array.

Yes, indices start at 0. But the declared size itself is still its size.
An array of size 5 has indices 0 to 4. Hope that makes sense.
1
2
3
int arr[5] = {2, 4, 5, 8, 9};
// arr[0] is 2
// arr[4] is 9 


Adding the semicolon did not fix the error.

So, change
double const cdaPrice[3] = {150,100,75,50}
to
double const cdaPrice[4] = {150,100,75,50};

EDIT:
I didn't notice you had your array declaration inside an enum. Move the declaration of your cdaPrice array to outside of the enum declaration.
Last edited on
EDIT: Nevermind, I'm doing good at the moment, thanks for all your help! I will post if I do something wrong again.
Last edited on
closed account (E0p9LyTq)
'A' is not 0 + 17, it is ASCII code 65.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>

int main()
{
   for (char loop = 'A'; loop <= 'Z'; loop++)
   {
      std::cout << loop << ' ';
   }
   std::cout << "\n\n";

   for (char loop = 'A'; loop <= 'Z'; loop++)
   {
      int num = loop - 65;
      std::cout << num << ' ';
   }
   std::cout << '\n';
}

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

0 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

Last edited on
Try it simplified and find out
1
2
3
4
5
6
7
8
9
10
11
12
$ cat ascii.cpp
#include <iostream>
using std::cout;

int main(){

        int iY=0, val=0;
        char test;
        test = (char)iY+17;
        val = test;
        cout << test << "\n" << val;
        }


It just produces "17" as output, which is a ctrl-q.

You've asked it to use a char datatype, but that doesn't make a VALUE of zero into a value of "0". It makes an int with a value of zero into a NUL.

Add 65 instead.
Last edited on
closed account (E0p9LyTq)
You can have your Section enum store the prices directly as part of the enumeration.

1
2
3
4
5
6
 enum Section
   {
      ORCHESTRA = 150, FRONT = 100, MIDDLE = 50, BACK = 50
   };

   std::cout << FRONT << '\n';

100
Topic archived. No new replies allowed.