Creating a function forcalculating

I have a code witch saves some data, can some one make a function which calculates the total points of var test + driving1 + driving2 and saves them in the text file as the first thing so i can sort them from the post points to lower points
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#include <iostream>

#include <fstream>

#include<iomanip>

#include <cstdlib>

#include <string>

using namespace std;

class Kursist
{
    //private
    string ime;
    string familia;
    int listovka;
    int drive1;
    int drive2;
    int resultat;

public:
    Kursist(string name, string lname, int test, int driving1, int driving2, int result)
    {
        ime=name;
        familia=lname;
        listovka=test;
        drive1=driving1;
        drive2=driving2;
        resultat=result;
    }
    Kursist() {}
    ~Kursist() {}

    void SetName(string name)
    {
        ime=name;
    }

    string GetName()
    {
        return ime;
    }


    void SetLname(string lname)
    {
        familia=lname;
    }


    string GetLname()
    {
        return familia ;
    }


    void SetTest(int test)
    {
        listovka=test;
    }


    int GetTest()
    {
        return listovka;
    }


    void SetDriving1(int driving1)
    {
        drive1=driving1;
    }


    int GetDriving1()
    {
        return drive1;
    }


    void SetDriving2(int driving2)
    {
        drive2=driving2;
    }


    int GetDriving2()
    {
        return drive2;
    }


    void SetResult(int result)
    {
        resultat=result;
    }


    int GetResult()
    {
        return resultat;
    }
};

void outputLine( Kursist );

int main( )

{

    int i;

    Kursist kursist[3];

    string name;
    string lname;
    int test;
    int driving1;
    int driving2;
    int result;

    cout << "Enter the name, family and results.\n";


    for (i=0; i<3; i++)

    {

        cout <<"Ime: \n";
        cin >> name;
        kursist [i].SetName(name);

        cout <<"Family: \n";
        cin >> lname;
        kursist [i].SetLname(lname);

        cout <<"Test: \n";
        cin >> test;
        kursist [i].SetTest(test);
        if ( test < 90 )
        {
            cout<<"Fail!\n";
            exit(0);
        }

        cout <<"Driving1: \n";
        cin >> driving1;
        kursist [i].SetDriving1(driving1);
        if ( driving1 < 90 )
        {
            cout<<"Fail!\n";
            exit(0);
        }

        cout <<"Driving2: \n";
        cin >> driving2;
        kursist [i].SetDriving2(driving2);
        if ( driving2 < 90 )
        {
            cout<<"Fail!\n";
            exit(0);
        }

        result = test + driving1 + driving2;

        cout << "Obshti tochki:" << result <<endl;

        Kursist akursist(name, lname, test, driving1, driving2, result);

        kursist[i]=akursist;

    }


    ofstream outKursistFile;

    outKursistFile.open( "kursist18.dat" );

    {


        if ( !outKursistFile )


            cerr << "File could not be opened" << endl;

    }


    for (i=0; i<3; i++)

    {

        outKursistFile << kursist[i].GetName() << setw( 10 ) << kursist[i].GetLname()<< setw( 13 )<<kursist[i].GetTest()<< setw( 7 ) << kursist[i].GetDriving1() << setw( 10 ) <<kursist[i].GetDriving2()<< setw( 10 ) <<kursist[i].GetResult() <<  "\n";

    }

    outKursistFile.close();




    return 0;
}

void outputLine( Kursist kursist )

{

    cout << setiosflags( ios::left ) << setw( 10 ) << kursist.GetName() << setw( 13 ) << kursist.GetLname() <<setw( 7 ) << setprecision( 2 )<< resetiosflags( ios::left )<<kursist.GetTest()<< setw( 10 ) <<kursist.GetDriving1()<< setw( 10 ) <<kursist.GetDriving2()<< kursist.GetResult() << "\n";
}
can some one make a function which calculates the total points of var test + driving1 + driving2 and saves them in the text file as the first thing so i can sort them from the post points to lower points


Can you please rephrase this question. I do not understand.
You could change line 196 so the first item written to outKursistFile is kursist[i].GetResult().
Topic archived. No new replies allowed.