,   CyberForum.ru

getch() - C++

 
:  :  - 29,   - 4.86
fuzzytoozy
8 / 8 / 1
: 23.11.2012
: 94
18.02.2013, 19:14     getch() #1
! : getch(), main , employee, add() getch(), . , enter, , . !
:
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
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#include <windows.h>
#include <fstream>
#include <iostream>
#include <typeinfo>
#include <process.h>
#include <conio.h>
using namespace std;
 
//---------------------------------------------------------------------------
const int LEN = 32;
const int MAXEM = 100;
enum employee_type { tmanager, tscientist, tlaborer };
char buf[256];
//---------------------------------------------------------------------------
char* Rus ( const char* text )
{
 CharToOem ( text, buf );
 return buf;
}
//---------------------------------------------------------------------------
class employee
{
 private:
  char name[LEN];
  unsigned long number;
  static int n;
  static employee* arrap[];
 
 public:
  virtual void getdata()
  {
   cin.ignore(10, '\n');
   cout << Rus ( "\n Ââåäèòå ô*ìèëèþ: " );
   cin >> name;
   cout << Rus ( "\n Ââåäèòå *îìåð: ");
   cin >> number;
  }
//---------------------------------------------------------------------------
  virtual void putdata()
  {
   cout << Rus("\n Ô*ìèëèÿ: "); cout << name;
   cout << Rus ("\n Íîìåð: "); cout << number;
  }
//---------------------------------------------------------------------------
  virtual employee_type get_type();
  static void add();
  static void display();
  static void read();
  static void write();
};
//---------------------------------------------------------------------------
int employee :: n;
employee* employee :: arrap[MAXEM];
//---------------------------------------------------------------------------
class manager : public employee
{
 private:
  char tittle[LEN];
  double dues;
 
 public:
  void getdata()
  {
   employee :: getdata ( );
   cout << Rus ( "\n Ââåäèòå òèòóë: " ); cin >> tittle;
   cout << Rus ( "\n Ââåäèòå **ëîãè: "); cin >> dues;
  }
//---------------------------------------------------------------------------
  void putdata()
  {
   employee :: putdata( );
   cout << Rus("\n Òèòóë: "); cout << tittle;
   cout << Rus("\n Í*ëîãè ãîëüô-êëóá*: "); cout << dues;
  }
};
//---------------------------------------------------------------------------
class scientist : public employee
{
 private:
  int pubs;
 
 public:
  void getdata()
  {
   employee :: getdata ();
   cout << Rus("\n Ââåäèòå ÷èñëî ïóáëèê*öèé: "); cin >> pubs;
  }
//---------------------------------------------------------------------------
  void putdata()
  {
   employee :: putdata();
   cout << Rus ( "\n ×èñëî ïóáëèê*öèé: " ); cout << pubs;
  }
};
//---------------------------------------------------------------------------
class laborer : public employee
{
};
//---------------------------------------------------------------------------
  void employee :: add ( )
  {
   char ch;
   cout << Rus ( "\n Ââåäèòå: " );
   cout << Rus ( "\n 'm' äëÿ äîá*âëå*èÿ ìå*åäæåð* ");
   cout << Rus ( "\n 's' äëÿ äîá*âëå*èÿ ó÷å*îãî " );
   cout << Rus ( "\n 'l' äëÿ äîá*âëå*èÿ ð*áî÷åãî " );
   ch = getch(); // âîò î* ïðîáëåì*ûé getch()
 
   switch(ch)
   {
    case 'm': arrap[n] = new manager; break;
    case 's': arrap[n] = new scientist; break;
    case 'l': arrap[n] = new laborer; break;
    default: cout << Rus ( "\n Íåèçâåñò*ûé òèï ð*áîò*èê* \n" ); return;
   }
   arrap[n++]->getdata();
  }
//---------------------------------------------------------------------------
  void employee :: display ()
  {
   for(int j = 0; j < n; j++ )
   {
    cout << Rus( "\n Ð*áîò*èê: ") << ( j+1 );
    switch( arrap[j]->get_type() )
    {
     case tmanager: cout << Rus ( "\n Òèï: Ìå*åäæåð" ); break;
     case tscientist: cout << Rus ( "\n Òèï: Ó÷å*ûé" ); break;
     case tlaborer: cout << Rus ("\n Òèï: Ð*áî÷èé" ); break;
     default: cout <<Rus("\n Íåèçâåñòû*é òèï");
    }
    arrap[j]->putdata();
    cout << endl;
   }
  }
//---------------------------------------------------------------------------
  employee_type employee::get_type()
  {
   if( typeid(*this) == typeid(manager) )
   return tmanager;
   else if ( typeid(*this) == typeid(scientist) )
   return tscientist;
   else if ( typeid(*this) == typeid(laborer) )
   return tlaborer;
   else
    { cerr << Rus ( "\n Íåïð*âèëü*ûé òèï ð*áîò*èê*"); exit(1); }
   return tmanager;
  }
//---------------------------------------------------------------------------
  void employee :: write()
  {
   int size;
   cout << Rus ( "\n Èäåò ç*ïèñü " ); cout << n << Rus ("\n ð*áîò*èêîâ.\n");
   ofstream ouf;
   employee_type etype;
   ouf.open("EMPLOY.DAT", ios::trunc|ios::binary);
   if(!ouf)
    { cout << Rus ( "\n Íåâîçìîæ*î îòêðûòü ô*éë\n"); return; }
   for (int j = 0; j < n; j++ )
   {
    etype = arrap[j]->get_type();
    ouf.write((char*)&etype,sizeof(etype));
    system("PAUSE");
 
    switch(etype)
    {
     case tmanager: size = sizeof(manager); break;
     case tscientist: size = sizeof(scientist); break;
     case tlaborer: size = sizeof(laborer); break;
    }
    ouf.write( (char*)(arrap[j]), size );
    if(!ouf)
    { cout << Rus("\nÇ*ïèñü â ô*éë *åâîçìîæ**\n"); return; }
   }
  }
//---------------------------------------------------------------------------
  void employee :: read()
  {
   int size;
   employee_type etype;
   ifstream inf;
   inf.open("EMPLOY.DAT", ios::binary);
 
   if(!inf)
   { cout << Rus("\n Íåâîçìîæ*î îòêðûòü ô*éë!"); return; }
   n = 0;
 
   while(true)
   {
    inf.read( (char*)&etype, sizeof(etype) );
    if( inf.eof() )
    break;
 
    if(!inf)
    { cout << Rus("\n Íåâîçìîæ*î ÷òå*èå òèï*\n"); return ;}
    switch(etype)
    {
     case tmanager:
      arrap[n] = new manager;
      size = sizeof(manager);
      break;
     case tscientist:
      arrap[n] = new scientist;
      size = sizeof(scientist);
      break;
     case tlaborer:
      arrap[n] = new laborer;
      size = sizeof(laborer);
      break;
     default: cout << Rus ( "\n Íåèçâåñò*ûé òèï â ô*éëå\n"); return;
    }
    inf.read( (char*)arrap[n], size );
    if(!inf)
    { cout << Rus("\n ×òå*èå ä***ûõ èç ô*éë* *åâîçìîæ*î\n"); return; }
    n++;
    }
   cout << Rus ( "\n Èäåò ÷òå*èå "); cout << n << Rus(" ð*áîò*èêîâ\n");
  }
//---------------------------------------------------------------------------
int main(int argc, char* argv[])
{
 char ch;
 while(true)
 {
  cout << Rus ("\n 'a' - äîá*âëå*èå ä***ûõ î ð*áîò*èêå" );
  cout << Rus ( "\n 'd' - âûâåñòè ñâåäå*èÿ îáî âñåõ ð*áîò*èê*õ" );
  cout << Rus ( "\n 'w' - ç*ïèñ*òü âñå ä***ûå â ô*éë" );
  cout << Rus ( "\n 'r' - ïðî÷èò*òü âñå ä***ûå èç ô*éë*" );
  cout << Rus ( "\n 'x' - âûõîä \n" );
  ch = getch(); // ýòîò getch ð*áîò*åò *îðì*ëü*î
 switch(ch)
 {
  case 'a':
   employee :: add(); break;
  case 'd':
   employee:: display(); break;
  case 'w':
   employee :: write(); break;
  case 'r':
   employee :: read(); break;
  case 'x': exit(0);
  default: cout << Rus ( "\n Íåèçâåñò**ÿ êîì**ä*");
 }
 }
        return 0;
}
//---------------------------------------------------------------------------
Similar
41792 / 34177 / 6122
: 12.04.2006
: 57,940
18.02.2013, 19:14     getch()
:

getch(), char *name; C++
getch C++
getch C++
getch C++
C++ getch()
.
ITcrusader
C++
   ITcrusader
176 / 162 / 8
: 12.02.2013
: 410
18.02.2013, 19:57     getch() #2
cin.ignore(10, '\n');
,

C++
1
2
3
4
5
6
7
8
virtual void getdata()
  {
   cin.ignore(10, '\n');
   cout << Rus ( "\n  : " );
   cin >> name;
   cout << Rus ( "\n  : ");
   cin >> number;
  }
fuzzytoozy
8 / 8 / 1
: 23.11.2012
: 94
18.02.2013, 20:36  []     getch() #3
. ?
ITcrusader
C++
   ITcrusader
176 / 162 / 8
: 12.02.2013
: 410
18.02.2013, 20:49     getch() #4
, . ignore . - ))) , ?)
fuzzytoozy
8 / 8 / 1
: 23.11.2012
: 94
18.02.2013, 21:42  []     getch() #5
. . () . , cin.ignore( 10, '\n' ); 10 '\n'. . , .
ITcrusader
C++
   ITcrusader
176 / 162 / 8
: 12.02.2013
: 410
18.02.2013, 21:51     getch() #6
, , , http://www.cplusplus.com/reference/i...stream/ignore/

( ) , , , 2 , . , /))) . , , , . , , , stream'))))) , )

, , , - ))) 3D Max - ( ) , , ))))))))
MoreAnswers
37091 / 29110 / 5898
: 17.06.2006
: 43,301
18.02.2013, 21:57     getch()
:

C++ getch()
getch() C++
getch C++



:
fuzzytoozy
8 / 8 / 1
: 23.11.2012
: 94
18.02.2013, 21:57  []     getch() #7
. , , . , , =) .
Yandex
18.02.2013, 21:57     getch()

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