,   CyberForum.ru

- C++

 
Vadim8063
1 / 1 / 0
: 17.01.2012
: 130
22.11.2012, 13:48     #1
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdio.h>
/*
 * No description
 */
class Action
{
    private:
  int n;
  TStud *mas;
 public:
  int GetN() {return n;}
  Action( int ); 
  ~Action();
  void Clear(){ n=0; };
  void Add(TStud);
  void ToFile();
  void FromFile(char*);
  void Obrab_Fac();
  void Obrab_Gr();
  void Sort_Spis();
  void ToScreen();
 
};
C++
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
#include "action.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
 // class's header file
using namespace std;
// class constructor
Action::Action(int nn)
{  n=0; mas=new TStud[nn]; }
//------------------------------------------------------------
Action::~Action()
{  delete [] mas; n=0; }
 
void Action::Add(TStud stud)
{  *(mas+n)= stud; n++; }
 //------------------------------------------------------------
void Action::ToFile()
{
  ofstream zap("Spisok.txt");
  if(!zap) 
  {
     cout<<"nevozmozno otkrit fale lkz zapisi.Nazmite lubyy klavishy...";
     getch();  exit(1);
  };
  zap<<n<<endl;
  for(int i=0; i<n; i++)  zap<<*(mas+i);
  zap.close();
  clrscr();
  cout<<"Ââîä ä***ûõ ç*êî*÷å* "<<
   "("<<GetN()<<" zap)"<<" Nazmite lubyy klavishy..."; getch();
}
//------------------------------------------------------------
void Action::FromFile(char *fname)
{
  int nn; TStud stud;
  ifstream chten(fname, ios::in|ios::nocreate);
  if(!chten)
    {
    cout<<endl<<"*åâîçìîæ*î îòêðûòü ô*éë äëÿ ÷òå*èÿ.Í*æìèòå ëþáóþ êë*âèøó...";
    getch();  exit(1);
  }
  Clear();
  chten>>nn;
  for(int i=0; i<nn; i++)
  {
    chten>> stud;
    system("cls");
    cout<< stud; getch();
    Add(stud);
  };
  chten.close();
  clrscr();
  cout<<"Ñ÷åò ç*âåðøå*. Í*æìèòå ëþáóþ êë*âèøó..";
}
//------------------------------------------------------------
void Action::Obrab_Fac()
{
  char sh_fac[3];
  int stud=0, propusk=0;
  float  stud_propusk=0;
  TStud *ptr;
  cout<<" ââåäèòå øèôð ô*êóëüòåò*:";
  cin>> sh_fac;
  for(int i=0; i<n; i++)
  {
    ptr=(mas+i);
    if(strcmp(ptr->Shifr_Fac, sh_fac)==0)
    {
      stud+=ptr->kol_stud;
      propusk+=ptr->prop;
      stud_propusk+=(ptr->prop - ptr->uv_prop);
    }
   }
  if (stud!=0)
  {
   stud_propusk=float (stud_propusk/stud);
    system("cls");
    cout<<"  È*ôîðì*öèÿ ïî ô*êóëüòåòó "<<sh_fac<<": "<<endl;
    cout<<"  îáùåå êîëè÷åñòâî ñòóäå*òîâ : "<< stud<<endl;
    cout<<"  Îáùåå êîëè÷åñòâî ïðîïóùå*ûõ ÷*ñîâ: "<< propusk<<endl;
    cout<<"  Ñðåä*åå êîëè÷åñòâî ïðîïóùå*ûõ ÷*ñîâ ** îä*îãî ñòóäå*ò*:
     "<< stud_propusk<<endl;
  }
  else cout<<"Ò*êîé ô*êóëüòåò *å **éäå*"<<endl;
  getch();
}
//------------------------------------------------------------
void Action::Obrab_Gr()
{
  TStud *ptr; int max=0, imax=0;
  if(n>0)
  {
    for(int i=0; i<n; i++)
    {
      ptr=(mas+i);
      if (ptr->uv_prop>max)
      { imax=i; max=ptr->uv_prop; }
     }
   cout<<" Ñâåäå*èÿ î ãðóïïå, èìåþùåé ì*êñ. êîë-âî ïðîïóñêîâ ïî óâ. ïðè÷è*å:"   <<endl;
  cout<<*(mas+imax);
  getch();
 }
}
//------------------------------------------------------------
void Action::Sort_Spis()
{
  TStud tmp, *ptr1, *ptr2;
  if(n>0)
  {
     L1:
     for(int i=0; i<n-1; i++)
     {  ptr1=(mas+i); ptr2=(mas+i+1);
     if (ptr2->prop> ptr1->prop)
      { tmp=*ptr2; *ptr2=*ptr1; *ptr1=tmp; goto L1; }
      }
   }
}
//------------------------------------------------------------
void Action::ToScreen()
{
  int i=0; char ch;
  do
  {
   system("cls");
    cout<<"--- " <<i+1<<"-*ÿ ç*ïèñü èç "<< GetN() <<" ----"<<endl;
    cout<<*(mas+i)<<endl;
    ch=getch();
    switch(ch)
    {
      case 0:   ch=getch();
      case 72: if (i==0) i=GetN()-1; else i--; break;  // **æìèòå  Page Up
      case 80: if (i==GetN()-1) i=0; else i++;           //**æìèòå Page Down
    }
  } while(ch!=27);      // âûõîä ïî **æ*òèþ Esc
}
C++
1
2
3
4
5
6
7
8
9
10
11
12
class TStud
{
private:
    char Shifr_Fac[3], Name_Fac[4], Shifr_Gr[6];
    int kol_stud;
    int prop;
    int uv_prop;
  friend istream& operator >> (istream&, TStud&);
  friend ostream& operator << (ostream&, TStud&);
 public:
  friend class Action;
};
C++
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 "tstud.h" // class's header file
 
