Structs C++ - Reading Assignments

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

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.

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;
  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.
  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.
  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 }.
  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

  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

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.

1 - we need structs to be able to assign several variables relating to one single object.
2 - member are the variables that make a struct.
3 - to access a member in a struct, one should use the period
4 - a nested struct is a struct inside another struct.

  1. Why do we need structs? To store more than one variable ir order to represent an object.
  2. What are members in a struct? A struct (short for structure) allows us to group variables of mixed data types together into a single unit.
  3. How do you access a member inside a struct? In order to access the individual members, we use the member selection operator, this is “variable struct name.member”.
  4. What is a nested struct? Structs that content other structs.
  1. A struct (short for structure) allows us to group variables of mixed data types together into a single unit.
  2. Members (or fields), are the variables inside a struct.
  3. In order to access the individual members, we use the member selection operator (which is a period).
  4. A nested struct, is a struct within a struct.

#letsgetthiscrypto

  1. Why do we need structs?
    Structs allows us to group variables of mixed data types together, into a single unit as new data type.
    2. What are members in a struct?
    Different types of variables (or the same type) contained within a struct.
    3. How do you access a member inside a struct?
    struct name . member name;
    or in nested struct: struct name . nested struct name . member;
  2. What is a nested struct?
    a nested struct is a struct within another struct. how to access member of nested struct - see previous answer.

a question - what is “static_cast” for?

in the second quiz answer the “multiply” function did not execute properly without it :

std::cout << static_cast(f1.numerator * f2.numerator) /
(f1.denominator* f2.denominator);

Omiting the "static_cast " resulted in nonexecution of the “multiply” function .

Thanks :slight_smile:

Structs C++ - Reading Assignments

1. Why do we need structs?

  • to order and categorize multible variables

2. What are members in a struct?

  • Members are variables which are part of a structure

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

  • stuctureName.memeberName;

4. What is a nested struct?

  • Nested Structure are structures inside structures

Sorry Guy, I have now clew what “static_cast” is for. I’m c++ noob.

Hope the next one can answer you question. :wink:

PS. Actually I have the same question.

Why do we need structs?

To store many variables in one structure

What are members in a struct?

It defines the types of variables that will be put in to the struct

How do you access a member inside a struct?

First declare a name for struct using your struct variable , then use you new variable.member to fill the info for each member

What is a nested struct?

A struct inside a struct