How do you write structures?

Apr 15, 2010 at 12:34am
Im new to C++ and I'm really confused about how structures work.

Write a short program to create a “student” structure that will store a student’s id number, name, major, and CGPA.

Then, assign the follow information into the structure:
Name: Elizabeth Carter
Id number: 53124
Major: IS
CGPA: 3.68
Print out all fields in the structure.

I have to write this short program but I dont even know how to approach it. Any help would be awesome.
Apr 15, 2010 at 12:57am
Okay.

First, define your structure outside of any functions or classes using the struct keyword.

struct NAEM

Then, in the next line, fill it with hot sauce, habanero peppers, cyanide, a pinch of Tabasco, more hot sauce, and a few crystals of pure caffeine variables.
1
2
3
{
   //Variables, insert here.
};


In main(), you need to create an instance of this structure.
 
NAEM instant;

From there, you access the variables like you would from a class instance.

-Albatross

Last edited on Apr 15, 2010 at 12:58am
Apr 15, 2010 at 2:41am
thanks for the help man
Topic archived. No new replies allowed.