How do you write structures?

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.
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
thanks for the help man
Topic archived. No new replies allowed.