About classes


1
2
3
4
5
6
7
struct josiah{
float hez;
int asa;
char flah[8];
};
int main (void){
struct josiah josh = {2.141, 22,  "king"};


Q1: what is the effect of the code cout<< ++joash.asa.+joash.hez;?
A1: ++joash.asa = 22+1 = 23, joash.hez = 3.14, so cout<< ++joash.asa.+joash.hez; will display 26.141.
The professor grade me and say "what else?" i don't know what else is there. Can anyone help me on that.

Q2: if i were to add a substructure of type jehoram name joram to this structure, how would i access the member initial of the sub structure and set it equal to 'A'
A:
1
2
3
4
5
6
struct jehoram{
char initial {2};
};
int main (void){
struct jehoram joram = {'A'};
return 0;


For that answer the professor mark me completely wrong, which i don't know why.
Last edited on
1) I don't see anything else there...I think your answer was correct.

2) By "substucture" the question meant:

1
2
3
4
5
6
7
8
9
struct josiah{
    float hez;
    int asa;
    char flah[8];
    //this is the substructure
    struct jehoram_name {
        char initial;
    } joram;
};


Can you answer it now?
Jimmy, your answer to question 2 doesn't compile, and you've misunderstood how to create a new instance of a structure in C++.
Last edited on
++joash.asa.+joash.hez <-- ".asa."
Is the period after asa suppose to be there. You type it twice so I assume yes... Isn't that an error?
Topic archived. No new replies allowed.