0

Hi there, im trying to create a quiz program in c++.

I need to have an array within a struct as i need to store a question title, ten possible answers and the points that each answer is associated with

any help about how to go around declaring this would be appreciated!

5
Contributors
8
Replies
9
Views
6 Years
Discussion Span
Last Post by Nick Evan
Featured Replies
  • 1

    [quote] Yes structures can be used in C++ but I still think that they are kind of outdated, when Stroustrup created The C++(as far as I know) he left structures just for compatibility with the older version of the language, which is C. [/quote] Nope. Please re-read my previous post. … Read More

0

Structures are more related to C language than C++. Anyway you could do it loke so:

#include <string>//including the header for strings
//--------------Other-includes------------------------//
//--------------Other-structs-or-classes-------------//
typedef struct Quiz{
string qTitle;//Question title
int cAnswer;//Correct answer
int Answer;//The user's asnwer
};
//--------------The-rest-of-the-code-------------//

You could also use a vector of Answers(strings) if you want to stock all of the answers in the structure type.

Edited by Basteon: n/a

-2

Hi StuartB2,
we are here working for helping others, So plz do ur best and post here ur thoughts regard ur issue and u will find a lot of help, Thanks

0

Structures are more related to C language than C++.

That's not true, a struct is a perfectly normal thing to use in C++, just like a class. The difference between the structs and classes is that a struct defaults members to public while a class defaults to private. Yes, struct existed in C and classes didn't, but that doesn't mean structs are somehow "outdated"

Offtopic: Basteon, don't give away free help. It's not in forum policy.

Free help can be given away at all time. It's just that we discourage people to give out ready-made solutions to people who are clearly only here to get a homework freebie. Giving some code to illustrate your point is no problem at all. Don't be too harsh to our new-and-enthusiastic members ;)

On topic:

Do you perhaps mean an array of structs? That would make more sense IMO.

Edited by Nick Evan: n/a

0

Yes, arrays, that's what I meant )). I gave up to arrays when I learned about vectors, since then I sometimes confuse this two notions.

Yes structures can be used in C++ but I still think that they are kind of outdated, when Stroustrup created The C++(as far as I know) he left structures just for compatibility with the older version of the language, which is C.

Edited by Basteon: n/a

1

Yes structures can be used in C++ but I still think that they are kind of outdated, when Stroustrup created The C++(as far as I know) he left structures just for compatibility with the older version of the language, which is C.

Nope. Please re-read my previous post. Structs in C++ are exactly the same as classes with the one exception that members in structs are public by default while members in classes are private by default.

Edited by Nick Evan: n/a

Comments
Yeah, I agree. I was going to comment in their defense, but you took care of it :)
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.