// class constructor
istream& operator >> (istream& s, TStud & A)
{
 cout<<"ââåäèòå øèôð ô*êóëüòåò*: "; s>>A.Shifr_Fac;
 cout<<" ââåäèòå **çâ**èå ô*êóëüòåò*: "; s>>A.Name_Fac;
 cout<<" ââåäèòå øèôð ãðóïïû: "; s>>A.Shifr_Gr;
 cout<<" ââåäèòå êîëè÷åñòâî ñòóäå*òîâ â ãðóïïå"; s>>A.kol_stud;
 cout<<" ââåäèòå îáùåå êîëè÷åñòâî ïðîïóñêîâ â ãðóïïå"; s>>A.prop;
 cout<<" ââåäèòå êîëè÷åñòâî ïðîïóñêîâ ïî óâ*æèòåëü*îé ïðè÷è*å"; s>>A.uv_prop;
 return s;
}
//------------------------------------------------------------
ostream& operator << (ostream& s, TStud& A)
{
 cout<<" øèôð ô*êóëüòåò*: "; s<<setw(2)<<A.Shifr_Fac<<endl;
 cout<<" **çâ**èå ô*êóëüòåò*: "; s<<setw(3)<<A.Name_Fac<<endl;
 cout<<" øèôð ãðóïïû: "; s<<setw(5)<<A.Shifr_Gr<<endl;
 cout<<" êîëè÷åñòâî ñòóäå*òîâ â ãðóïïå: "; s<<A.kol_stud<<endl;
 cout<<" îáùåå êîëè÷åñòâî ïðîïóñêîâ â ãðóïïå: "; s<<A.prop<<endl;
 cout<<" êîëè÷åñòâî ïðîïóñêîâ ïî óâ*æèòåëü*îé ïðè÷è*å: "; s<<A.uv_prop<<endl;
 return s;
}
C++
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
#include <windows.h>
#include <cstdlib>
#include <iostream>
#include <conio.h>
#include "tstud.h"
#include "action.h"
using namespace std;
void gotoxy(int xpos, int ypos)
{
  COORD scrn;    
 
  HANDLE hOuput = GetStdHandle(STD_OUTPUT_HANDLE);
 
  scrn.X = xpos; scrn.Y = ypos;
 
  SetConsoleCursorPosition(hOuput,scrn);
}
void Gl_Menu()
{
  system("cls");
  gotoxy(33,11); cout<<"1 - ââîä *îâûõ ä***ûõ";
  gotoxy(33,12); cout<<"2 - ïðîñìîòð";
  gotoxy(33,13); cout<<"3 - è*ôîðì*öèÿ î ô*êóëüòåòå";
  gotoxy(33,14); cout<<"4 - è*ôîðì*öèÿ î ãðóïïå";
  gotoxy(33,15); cout<<"Esc - âûõîä";
}
//------------------------------------------------------------
void Menu_1()
{
  system("cls");
  gotoxy(33,11); cout<<"1 - c êë*âè*òóðû";
  gotoxy(33,12); cout<<"2 - èç ô*éë*";
}
 
int main(int argc, char *argv[])
{
    char ch,ch1, *file_n;
  Action Act(20); 
  TStud stud;
  do
  {
   system("cls");
   Gl_Menu();
   ch=getch();
   switch(ch)
   {
     case '1':
      Menu_1();
      ch1=getch();
      switch(ch1)
             {
        case '1':
          system("cls");
          cin>> stud;
              Act.Add(stud);
          break;
        case '2':
           system("cls"); cout<<"ââåäèòå èìÿ ô*éë* ";
          cin>>file_n;
          Act.FromFile(file_n);
           break;
      };
        break;
     case '2':
       system("cls");
       if(Act.GetN()>0) Act .ToScreen();
       break;
     case '3':
       system("cls"); 
       Act.Obrab_Fac();
       break;
     case '4':
       system("cls"); 
       Act.Obrab_Gr();
       break;
    };
  }while(ch!=27);
 if (Act.GetN()>0) 
      { Act.Sort_Spis();  Act.ToFile(); }
    system("PAUSE");
    return EXIT_SUCCESS;
}
Action.h TStud *mas;
Similar
41792 / 34177 / 6122
: 12.04.2006
: 57,940
22.11.2012, 13:48    
:

C++
C++
C++
C++
C++
.
David Sylva
   David Sylva
1281 / 943 / 51
: 17.05.2012
: 2,686
22.11.2012, 13:51     #2
.
Vadim8063
1 / 1 / 0
: 17.01.2012
: 130
22.11.2012, 16:26  []     #3
mas=new TStud[nn];

1 1
mas

20
13 C:\Dev-Cpp\action.h ISO C++ forbids declaration of `TStud' with no type

1 6
3
MrGluck
 ++
   MrGluck
4920 / 2663 / 243
: 29.11.2010
: 7,419
22.11.2012, 16:32     #4
Action , TStud, .
Vadim8063
1 / 1 / 0
: 17.01.2012
: 130
22.11.2012, 16:33  []     #5
?
MrGluck
 ++
   MrGluck
4920 / 2663 / 243
: 29.11.2010
: 7,419
22.11.2012, 16:34     #6
#include "tstud.h" action.h .

. .h
Vadim8063
1 / 1 / 0
: 17.01.2012
: 130
22.11.2012, 16:38  []     #7
void Clear(){ n=0; }; cpp. ...

1
17 C:\Dev-Cpp\tstud.h ISO C++ forbids declaration of `istream' with no type
MrGluck
 ++
   MrGluck
4920 / 2663 / 243
: 29.11.2010
: 7,419
22.11.2012, 16:41     #8
Vadim8063
void Clear(){ n=0; }; cpp. ...

1
17 C:\Dev-Cpp\tstud.h ISO C++ forbids declaration of `istream' with no type
.. , ?

istream ostream . std::ifstream, using namespace std;
Vadim8063
1 / 1 / 0
: 17.01.2012
: 130
22.11.2012, 16:49  []     #9
using namespace std;

17 C:\Dev-Cpp\tstud.h `istream' is neither function nor member function; cannot be declared friend
17 C:\Dev-Cpp\tstud.h expected `;' before '&' token
18 C:\Dev-Cpp\tstud.h ISO C++ forbids declaration of `ostream' with no type
18 C:\Dev-Cpp\tstud.h `ostream' is neither function nor member function; cannot be declared friend
18 C:\Dev-Cpp\tstud.h expected `;' before '&' token
23 C:\Dev-Cpp\action.cpp variable `std::ofstream zap' has initializer but incomplete type

4
include fstream
40 C:\Dev-Cpp\action.cpp `nocreate' is not a member of `std::ios'
MrGluck
 ++
   MrGluck
4920 / 2663 / 243
: 29.11.2010
: 7,419
22.11.2012, 17:11     #10
Vadim8063
40 C:\Dev-Cpp\action.cpp `nocreate' is not a member of `std::ios'
, ios::nocreate .
Vadim8063
1 / 1 / 0
: 17.01.2012
: 130
22.11.2012, 17:21  []     #11
?
MrGluck
 ++
   MrGluck
4920 / 2663 / 243
: 29.11.2010
: 7,419
22.11.2012, 17:22     #12
Vadim8063
?
, . . - .
Vadim8063
1 / 1 / 0
: 17.01.2012
: 130
22.11.2012, 17:27  []     #13
,,, if
MrGluck
 ++
   MrGluck
4920 / 2663 / 243
: 29.11.2010
: 7,419
22.11.2012, 17:28     #14
Vadim8063
,,, if
""
MoreAnswers
37091 / 29110 / 5898
: 17.06.2006
: 43,301
22.11.2012, 17:42    
:

C++
C++
C++



:
Vadim8063
1 / 1 / 0
: 17.01.2012
: 130
22.11.2012, 17:42  []     #15
C++
1
2
3
4
5
6
file = fopen( fname, "r" );
if( file != 0 )
{
fgets( load_string, 50 , file );
cout << "load_string = " << load_string << endl;
}
׸

5
C++
1
2
3
4
5
if(!chten.is_open())
    {
    cout<<endl<<"*åâîçìîæ*î îòêðûòü ô*éë äëÿ ÷òå*èÿ.Í*æìèòå ëþáóþ êë*âèøó...";
    getch();  exit(1);
  }
Yandex
22.11.2012, 17:42    

: 11:56. GMT +3.
- , ,
-
Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2016, vBulletin Solutions, Inc.
@Mail.ru