Classes in C++ - Reading Assignment

1. Why do we need classes, why can’t we just use structs?
Because Classes allow you to use it as, not only data type but, also as, a function.
2. What are methods?
It is a function inside of a class, Aka member function. Can be defined inside or outside the class.
3. How would you define a class?

//Name the class name, it should use a capital letter in doing so.
class ClassName
{
//list the variables, functions and methods.
     public:
           memberVariable;
           memberFunction;
}

4. What is an object?
It is a instantiation of a class.

1 Like

Why do we need classes, why can’t we just use structs?
structs can only hold data, but classes allow us to define member functions inside as well

What are methods?
the functions defined inside a class

How would you define a class?
it is a data structure that enables you to create objects and is the core of object (not just data) oriented programming

What is an object?
an instance or variable of a class

1 Like

1. Why do we need classes, why can’t we just use structs?
With structs, we can only store data. With classes we can provide functions that works with data.

2. What are methods?
Methods are functions defined in classes.

3. How would you define a class?
class MyClass {
...
};

4. What is an object?
For example: instance of class, variable with members …

1 Like

We need classes because structs are data only. Classes allow complex combinations of functions and objects which can also be isolated or stored into modular groupings for easier modification and debugging.

Methods are usually functions defined in a class.

Class are defined as follows…
class ClassName
{
public or private
//variables,
//functions, etc.
};

An Object is an instance of a class.

1 Like
  1. struct types are built in/preset, whereas with class, you can define a custom data type. Thus, structs can only hold data but, class can hold data and functions.
  2. methods are the functions of each member.
  3. A class is like a struct, except that it can customize a type of variable because of its ability to hold data and functions.
  4. An instance of class
1 Like
  1. Classes allow us to have nested type variables as well as better compatibility with member functions.
  2. Methods are functions found within the class
  3. You define the class as class ClassName{}
  4. An object is a region of storage that holds value
1 Like
  1. because structs can only hold data and classes are working as function with the data

  2. A function defined inside a class

  3. class MyClass
    {
    public:



    };

4.An object is an instance of a class

1 Like
  1. Structs don’t allow functions. Classes are more powerful.

  2. Function inside a class ();

class {functions,
objects;
};
  1. An instance of a class.
1 Like

you didn’t specify the function name :slight_smile:

1. Why do we need classes, why can’t we just use structs?
Both structs and class can contain data and functions but it is recommended to use struct for data-only structures and class for both data and functions since class will deallocate memory after usage.
2. What are methods?
Methods are functions defined within a class
3. How would you define a class?
class SomeName {
public:
int x{};
void print(){}
};
4. What is an object?
An instance of a class

1 Like
  1. Classes not only hold data but can also hold suctions
  2. Methods are functions defined within a class
  3. You define a class in the same format as a struct but with the added public:
    class someClass {public:…};
  4. An Object is a variable of a Class type
1 Like
  1. We need classes to include both data and functions as members of a customized type.

  2. Methods are functions that are members of a class.

  3. A class is a customized type that can have as members both values and functions.

  4. After the definition of a class blueprint ( class ClassName {…}; ) all the variables
    of that type that we create are called objects ( ClassName objectname { }; ).

1 Like

1. Why do we need classes, why can’t we just use structs?
It is best practice to use structs for data-only structures and classes for objects with both member variables and member functions.

2. What are methods?
Methods or member functions are functions defined in a class

3. How would you define a class?
Class and struct definition are almost identicle except for class has public in it. class ClassName{
public:
}
4. What is an object?
A class provides the blue print for an object. An object is created from a class.

1 Like
  1. Classes are a cleaner way to create instaiated objects that have both variables and methods. Class objects will deallocate themselves from memory, where as structs may not.

  2. Methods are functions inside a class.

  3. Classes are defined with the class keyword followed by the capitalized class name.

  4. An object is a data structure in memory that may have variables and functions assigned to it that are generally working together to represent some aspect of the larger program.

1 Like

1. Why do we need classes, why can’t we just use structs?
Structs are only storing data, with classes we can start the object-orientated-programming.

2. What are methods?
mehtods are functions defined in an object.

3. How would you define a class?
A class is a user-defined data type that we can use in our program, and it works as an object constructor, or a blueprint for creating objects.

4. What is an object?
An Object is an instance of a Class.

1 Like
  1. Even though they work the same, it is not recommended to use the struct keyword if you are going to use a member function.

  2. A method, or so called member function, is a function defined in a class.

  3. Same as a struct, the only difference is a keyword. (private, public, protected)

struct structName {
keyword:
  //member variable
  //member function
};
  1. An object is an example of a class. The object attributes provide value for empty class members.
1 Like

1.We often want our types to not only hold data, but provide functions that work with the data as well
2. Functions defined inside of a class are called member functions (or sometimes methods ).
3.class Myclass{ };
4. Object is a part of the class

1 Like
  1. We need classes so that we can create aggregate data types that can also store functions that can interact with its variables.
  2. Methods are members that are functions rather than just variables.
  3. Defining a class is very similar to that of a struct. class x{
    public:
    };
  4. It can be an instance of a class. It could also be a variable of a class type.
1 Like

You have to use the keyword class to define a new class, not struct. :slight_smile:

1 Like

Haha Oh god of course! Thanks for correcting :slight_smile: