Turning the pieces of my program into a class

I would like to put parts of my file reading program into a class so that I can edit out certain characters and start totaling the contents of my file as well as have functions that can perform certain arithmetic operations on it.

Truth be told it's an excel file and I'm just re-inventing the wheel but I don't care. I need to practice before my next semester starts and I'm taking a basic beginner Java class. I passed the intro c++ class but it has been a while.

Any advice for getting parts of this into a class? I'm going to try some stuff before I head off to my delivery job but I only have like 10 minutes.

Thanks in advance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
  #include <iostream>
#include <fstream>
#include <string>

using namespace std;

void switchCase(int);
//void displayResult();

int menuList()
{

    int z;
    cout << "Menu" << endl;
    cout << "1. Edit File" << endl;
    cout << "2. Exit" << endl;
    cin >> z;

    return z;
}

int main()
{
    int p = menuList();
    switchCase(p);

}



void switchCase(int menuChoice)
{



        if (menuChoice == 1)
    {

        string hunned;

        fstream myfile;
        myfile.open ("address4.txt");



            while (!myfile.eof())
            {
                myfile >> hunned;
                cout << hunned;

            }

    }

    else if (menuChoice == 2)
    {
        cout << "ok" << endl;

    }

    do
    {
        cout << "Please select an option from the menu and try again." << endl;
        cout << endl;
        menuList();
    } while (menuChoice != 1 || menuChoice != 2);


}
Last edited on
I would suggest reading the tutorial about classes on this site:
http://www.cplusplus.com/doc/tutorial/classes/

Confirm
What kind of object or objects does this program represent or manipulate?
Not clear from your code what kind of objects are stored in address4.txt.

The only thing I see at this point that might be converted to a class is your menu.
Ok I'm going to turn the menu you into a class and just kinda go with it from there, I'll be back soon just need to really make sure I am understanding what the heck is going on when I'm working with classes lol.

Ah well I tried making it into a class and it got confusing as hell. Right now I think my original code is messed up because it doesn't care what I enter, my error checking doesn't even work.
Last edited on
Topic archived. No new replies allowed.