Structs C++ - Reading Assignments

#101

Why do we need structs?
Allows groups of different variables to be referred to as a distinct unit

What are members in a struct?
Fields, consisting of different variables

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

What is a nested struct?
A struct declared within another struct

#102

1. Why do we need structs?
When u need to group up many variables into a single data type.
2. What are members in a struct?
variables inside the struct parameters.
3. How do you access a member inside a struct?
struct.memberDataType
4. What is a nested struct?
An struct defined has a member inside another struct.

#103
1. Why do we need structs?

We need structs in order to group multiple individual variables of different data types together. This make it easier to pass information more easily to a function and declare faster several “entities”.

2. What are members in a struct?

The members are the variables inside the struct that define it. For example declaring an employee in a program might include its age, wage, department etc…

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

Accessing a member in a struct is done by using the name of variable that is the struct, and then appending the member selection operator, which is simply a period, and then the member previously declared in the struct. For example, I declare my struct:

struct Employee
{
    short id;
    int age;
    double wage;
};

Then I declare a variable, which type is the struct I created:

Employee joe; 
Then I access the members like so:
joe.id = 14;
4. What is a nested struct?

A nested struct is a struct within a struct

struct Employee
{
    short id;
    int age;
    double wage;
};
 
struct Company
{
    Employee CEO; // Employee is a struct within the Company struct
    int numberOfEmployees;
};
Company myCompany;
#104
  1. Why do we need structs?
    Structs allow us to group variables of different data types together into a single unit.
  2. What are members in a struct?
    Variables or fields within a struct.
  3. How do you access a member inside a struct?
    structName.member
  4. What is a nested struct?
    A struct inside of a struct.
#105
  1. We need structs when we want to store different types of data in one variable/unit.
  2. Variables or individual values of the struct.
  3. You can access a member of a struct typing its name preceded by a point
  4. A struct that contains other struct/s inside.
#106
  1. Why do we need structs? These are similar to classes, they are objects that contain multiple variables in them that are ‘aspects’ of the struct (called members).
  2. What are members in a struct? variables that are part of the struct are called members (or fields).
  3. How do you access a member inside a struct? Use the member selection operator (a period) to get to members inside a struct. i.e.: if you have a struct Students, and frank is a Student then the id variable for frank could be accessed by typing frank.id (the Student struct is init capped, the individual students (frank) are not, by convention).
  4. What is a nested struct? A nested struct is a ‘struct within a struct’. i.e.: you could have a separate struct for Employees and another struct for Companies. The Companies struct may include members that are members from the Employees struct: struct Company { Employee CEO; int noOfEmployees }.
#107
  1. It is a way to aggregate a related group of properties together under the one data structure. It helps with maintaining a good structure within a class, otherwise the individual properties (that really belong together) would be scattered throughout the code and the logic would be much harder to follow.

  2. Members are those individual fields/properties that make up the struct. Each member of the struct can have a different data type

  3. You can just use the dot notation for accessing them e.g myStruct.memberA

  4. A nested struct is when one of the member within a struct is itself defined as a struct. For example a struct could be Factory within many members within it, e.g location, number of buildings, but also some of these members could be nested structs e.g Employee, Machine e.t.c

#108
  1. We need struct to manage different variables that are related to only one object
  2. They are variables
  3. With the dot notation
  4. A struct defined using another struct
#109

http://www.learncpp.com/cpp-tutorial/47-structs/

  1. Why do we need structs?

Structs enable us to add multiple variables to an object.

They also allow us to group variables of mixed data types together into a single unit.

  1. What are members in a struct?

Members (or fields) are variables inside of a struct.

  1. 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.member

  1. What is a nested struct?

Structs can contain other structs.