Форум АНТИЧАТ

Форум АНТИЧАТ (https://forum.antichat.xyz/index.php)
-   С/С++, C#, Delphi, .NET, Asm (https://forum.antichat.xyz/forumdisplay.php?f=24)
-   -   Помогите разобраться с ошибками (https://forum.antichat.xyz/showthread.php?t=121295)

Mozy 18.05.2009 23:58

Помогите разобраться с ошибками
 
Мне очень срочно надо что бы программа работала
написана на Visual С++

Код:

#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <fstream>
#include <string>
#include <io.h>
using namespace std;

void my_enter(void);
void my_display(void);
void my_delete_record(void);
void my_edit(void);
void my_sort(void);

 char filename[100];

struct rabochi
{
    char fio[24];
    int Monday,Tuesday,Wednesday,Thursday,Friday,Saturday;
    int nomer;
    int sr;
}r[100];

int main()
{
        char c=0;
        cout << "Enter filename" << endl;
        cin >> filename;
        system("cls");
        while(c!='q')
        {
                cout<<"1 - Enter new."<<endl;
                cout<<"2 - Display."<<endl;
                cout<<"3 - Delete record."<<endl;
                cout<<"4 - Edit Record."<<endl;
                cout<<"5 - Problem part."<<endl;
                cout<<"q - Quit."<<endl;
                cin>>c;
                system("cls");
                switch(c)
                {
                        case '1':
                            my_enter();
                            break;
                        case '2':
                            my_display();
                            break;
                        case '3':
                            my_delete_record();
                            break;
                        case '4':
                            my_edit();
                            break;
                        case '5':
                            my_sort();
                            break;
                        default:
                            break;
                }     
                }
}

void my_enter(void)
{
char vib='n';
int i=0;

fstream file;
file.open(filename, ios::app);
       
        if (!file)
        {
            cerr<<"TRY OPEN FILE \""<<filename<<"\" GET ERROR!"<<endl;
           
        }

        do{
        i++;
        r[i].nomer=i;
        cout<<"Enter FIO: "<<endl;
                cin >> r[i].fio;
        cout<<"Enter the amount of detail collected on Monday"<<endl;
        cin>>r[i].Monday;
        cout<<"Enter the amount of detail collected on Tuesday"<<endl;
        cin>>r[i].Tuesday;
        cout<<"Enter the amount of detail collected on Wednesday"<<endl;
        cin>>r[i].Wednesday;
        cout<<"Enter the amount of detail collected on Thursday"<<endl;
        cin>>r[i].Thursday;
        cout<<"Enter the amount of detail collected on Friday"<<endl;
        cin>>r[i].Friday;
        cout<<"Enter the amount of detail collected on Saturday"<<endl;
        cin>>r[i].Saturday;

        file<<r[i].nomer<<" "<<r[i].fio<<" "<<r[i].Monday<<" "<<r[i].Tuesday<<" "<<r[i].Wednesday<<" "<<r[i].Thursday<<" "<<r[i].Friday<<" "<<r[i].Saturday<<endl;
        cout << "What's all(y/n)?" << endl;
                  cin >> vib;
        }while(vib == 'y');

        file.close();
               
     
}
   
void my_display(void)
{
        int i=0;

        ifstream file;
        file.open(filename);
       
        if (!file)
        {
            cout<<"TRY OPEN    FILE \""<<filename<<"\"! GET ERROR!"<<endl;
       
        }

        cout <<"============================================================================\n";
        cout <<"|        FIO        |Monday|Tuesday|Wednesday|Thursday|Friday|Saturday    |\n";
        cout <<"============================================================================\n";
        while(!file.eof())
        {   
            i++;
            file>>r[i].fio>>r[i].Monday>>r[i].Tuesday>>r[i].Wednesday>>r[i].Thursday>>r[i].Friday>>r[i].Saturday;
            cout<<"|"<<setw(10)<<
            r[i].fio<<setw(10)<<
            "|"<<setw(4)<<
            r[i].Monday<<setw(4)<<
            "|"<<setw(4)<<
            r[i].Tuesday<<setw(4)<<
            "|"<<setw(4)<<
            r[i].Wednesday<<setw(4)<<
            "|"<<setw(4)<<
            r[i].Thursday<<setw(4)<<
            "|"<<setw(4)<<
            r[i].Friday<<setw(4)<<
            "|"<<setw(4)<<
            r[i].Saturday<<setw(4)<<
            "|\n";
            cout << "=========================================================================\n";
        }
        file.close();
               
     
}

void my_delete_record(void)
{
    int i=0,j;
    char del='n';

    fstream file;
    file.open(filename, ios::app);
       
        if (!file)
        {
            cerr<<"TRY OPEN FILE \""<<filename<<"\" GET ERROR!"<<endl;
         
                }

        do{
    cout << "Enter number of worker" << endl;
    cin >> i;
   
    file >> r[i].nomer>>r[i].fio>>r[i].Monday>>r[i].Tuesday>>r[i].Wednesday>>r[i].Thursday>>r[i].Friday>>r[i].Saturday;
   
    r[i].nomer=' ';
        for (j=0;j<=23;j++){
                r[i].fio[j]=' ';}
    r[i].Monday=' ';
    r[i].Tuesday=' ';
    r[i].Wednesday=' ';
    r[i].Thursday=' ';
    r[i].Friday=' ';
    r[i].Saturday=' ';

    file << r[i].nomer
                << r[i].fio
                << r[i].Monday
                << r[i].Tuesday
                << r[i].Wednesday
                << r[i].Thursday
                << r[i].Friday
                << r[i].Saturday;

    cout << "Record deleted" << endl;
    cout << "What's all?(y/n)" << endl;
    }while(del == 'y');

    file.close();
       
}

void my_edit(void)
{   
        int i=0;
        char del='n';
   
    fstream file;
    file.open(filename, ios::app);
       
        if (!file)
        {
            cerr<<"TRY OPEN FILE \""<<filename<<"\" GET ERROR!"<<endl;
           
                }

        do{
    cout << "Enter number of worker" << endl;
    cin >> i;
   
    file >>r[i].nomer>>r[i].fio>>r[i].Monday>>r[i].Tuesday>>r[i].Wednesday>>r[i].Thursday>>r[i].Friday>>r[i].Saturday;
   
    cout << r[i].nomer<<" "<<r[i].fio<<" "<<r[i].Monday<<" "<<r[i].Tuesday<<" "<<r[i].Wednesday<<" "<<r[i].Thursday<<" "<<r[i].Friday<<" "<<r[i].Saturday;

        cout<<"Enter FIO: "<<endl;
        cin>>r[i].fio;
        cout<<"Enter the amount of detail collected on Monday"<<endl;
        cin>>r[i].Monday;
        cout<<"Enter the amount of detail collected on Tuesday"<<endl;
        cin>>r[i].Tuesday;
        cout<<"Enter the amount of detail collected on Wednesday"<<endl;
        cin>>r[i].Wednesday;
        cout<<"Enter the amount of detail collected on Thursday"<<endl;
        cin>>r[i].Thursday;
        cout<<"Enter the amount of detail collected on Friday"<<endl;
        cin>>r[i].Friday;
        cout<<"Enter the amount of detail collected on Saturday"<<endl;
        cin>>r[i].Saturday;

    file << r[i].nomer
                << r[i].fio
                << r[i].Monday
                << r[i].Tuesday
                << r[i].Wednesday
                << r[i].Thursday
                << r[i].Friday
                << r[i].Saturday;

    cout << "Record edited" << endl;
    cout << "What's all?(y/n)" << endl;
    }while(del == 'y');

    file.close();
 
}


void my_sort(void)
{
    int i=0;
    int max=0;
   
    fstream file;
    file.open(filename, ios::app);
       
        if (!file)
        {
            cerr<<"TRY OPEN FILE \""<<filename<<"\" GET ERROR!"<<endl;
         
        }

        while(! file.eof()){
            i++;

            file>>r[i].nomer>>r[i].fio>>r[i].Monday>>r[i].Tuesday>>r[i].Wednesday>>r[i].Thursday>>r[i].Friday>>r[i].Saturday;
           
            r[i].sr=(r[i].Monday+r[i].Tuesday+r[i].Wednesday+r[i].Thursday+r[i].Friday+r[i].Saturday)/6;
           
            if(r[i].sr > max){
                max=r[i].sr;
            }
            }
            i=0;

        while(! file.eof()){
            i++;
           
            file>>r[i].nomer>>r[i].fio>>r[i].sr>>r[i].Monday>>r[i].Tuesday>>r[i].Wednesday>>r[i].Thursday>>r[i].Friday>>r[i].Saturday;

            if (r[i].sr == max)
                exit(1);
        }

        if(r[i].Monday>r[i].Tuesday && r[i].Monday>r[i].Wednesday && r[i].Monday>r[i].Thursday && r[i].Monday>r[i].Friday && r[i].Monday>r[i].Saturday){
            cout << "More details of all made " << r[i].fio << " a day when he reached the highest productivity is Monday";
        }
        if(r[i].Tuesday>r[i].Monday && r[i].Tuesday>r[i].Wednesday && r[i].Tuesday>r[i].Thursday && r[i].Tuesday>r[i].Friday && r[i].Tuesday>r[i].Saturday){
            cout << "More details of all made " << r[i].fio << " a day when he reached the highest productivity is Tuesday";
        }
        if(r[i].Wednesday>r[i].Monday && r[i].Wednesday>r[i].Thursday && r[i].Wednesday>r[i].Friday && r[i].Wednesday>r[i].Saturday){
            cout << "More details of all made " << r[i].fio << " a day when he reached the highest productivity is Wednesday";
        }
        if(r[i].Thursday>r[i].Monday && r[i].Thursday>r[i].Wednesday && r[i].Thursday>r[i].Friday && r[i].Thursday>r[i].Saturday){
            cout << "More details of all made " << r[i].fio << " a day when he reached the highest productivity is Thursday";
        }
        if(r[i].Friday>r[i].Monday && r[i].Friday>r[i].Wednesday && r[i].Friday>r[i].Thursday && r[i].Friday>r[i].Saturday){
            cout << "More details of all made " << r[i].fio << " a day when he reached the highest productivity is Friday";
        }
        if(r[i].Saturday>r[i].Monday && r[i].Saturday>r[i].Wednesday && r[i].Saturday>r[i].Thursday && r[i].Saturday>r[i].Friday){
            cout << "More details of all made " << r[i].fio << " and day when he reached the highest productivity is Saturday";
        }
       
               
}

А я почти разобрался во всём :D

Feonor 19.05.2009 12:17

У тебя не хватает одной '}' в самом конце. Поставь и перекомпили, может и все ошибки из за этого.

Gar|k 19.05.2009 16:54

ну как по мне тут у тебя ваще все не правильно )

bool my_enter(char *filename);
bool my_display(char *filename);
bool my_delete_record(char *filename);
bool my_edit(char *filename);
bool my_sort(char *filename);

соотвественно надо переделать в тех функциях
а в функциях котрые вызывают их надо писать типа my_enter(&filename);

а скобочка хз мож где не закрыл или не так скопировал )

razb 19.05.2009 17:16

Сначала взялся исправлять а потом плюнул на это дело тк ошибки в КАЖДОЙ строке.
Советую перечитать учебник по С\С++ минимум раза 3.

Kaimi 19.05.2009 18:46

Цитата:

но мне срочно надо сдать эту работу,что посоветуете,кроме прочтения заново книги?
Закажи у кого-нибудь в соответствующем разделе


Время: 13:00