CODE::BLOCKS vs MS C++ 6

Pages: 12
hi guys ....

I'm sorry to ask this kind of question .. , but I am in a bad really bad sitiuation ......
guys .. I have gave a student a word that i will solve his assignment and teach him how it works .......

(I'm a VB.Net2008 programmer .. and I know the syntax of C++).....

any way now (we have 3 days left till the deadline)
I got it working in the CODE::Blocks ..... (I didn't ask him what his teacher uses ...... my fault....)

when I asked him ..... he said MS C++6 ........

I coped the code from Code::Blocks and creatd a project in MSC++6 and pasted it there ...........
It didn't work ..... it gave me about 40 or more error messages

one of them :
i made an overloading of th operator >> and << .....
i declared it in the class .....
and i defined it after the class ......(that works in Borland too..)
in MSC++6 it told me that fried can only be declared in the class

I mean I can't fix them all if i don't already know them ......

and if i will make them ...... it's gonna take for ever ..... (and I am out of time ..)

the big problem tha I'm paid for this ..... it's not a jock here.......so i have to commit to it ..........


so can any one pleas ....... just help me to change it from CODE::BLOCKS to MSC++6 .......(I promise u I will never ask like this question....)
I'm really feeling shy saying this to u .....

and one more problem....... I made two way to solve the assingnment ...(sorry ...!@!@#@#@#$#$%#@$%^%^)


in the next post i will post the code (to not exceed the limit of the max length of the post)

this is noe of the ways .......
one class in this post and the another in the next post

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


#include <iostream>
#include <string.h>
#include <fstream.h>
#include <Math.h>
using namespace std;

long Val(char NumChars[]){

    if ( strlen(NumChars)== 1 )
        { return (int) NumChars[0]-48 ; }

    long rtn = 0;
    for (int i = strlen(NumChars) -1   ; i  >=0  ; i--)
    {
        rtn += ceil(pow( 10 ,strlen(NumChars) -1- i)) * ((int) NumChars[i]-48) ;
    }
    return rtn ;
  }

class Invoice{

    private :
    public :
        Invoice (): CounterNum(0),            Address("nowhere"),
                    InvoiceNum(0),            AllFees(0),
                    FeesKind(0),              CounterPreSign(0),
                    CounterCurSign(0),        CycleNum(1),
                    Year(2009),               ReleaseDate(0)
                    {}
        // end of the default Constructor

        long CounterNum ;
        string Address;
        long InvoiceNum ;
        long AllFees;
        int FeesKind ;
        long CounterPreSign;
        long CounterCurSign;
        int CycleNum ;
        int Year ;
        long ReleaseDate;
        // end of fields

        long ConsumAmount()        {
            return CounterCurSign - CounterPreSign;
        }

        double InvoiceAmount() {

            long CA = ConsumAmount();
            long rtn = 0 ;

            if (CA > 2000)
                {
                    rtn = CA * 400;
                    rtn += AllFees ;
                    return rtn *1.0 /100 ;
                }

            if (CA >=1001  && CA <= 2000)
                {
                    rtn += (CA - 1000) * 350 ;
                    CA -= CA - 1000 ;
                }

            if (CA >=801  && CA <= 1000)
                {
                    rtn += (CA - 800) * 300 ;
                    CA -= CA - 800;
                }

            if (CA >=601  && CA <= 800)
                {
                    rtn += (CA - 600) * 200 ;
                    CA -= CA - 600 ;
                }

            if (CA >=401  && CA <= 600)
                {
                    rtn += (CA - 400) * 75 ;
                    CA -= CA - 400 ;
                }

            if (CA >=201  && CA <= 400)
                {
                    rtn += (CA - 200) * 50 ;
                    CA -= CA - 200 ;
                }

            if (CA >=101  && CA <= 200)
                {
                    rtn += (CA - 100) * 35 ;
                    CA -= CA - 100 ;
                }

            if (CA >=1  && CA <= 100)
                {
                    rtn += CA  * 25 ;
                }

            rtn += AllFees ;
            return   rtn *1.0 /100 ;

            }

        void Update(long CntrNum ,           string Adres,
                    long nvsNum ,            long AlFs,
                    int FsKind ,             long CntrPreSign,
                    long CntrCurSign,      int CycleN ,
                    int Yr ,                 long RlsDt
                    ){

                    CounterNum =CntrNum ;            Address = Adres ;
                    InvoiceNum = nvsNum ;            AllFees = AlFs;
                    FeesKind= FsKind;                CounterPreSign = CntrPreSign ;
                    CounterCurSign = CntrCurSign ;   CycleNum = CycleN;
                    Year=Yr;                          ReleaseDate=RlsDt;
                    }
    friend istream &operator >> (istream &in,Invoice &inv );
    friend ostream &operator << (ostream &out ,Invoice &inv );
};

istream &operator >> (istream &in,Invoice &inv ){

    cout << "Enter Counter Number\t";           in >> inv.CounterNum;
    cout << "Enter Address \t";                 in >> inv.Address;
    cout << "Enter Invoice Number\t";           in >> inv.InvoiceNum;
    cout << "Enter All Fees \t";                in >> inv.AllFees;
    cout << "Enter Fees Kind  \t";              in >> inv.FeesKind ;
    cout << "Enter Counter Previous Sign\t";    in >> inv.CounterPreSign;
    cout << "Enter Counter Current Sign\t";     in >> inv.CounterCurSign;
    cout << "Enter Cycle Number \t";            in >> inv.CycleNum ;
    cout << "Enter Invoice Year \t";            in >> inv.Year;
    cout << "Enter Release Date\t";             in >> inv.ReleaseDate;

    return in;

}
ostream &operator << (ostream &out,Invoice &inv ){

    out << "Counter Number\t" << inv.CounterNum << "\n" ;
    out << "Address \t" << inv.Address << "\n" ;
    out << "Invoice Number\t" << inv.InvoiceNum << "\n" ;
    out << "All Fees \t" << inv.AllFees << "\n" ;
    out << "All Fees Kind \t" << inv.FeesKind << "\n" ;
    out << "Counter Previous Sign\t" << inv.CounterPreSign << "\n" ;
    out << "Counter Current Sign\t" << inv.CounterCurSign << "\n" ;
    out << "Cycle Number \t" << inv.CycleNum  << "\n" ;
    out << "Invoice Year \t" << inv.Year << "\n" ;
    out << "Release Date\t" << inv.ReleaseDate << "\n" ;
    out << "Invoice Amount\t" << inv.InvoiceAmount()<< "\n" ;

    return out;
}
Last edited on
this is the a part of the second class
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

class Client{
    private :
    public :
        Client(string cName,long cNatID, long cCntrNum){
                Name = cName ;
                NationalID = cNatID ;
                CounterNum = cCntrNum;
                PaymentsCount = 0 ; // as an initioalization
                InvoicesCount = 0 ; // as an initioalization

            }
        string Name ;
        long NationalID;
        long CounterNum ;
        long InvoicesCount ;
        Invoice Invoices[300];
        int PaymentsCount;
        long Payments [300]; // ask what the len of this array is
        long PaymentsDates[300];// this array has to have the same size of Payments[] // and see the type of it
        long PaymentsMethod[300];// this array has to have the same size of Payments[]
        // end of fields

        void Client2File (char FileName[] ){
            fstream file2write2( FileName ,ios::out);
            if (file2write2.fail())
                {
                    cout <<"\nan error encountered during opening the file";
                    cout <<"\nData Were Not Written To The File .";
                    return ;
                }

            file2write2 << InvoicesCount  << "\n";
            file2write2 << PaymentsCount << "\n";

            // next is to write invoices
            file2write2 << "[Invoices Amounts]\n";//like a section
            for (int i =0 ;i<300 ;i++)
                {
                    file2write2 << "[Invoice Number " << i << "]\n";
                    file2write2 << Invoices[i].CounterNum<< "\n";
                    file2write2 << Invoices[i].Address<< "\n";
                    file2write2 << Invoices[i].InvoiceNum<< "\n";
                    file2write2 << Invoices[i].AllFees<< "\n";
                    file2write2 << Invoices[i].FeesKind<< "\n";
                    file2write2 << Invoices[i].CounterPreSign<< "\n";
                    file2write2 << Invoices[i].CounterCurSign<< "\n";
                    file2write2 << Invoices[i].CycleNum<< "\n";
                    file2write2 << Invoices[i].Year<< "\n";
                    file2write2 << Invoices[i].ReleaseDate<< "\n";

                }

            file2write2.flush();

            // next is to write Payments
            file2write2 << "[Payments]\n";//like a section
            for (int i =0 ;i<300 ;i++)
                {
                    file2write2 << "[Payment " << i << "]\n";
                    file2write2 << Payments[i] << "\n";
                    file2write2 << PaymentsDates[i] << "\n";
                    file2write2 << PaymentsMethod[i] << "\n";
                }

            file2write2.close();
        }
        void ClientFromFile(char FileName[]){

            fstream file2readFrom( FileName , ios::in);

            char *line ;
            line = new char [0];

            file2readFrom.getline((char *)line,100);
            InvoicesCount = Val(line);
            //----------------
            //line = new char [0];
            file2readFrom.getline((char *)line,100);
            PaymentsCount  = Val(line);
            //----------------

            // next is to read invoices
            //line = new char [0];
            file2readFrom.getline((char *)line,100); //this is to read the section  "[InvoicesAmounts]"
            //line = new char [0];
            for (int i =0 ;i<300 ;i++)
                {
                    file2readFrom.getline((char *)line,100); //this is to read the section  "[Invoices Number i]
                    //cout << line <<"\n";
                    file2readFrom.getline((char *)line,100);
                    Invoices[i].CounterNum = Val(line);

                    file2readFrom.getline((char *)line,100);
                    Invoices[i].Address = line ;

                    file2readFrom.getline((char *)line,100);
                    Invoices[i].InvoiceNum = Val(line);

                    file2readFrom.getline((char *)line,100);
                    Invoices[i].AllFees = Val(line);

                    file2readFrom.getline((char *)line,100);
                    Invoices[i].FeesKind = Val(line);

                    file2readFrom.getline((char *)line,100);
                    Invoices[i].CounterPreSign = Val(line);

                    file2readFrom.getline((char *)line,100);
                    Invoices[i].CounterCurSign = Val(line);

                    file2readFrom.getline((char *)line,100);
                    Invoices[i].CycleNum = Val(line);

                    file2readFrom.getline((char *)line,100);
                    Invoices[i].Year = Val(line);

                    file2readFrom.getline((char *)line,100);
                    Invoices[i].ReleaseDate = Val(line);
             }

            // next is to read Payments
            file2readFrom.getline((char *)line,100); //this is to read the section   "[Payments]"

            for (int i =0 ; i< 300 ; i++) {

                    file2readFrom.getline((char *)line,100); //this is to read the section  "[Payment Number i]

                    file2readFrom.getline((char *)line,100);
                    Payments[i] = Val(line);

                    file2readFrom.getline((char *)line,100);
                    PaymentsDates[i] = Val(line);

                    file2readFrom.getline((char *)line,100);
                    PaymentsMethod[i] = Val(line);
                 }

            file2readFrom.close();

            }

hahahaha.. cool story dude...

so is the full code.. i mean only one file.. paste the full code.. there is no main function!!!
then let me help you.. :) send me half the money... hehehe...lolzzzz... just joking..

paste the whole code..
this is the last part of the second class Client
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


        void AddInvoiceP ( long CounterNum ,       string Address,    long InvoiceNum ,
                           long AllFees,         int FeeKind ,      long CounterPreSign,
                           long CounterCurSign,  int CycleNum ,     int Year,
                           long RlsDt  )  {

                Invoice tmp ;
                tmp.CounterNum = CounterNum ;
                tmp.Address =  Address;
                tmp.InvoiceNum = InvoiceNum ;
                tmp.AllFees=     AllFees ;
                tmp.FeesKind =FeeKind ;
                tmp.CounterPreSign = CounterPreSign ;
                tmp.CounterCurSign = CounterCurSign ;
                tmp.CycleNum =  CycleNum;
                tmp.Year =Year;
                tmp.ReleaseDate=RlsDt;
                InvoicesCount++;
                Invoices[InvoicesCount-1] =  tmp;

        }
        void AddInvoiceK () {

                Invoice tmp ;
                cout << "\nEnter the Invoice Informations\n";
                cin >> tmp ;
                InvoicesCount++;
                Invoices[InvoicesCount-1] =  tmp;

        }
        void AddPayment(){
            PaymentsCount+=1 ;

            cout << "Enter Payement Amount ";        cin >> Payments[PaymentsCount-1];
            cout << "Enter Payement Date ";          cin >>PaymentsDates[PaymentsCount-1];
            cout << "Enter Payement Method ";        cin >>PaymentsMethod[PaymentsCount-1];
        }
        void ShowClient ()  {
            double AllInvoicesAmounts = 0 ; long AllPayments =0;

            cout << "\nClient [" << Name <<"] Informations :\n";
                    cout << "\tNational ID\t" << NationalID <<"\n";
                    cout << "\tCounter Number\t" << CounterNum <<"\n";
                    cout << "\tInvoices Count\t" << InvoicesCount <<"\n";

                    cout << "\tInvoices are like next :\n";
                            for (int i = 0 ; i < InvoicesCount ; i++)
                             {
                               cout <<"\t\tInvoice Number\t" << Invoices[i].InvoiceNum<<"\n";
                               cout <<"\t\tCycle Number\t" << Invoices[i].CycleNum<<"\n";
                               cout <<"\t\tYear \t" << Invoices[i].Year<<"\n";
                               cout <<"\t\tInvoice Amount\t" << Invoices[i].InvoiceAmount()<<"\n";
                               AllInvoicesAmounts +=Invoices[i].InvoiceAmount() ;
                               cout << "\t\t------------------\n";
                              }
                    cout << "\tAll Invoices Amounts : "<< AllInvoicesAmounts <<"\n";
                    cout << "\t------------------\n";
                    cout << "\tPayments Count\t" << PaymentsCount << "\n";
                    cout << "\tPayments are like next :\n";
                            for (int i = 0 ; i < PaymentsCount ; i++)
                                {
                                 cout <<"\t\tPayment Number [" <<  i+1 <<"] :\n";
                                 cout <<"\t\t\tPayment Amount\t" << Payments[i]<<"\n";
                                 cout <<"\t\t\tPayment Date\t" << PaymentsDates[i]<<"\n";
                                 cout <<"\t\t\tPayment Method\t" << PaymentsMethod[i]<<"\n";
                                 AllPayments +=Payments[i];

                                 cout << "\t\t------------------\n";
                                }
                    cout << "\tAll Payments : "<< AllPayments <<"\n";
                    cout << "\t------------------\n";
        }
        void ShowAllInvoices() {
            for (int i = 0 ; i < InvoicesCount ; i++)
                {
                    cout << Invoices[i]<< "\n---------------\n";
                }
        }
        void ShowAllInvoicesInYear(long Y)  {
            cout << "Invoices in the year [" << Y << "]\n------\n";
            for (int i = 0 ; i < InvoicesCount ; i++)
                {  if ( Invoices[i].Year == Y)
                    {
                        cout << Invoices[i] << "\n---------------\n";
                    }
                }

        }
};
int main(){
// in the assignment .... the function main is not required
}


and I'm sorry for the typos .... and aparting the code .......
I should have sent the code as an attachment ...... but I'm new to this forum and I don't know how to do that yet ............
and tell which file has which code.. the code looks huge.. :(
the code is one file .....
tell me pleas (as i see that u r live to me now ...)
can u help me .......... ???
here are the 2 ways in a whoe file ......

http://www.4shared.com/file/94336230/760c6d42/the_2_ways.html
you want this code with no errors in vc++.. correct. thats all you want.
will do it tomorrow morning (IST). coz i have a linux machine at home, will do it in office. :D
thanks ...... but not a VC++ ...... it's a console C++
Last edited on
I fixed the first one by merely using new headers. Change <string.h> to <string> and <fstream.h> to <fstream> and main.cpp compiles and runs.

All you need to do is get rid of the depreciated headers and your good.

I think VC++ thinks that string.h is actually <cstring> and not <string> which in fact it is.
Last edited on
are you saying that it worked with you ...... cuz it didn't work with me.......
it keeps saying
'string' : undeclared identifier
I did what ever you mentioned ...... but still saying it......


as a solutions ...... I changed the data type of all string variable from 'string' to char array ........

and it keept giving me errors I don't think that it was right to give (lol)
like
'cout is not declared in the scope'

what does it mean ...???!!...i have included the "iostream.h" even without the .h

any way .... I tried to make the program step by step .......
i drove me crazy ........... ,but finally i got it working ........

but there is still something missing

there is a class called "Client"

when i declare an object of it ...... it works nicely ......
 
Client c("sky walker" , 10 , 10 ) ;


but when i declare 2 objects it breaks down and gives me this msg

"Unhandled exception in skywalker.exe: 0xC00000FD: Stack Overflow."

even worse .......
if i declare 2 objects with defalt constructor ..... it works .............

what can i do . ???????




I compiled the main.cpp on VC 2008 Express with a change to the header and that was it.

Here is the code: All I changed were the headers. I didn't even get a warning.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <string>
#include <fstream>
#include <Math.h>
#include<conio.h>
using namespace std;

/* bla bla bla */

int main()
{
return 0;
}


I didn't bother to test main1.cpp because the main function was not set up but main.cpp works flawlessly.
what about the errors and warings i see in "console MS C++6" ?
Personally, I think you should tell your teacher your code is standard-compliant, and it's them who should change compilers. VC++ 6.0 is very old.

But if you want to convert your code to something that VC++ 6.0 can compile, here's how:
1. Use old style headers. That is, iostream.h instead of iostream, stdlib.h instead of cstdlib, etc.
2. Watch out for variable scope:
1
2
3
4
5
6
7
8
9
10
11
12
//Illegal in VC++ 6.0 (undeclared variable), illegal in MinGW (undeclared variable).
for (a;/**/);

for (int a;/**/);
//In MinGW, a goes out of scope when the for finishes. VC++ 6.0, a remains in
//scope, so...

//Legal in MinGW, illegal in VC++ 6.0 (double declaration).
for (int a;/**/);

//Legal in VC++ 6.0, illegal in MinGW (undeclared variable).
for (a;/**/);

3. IIRC, VC++ 6.0 didn't have the std namespace, yet, so if you're using members of std, for example:
std::cout <<"Hello, World!"<<std::endl;
You'd have to rewrite that as
cout <<"Hello, World!"<<endl;
If you're using using namespace, it will at most give you an error saying that namespace doesn't exist. Just comment that line and you're good to go.
I'm sorry to say ............ nothing works ..........

MS C++6 drives me crazy .............. it seems to me like they changed the syntax .... ............... this is not legal ......... how could they do thigs like these ........

now I have one of them working (with the declaring 2 objects of Client problem)
and the other is still giving me the error msg "<< operator is ambiguous" problem


what to do .........
Last edited on
Tell your teacher to get a new compiler.

I have a similar problem with my teacher. We use a version of Dev-C++ that is from 2000.

You could try including <istream> and <ostream>.
Last edited on
You could try including <istream> and <ostream>.




I did ........... but didn't work ...............
Post the code you're trying to compile with VC++ 6.0.
Pages: 12