Your class should have a constructor that initializes the three data members.

Asked 2 years ago, Updated 2 years ago, 23 views

I'm asking you this question because I don't understand exactly what it means To sum up, this is a class example, but it's a class for vehicles Give 5 member variables and make set and get functions for each variable The question is to print out the member variable of each object through the method

But I think that phrase in the question means I think you're asking me to put only three variables in the constructor, so what do I do with the other two? I don't think it makes sense. I don't think I understand the problem ㅠ<

c++

2022-09-22 08:37

2 Answers

Your class should have a constructor that initializes the three data members.

Constructor is the code that runs when you create that instance.

What about the other two variables? Are you just telling me to skip it? I think it's a question, so I'm focusing on it and answering.

Maybe you're asking me to make a Constructor that receives three parameters.

#include <iostream>
#include <ctime>
#include <string>
using namespace std;

class user{
    private:
        int id;
        time_t create_date;
        string userID;
        string password;
        string email;
    public:
        user(string userID, string password, string email){
            this -> userID = userID;
            this -> password = password;
            this -> email = email;

            Assign using this -> id; // auto increment function.
            This -> create_date; // Get the current date and assign it.
        }

        void print(){
        }
};

int main()
{
}

For the other two member variables, you can have the computer automatically turn off, or you can just assign nothing.

I think you can think of it as an option.


2022-09-22 08:37

Slightly literal: There must be a constructor that initializes the three data members (variables).

Translation: The constructor must have code to initialize three data member variables.


2022-09-22 08:37

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.