Structs C++ - Reading Assignments

1. Why do we need structs?
When we need to store variables that represent an object.

2. What are members in a struct?
Members are variables part of the struct

3. How do you access a member inside a struct?
struct.member

4. What is a nested struct?
This is when a struct has another struct like member

1 Like
  1. A struct allows us to group variables of mixed data types together into a single unit.
  2. Members are the variables that are part of a struct.
  3. We use the member selection operator (which is a period).
  4. A struct that is inside other struct.
1 Like

1. Why do we need structs?
Structs are useful because they help in grouping multiple related variables together into one single data type.

2. What are members in a struct?
Members of a struct are the individual variables that are being grouped together into the struct data type.

3. How do you access a member inside a struct?
Each member is accessed via the dot operator.

4. What is a nested struct?
A nested struct is a struct that is itself a member of another struct.

1 Like

Questions:
. Structs exist so that multiple variables may represent an object.
. Members are variables which are part of the struct.
. The member selection operator must be used.
. Nested structs are structs which contain other structs.

1 Like
  1. Sometimes a number of variables are needed to represent one object. Structs allow us to group variables of mixed data types into a single unit.

  2. The variables that are a part of the struct are called members.

  3. The members inside a struct are accessed with the name of the struct and then the name of the member separated by a period.

struct.member

  1. A nested struct is a struct that is inside of another struct.
1 Like
  1. It allows for the ability to save variables of multiple data types into a single unit.
  2. Variables that are part of the struct.
  3. using the member selection operator (a period), and the data name that you’re looking to retrieve from the member.
  4. A struct that contains other structs within it.
1 Like
  1. Structs help to reduce code and keep multiple attributes for a single variable.

  2. Members or fields are individual variables.

  3. Use member selection operator - struct.member

  4. When a struct has another struct within it - nested.

1 Like

1. Why do we need structs?
To store variables of mixed data types, which we want to deal with as one group, rather than having to refer to each variable individually.

2. What are members in a struct?
They are the variables within of the structure

3. How do you access a member inside a struct?
By using the member selectionoperator, the period similar to dot notation. structName.memberName

4. What is a nested struct?
A structure which is used as a member within another structrure.

1 Like
  • Why do we need structs?
    To group multiple variables together and use them.

  • What are members in a struct?
    The individual variables that make up the struct.

  • How do you access a member inside a struct?
    Member selection operator (.)
    StructName.memberName

  • What is a nested struct?
    A member of a struct which is itself a struct

1 Like
  1. We need structs to store multiple items of data within one “variable” type location.
  2. Members in a struct are the pieces of data that it holds.
  3. You access these members with this format: structname.idofmember.
  4. A nested struct is a struct that has other structs as its members.
1 Like
  1. Structs allow us to group variables of mixed data types together into a single user-defined aggregate data type.
  2. The variables that are part of the struct are called members (or fields).
  3. By using the member selection operator which is a dot. e.g. structName.variable
  4. A nested struct is where a struct is a member within another struct.
1 Like
  1. Why do we need structs?
    because in some cases it is useful to create our own user-defined aggregate data types , and structs allow us to create a variable that holds a mix of different data types

  2. What are members in a struct?
    its like when in javascript we defined the objects:

let school = {
     name: someName,
     totalStudents: 1000,
     teachers: 50,
}

the keys or props in javascripts would be like the members in C++

struct School {
     string name{someName};
     int totalStudents{1000};
     int teachers{50};
}
  1. How do you access a member inside a struct?

Same way that to access an object key or prop in javascript :smiley:

  1. What is a nested struct?

its pretty much like a nest object in javascript :partying_face:

2 Likes
  • Why do we need structs?
    A struct (short for structure) allows us to group variables of mixed data types together into a single unit
  • What are members in a struct?
    These variables that are part of the struct are called members (or fields)
  • How do you access a member inside a struct?
    In order to access the individual members, we use the member selection operator (which is a period)
struct Employee
{
    int id{};
    int age{};
    double wage{};
};
Employee joe; // create an Employee struct for Joe
joe.id = 14; // assign a value to member id within struct joe
joe.age = 32; // assign a value to member age within struct joe
joe.wage = 24.15; // assign a value to member wage within struct joe
  • What is a nested struct?
    Structs can contain other structs. For example:
struct Employee
{
    int id{};
    int age{};
    double wage{};
};

struct Company
{
    Employee CEO{}; // Employee is a struct within the Company struct
    int numberOfEmployees{};
};

Company myCompany;
2 Likes
  1. it allows us to mix different variables of different data types in to one unit

  2. The members are the different vaiables within a struct

  3. You access a memberr by using a member selection operatior. which is a period.

so example

person andy
andy.age=31
andy.gender=male

etc

  1. a nested struct is when one of the members of the struct is also a struct itself with members
2 Likes
  1. Why do we need structs? To store several variables of different data types together

  2. What are members in a struct? Variables

  3. How do you access a member inside a struct? Enter the name of the struct and use dot (.)

  4. What is a nested struct? Nested structure is when a structure is contained inside another one.

2 Likes
  1. Why do we need structs?
    -to group multiple individual variables together to avoid it getting out of control.

  2. What are members in a struct?

    • the variables inside the struct declaration
  3. How do you access a member inside a struct?

    • structName.memberName
  4. What is a nested struct?

    • It is a struct declared inside a struct.
2 Likes
  1. for an object to hold multiple identifiers
  2. the variables to be defined
  3. struct.member
  4. This is when a struct has another struct like member
2 Likes

1. Why do we need structs?
To group variables of mixe data types together into a single unit, a struct.

2. What are members in a struct?
All kind of variable like string, numbers… booleans which are together inside a struct.

3. How do you access a member inside a struct?
With the member selection operator (which is a period).

eg. structName.varibale

// …reminds me of JavaScript :slight_smile:

4. What is a nested struct?
A struct inside a struct.

3 Likes
  1. Why do we need structs?

When we need more than one variable to represent a situation

  1. What are members in a struct?

Variables like ints, strings etc…
3. How do you access a member inside a struct?

you call the struct and variable in it with format:

structname.variablecalled

  1. What is a nested struct?

A struct inside a struct

3 Likes
  1. Simple collection of assicated data
  2. variables of the struct
  3. structVariableName.member
  4. A struct contained within a struct
3 Likes