Documentos de Académico
Documentos de Profesional
Documentos de Cultura
// All_tasks.cpp
C++ program: gather all tasks
programmers
Prepared By:
Khalid Waleed
C A N A HIGHER
L HIGHER IN
STITUTE OF EN
G I N ENGINEERING
EERING & TECHNOLO
CANAL
INSTITUTE
OF
&G Y
TECHNOLOGY
1|Page
1: // All_tasks.cpp
2: // gather all tasks programmers
3: #include <iostream>
4: #include <iomanip>
5: using namespace std;
6: void error(int &);
7: void line();
8: void sizes();
9: void numbers();
10: void factorial();
11: void daycalc();
12: int main()
13: {
14: int q; char Y;
15: do
16: {
17: line();
18: cout << setw(30)<<"khalid's projects"<< endl;
19: line();
20: cout <<"1- sizes.cpp"<< setw(25)<<"2- numbers.cpp"<< endl;
21: cout <<"3- factorial.cpp"<< setw(28)<<"4- daycalculation.cpp"<< endl;
22: line();
23: cout <<"Enter number of programme to open: ";
24: cin >> q;
25: error(q);
26: switch(q)
27: {
28:
case 4:
29:
cout << endl;
30:
daycalc();
31:
break;
32:
case 1:
33:
cout << endl;
34:
sizes();
35:
break;
36:
case 2:
37:
cout << endl;
38:
numbers();
2|Page
39:
break;
40:
case 3:
41:
cout << endl;
42:
factorial();
43:
break;
44:
default:
45:
cout <<"Unknown number!"<< '\n';
46: }
47: cout <<"open khalid's projects (y/n)? :";
48: cin >> Y;
49: cout << endl;
50: }while(Y == 'y');
51: return 0;
52: }
53: void sizes()
54: {
55: int x;
56: cout <<"Size of bool"<< setw(11)<<":"<< setw(6)<< sizeof(bool)<<" Byte"<< endl;
57: cout <<"Size of char"<< setw(11)<<":"<< setw(6)<< sizeof(char)<<" Byte"<< endl;
58: cout <<"Size of unsigned char :"<< setw(6)<< sizeof(unsigned char)<<" Byte"<<
endl;
59: cout <<"Size of short"<< setw(10)<<":"<< setw(6)<< sizeof(short)<<" Byte"<< endl;
60: cout <<"Size of unsigned short:"<< setw(6)<< sizeof(unsigned short)<<" Byte"<<
endl;
61: cout <<"Size of long"<< setw(11)<<":"<< setw(6)<< sizeof(long)<<" Byte"<< endl;
62: cout <<"Size of unsigned long : "<< setw(5)<< sizeof(unsigned long)<<" Byte"<<
endl;
63: cout <<"Size of int"<< setw(12)<<":"<< setw(6)<< sizeof(int)<<" Byte"<< endl;
64: cout <<"Size of unsigned int"<< setw(3)<<":"<< setw(6)<< sizeof(unsigned int)<<"
Byte"<< endl;
65: cout <<"Size of short int"<< setw(6)<<":"<< setw(6)<< sizeof(short int)<<" Byte"<<
endl;
66: cout <<"Size of long int"<< setw(7)<<":"<< setw(6)<< sizeof(long int)<<" Byte"<<
endl;
67: cout <<"Size of float"<< setw(10)<<":"<< setw(6)<< sizeof(float)<<" Byte"<< endl;
68: cout <<"Size of double"<< setw(9)<<":"<< setw(6)<< sizeof(double)<<" Byte"<<
endl;
3|Page
69:
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:
5|Page
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:
6|Page
182:
case 9:
183:
cout <<"Enter your number : ";
184:
cin >> numb;
185:
error(numb);
186:
for ( int c=2; numb>=c ; c++)
187:
{
188:
f=0;
189:
for (int j=2; j<=c/2; j++)
190:
{
191:
if (c % j ==0)
192:
{
193:
f=1;
194:
break;
195:
}
196:
}
197:
if (f==0)
198:
cout << c <<", ";
199:
}
200:
break;
201:
default:
202:
cout <<"number of process unknown !";
203:
204:
}
205:
break;
206:
default:
207:
cout <<"number of process unknown !";
208: }
209: cout <<"\nDo you want to exit the programme (y/n) ? ";
210: cin >> ask;
211:
}while(ask == 'n');
212: }
213: void daycalc()
214: {
215: int day, month, m, year, century, day_of_week;
216: char ask;
217: cout << program to show the day of the week by date \n";
218: line( );
219: cout <<"centuries availiable : 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23";
7|Page
296:
m =0;
297:
break;
298: case 6:
299:
m =3;
300:
break;
301: case 7:
302:
m =5;
303:
break;
304: case 8:
305:
m =1;
306:
break;
307: case 9:
308:
m =4;
309:
break;
310: case 10:
311:
m =6;
312:
break;
313: case 11:
314:
m =2;
315:
break;
316: case 12:
317:
m =4;
318:
break;
319: default:
320:
cout <<"Unknown month! \n";
321:
goto again;
322: }
323: cout <<"year number = "; cin >> year;
324: error(year);
325: day_of_week =( day + m + year +(year/4)+ century )%7;
326: switch(day_of_week)
327: {
328:
case 6:
329: cout <<"the day was a Saturday \n";
330:
break;
331: case 0:
332:
cout <<"the day was a Sunday \n";
333:
break;
10 | P a g e
334: case 1:
335:
cout <<"the day was a Monday \n";
336:
break;
337: case 2:
338:
cout <<"the day was a Tuesday \n";
339:
break;
340: case 3:
341:
cout <<"the day was a Wednesday \n";
342:
break;
343: case 4:
344:
cout <<"the day was a Thursday \n";
345:
break;
346: case 5:
347:
cout <<"the day was a Friday \n";
348:
break;
349: default:
350:
cout <<"ERROR!! \n";
351: }
352: again:
353: cout <<"Do you want to exit the programme (y/n)? : ";
354: cin >> ask;
355: }while(ask == 'n');
356: }
357: void error(int &x)
358: {
359: while (cin.fail())
360: {
361:
cin.clear();// clear input buffer to restore cin to a usable state
362:
cin.ignore(INT_MAX, '\n');// ignore last input
363:
cout <<"You can only enter numbers.\n";
364:
cout <<"Enter a number : ";
365:
cin >> x;
366:
}
367: }
368: void line()
369: {
370: for(int j=0; j<45; j++)
371: cout << '=';
11 | P a g e
12 | P a g e
13 | P a g e
14 | P a g e