Classes in C++ - Reading Assignment

1. Why do we need classes, why can't we just use structs?

Structs are typically used to hold data only, although structs may contain functions. Classes provide a way to hold data and functions that work with the data as well. Data only structs need the functions to be defined separately. Classes will also dealocate memory after being destroyed, which increases performance, you may not assume this using a struct.

2. What are methods?

Methods or member functions are functions inside a class that use the data inside the class.

3. How would you define a class?

First declare the class

class DateClass
{
public:
    int m_year;
    int m_month;
    int m_day;
};

then declare the variables of the class using the known method:
DateClass today { 2020, 10, 14 };

4. What is an object?

An object is a variable of a class type, also called an instance

1. Why do we need classes, why can’t we just use structs?
Classes allow for functions to be included. Structs can only hold data.
2. What are methods?
Functions which are a member of a class.
3. How would you define a class?
class TestClass {
code goes here…
};
4. What is an object?
An object is an instance of a class.

1. Why do we need classes, why can’t we just use structs? Use the struct keyword for data-only structures. They can contain functions, but they do not implicitly pass the struct object that is inside the struct. You need to explicitly pass the object to the function (ie: class usage of member function: today.print(); vs struct function usage: print(today):wink: In the struct use of the function, you need to pass the struct to the function, otherwise it will not know what to do. Versus the class use of the member function, it’s dot notation implicitly passes the class object into the function. Use the class keyword for objects that have both data and functions
2. What are methods? Methods are functions that are within classes or structs .
3. How would you define a class? You can define a class the same way as a struct, the convention is to name it with initial caps and classes can have private and public member variables.
4. What is an object? A variable of a class type is also called an object

  1. Structs on their own are not that useful as they only contain data but don’t have a way to alter that data. Classes allow programmers to take data as inputs (e.g structs, arrays, primitive data types) and manipulate the state of the data in order to produce some behaviour.

  2. Methods are member functions within a class which can take input and manipulate it order to produce some specific behaviour or functionality

  3. class MyClass {
    // member variables

// member functions
void myMethod() {
// do something to the variables
}
};

  1. An object is an instance of a class. For example, a programmer could create a class called Person. They could then create instances of that Person class which are the objects and can represent things in the real world e.g. John, Sarah e.t.c
  1. Because structs are data-only whereas classes can embed functions
  2. Methods are functions that belong to a class or at least that relate to a class
  3. A class is a model, like a struct for describing properties but with tools (methods) in addition
  4. An object is an instantiation of a class which means this is a concrete realization of a class. A class is an abstraction, a set of properties and methods whereas an object is a concrete materialization of this abstraction, it’s an exemple of applied set of properties and methods.
  1. Why do we need classes, why can’t we just use structs?
    Classes hold member variables and member functions and structs hold only variables.

  2. What are methods?
    Member functions defined inside of a class.

  3. How would you define a class?
    Class Date {
    Public:
    Int m_year;
    Int m_month;
    Int m_day;

    Void printDate() {
    Cout << m_year << “/” << “/” << m_day;
    }
    }

  4. What is an object?
    A variable of a class is an object.

1 - classes allow to integrate functions inside them, using parameters from inside the same class.
2 - methods are functions defined inside a class, and they can use variables from inside the same class.
3 - class {
//access specifiers
// variables
// methods
};
4 - an object is an instantiation of a class.

  1. Why do we need classes, why can’t we just use structs? In the world of object-oriented programming, we often want our types to not only hold data, but provide functions that work with the data as well.
  2. What are methods? In addition to holding data, classes (and structs) can also contain functions! Functions defined inside of a class are called member functions (or sometimes methods ). Member functions can be defined inside or outside of the class definition.
  3. How would you define a class? A struct that not only hold data, but can also provide functions.
  4. What is an object? when we define a variable of a class, we call it instantiating the class. The variable itself is called an instance , of the class. A variable of a class type is also called an object, for example: DateClass today { 2020, 10, 14 }; // declare the variable or objet “today” of class “DateClass”.strong text

CAN SOMEONE ANSWER THIS PLEASE!?!?

So after getting 50% of the course done I just noticed this for the 1st time.

At the bottom of the article you’ll see a quiz - make sure to do the quiz!

I mean I have been answering them, but I wasn’t posting them on the quiz page, just solving them in my or taking notes.
Will this be a problem?

#letsgetthiscrypto

  1. With classes, we can provide functions that works with the data… structs only store the data.
  2. Functions defined in classes are methods.
  3. class class DateClass{

    };
  4. An object is an instance of a class.

#letsgetthiscrypto

1. Why do we need classes, why can’t we just use structs?
Because structs are data only. In addition to holding data, classes can also contain functions. Functions defined inside of a class are called member functions (or methods ).

2. What are methods?
methods are Functions defined inside of a class (member functions).

3. How would you define a class?
class ClassName
{
public:
public members (variables and functions/methods)
private:
private members (variables and functions/methods).
}

4. What is an object?
An object is an instance of a class. A variable of the type class allocated to memory.

Classes in C++ - Reading Assignment

1. Why do we need classes, why can’t we just use structs?

  • it is better to use class when using member functions
  • structures only can hold data, no functions

2. What are methods?

  • member functions can be called methods

3. How would you define a class?

class classname{
public:
    int var;
    int function(){
    code
    }
    ...
};

4. What is an object?

  • objects are the variables of classes