Need help please!!! I am stuck

Good evening, I have finished my homework assignment, and my code works like a charm (with probably some minor extra unused variables lol) , but I need help creating a class that will help me decrease the amount of code lines in main. Please help me as I would love to get that extra credit and understand how classes work, I tried watching youtube and google, but still everytime I try I get a compiling error. I want to send my code by PM because this assignment is due tomorrow and I don't want people to cheat and copy off me.
Also just a heads up I need to creat a class.cpp file that will send arguments to main.cpp.

Thank you in advance!
Hi there, you can try to create a sample project to understand how class works. For example, create a class with function which adds two numbers and return the sum.
You could share the sample project with us if you have problem.
I did, however when i use it with my fstream code and menu it just keeps giving me headaches
a "hello world" or list of potatoes works fine. I just have no idea what even the professor wants me to put into the class. He just said if we can add a class in the program we will get extra credit.
https://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/

^If you read through it, you should have an understanding of classes.

Basically, a class is like a room. You keep stuff in there that you think is similar/related/will be used with each other. You'll store variables and functions inside of classes to access later.

EX:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
 
class DateClass
{
public:
    int m_year;
    int m_month;
    int m_day;
 
    void print()
    {
        std::cout << m_year << "/" << m_month << "/" << m_day;
    }
};
 
int main()
{
    DateClass today { 2020, 10, 14 };
 
    today.m_day = 16; // use member selection operator to select a member variable of the class
    today.print(); // use member selection operator to call a member function of the class
 
    return 0;
}


^Taken from the site I linked.

EDIT: Wanted to add that this is classes at its basic form. For "safety", the keyword public will sometimes be private or protected to keep access to the class limited to only when needed/appropriate.
Last edited on
Topic archived. No new replies allowed.