Está en la página 1de 14

Task

// 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

CANAL HIGHER INSTITUTE OF ENGINEERING & TECHNOLOGY

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

CANAL HIGHER INSTITUTE OF ENGINEERING & TECHNOLOGY

69:

cout <<"Size of long double"<< setw(4)<<":"<< setw(6)<< sizeof(long double)<<"


Byte"<< endl;
70: cout << endl <<"write any number to exit programme: ";
71: cin >> x;
72: error(x);
73: }
74: void numbers()
75: {
76:
int process , numb , f=0;
77: char ask;
78: do{
79: cout <<" 1- ordering even numbers \n 2- ordering odd numbers\
80: \n 3- ordering prime numbers";
81: cout <<"\ninsert number of process : ";
82: cin >> process;
83: error(process);
84: switch(process)
85: {
86:
case 1:
87:
cout <<"\n 4- desending order \n 5- ascending order ";
88:
cout <<"\ninsert number of process : ";
89:
cin >> process;
90:
error(process);
91:
switch(process)
92:
{
93:
case 4:
94:
cout <<"Enter your number : ";
95:
cin >> numb;
96:
error(numb);
97:
for (numb ; numb>0;--numb)
98:
{
99:
if (numb%2==0)
100:
{
101:
cout << numb <<", ";
102:
}
103:
}
104:
break;
105:
case 5:
4|Page

CANAL HIGHER INSTITUTE OF ENGINEERING & TECHNOLOGY

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:

cout <<"Enter your number : ";


cin >> numb;
error(numb);
for (int c=1; numb>=c ; c++)
{
if (c%2==0)
{
cout << c <<", ";
}
}
break;
default:
cout <<"number of process unknown !";
}
break;
case 2:
cout <<"\n 6- desending order \n 7- ascending order ";
cout <<"\ninsert number of process : ";
cin >> process;
error(process);
switch(process)
{
case 6:
cout <<"Enter your number : ";
cin >> numb;
error(numb);
for (numb ; numb>0;--numb)
{
if (numb%2!=0)
{
cout << numb <<", ";
}
}
break;
case 7:
cout <<"Enter your number : ";
cin >> numb;
error(numb);

5|Page

CANAL HIGHER INSTITUTE OF ENGINEERING & TECHNOLOGY

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:

for (int c=1; numb>=c ; c++)


{
if (c%2!=0)
{
cout << c <<", ";
}
}
break;
default:
cout <<"number of process unknown !";
}
break;
case 3:
cout <<"\n 8- desending order \n 9- ascending order ";
cout <<"\ninsert number of process : ";
cin >> process;
error(process);
switch(process)
{
case 8:
cout <<"Enter your number : ";
cin >> numb;
error(numb);
for (numb ; numb>=2;--numb)
{
f=0;
for (int j=2; j<=numb/2; j++)
{
if (numb%j ==0)
{
f=1;
break;
}
}
if (f==0)
cout << numb <<", ";
}
break;

6|Page

CANAL HIGHER INSTITUTE OF ENGINEERING & TECHNOLOGY

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

CANAL HIGHER INSTITUTE OF ENGINEERING & TECHNOLOGY

220: cout <<"\n


***** Note: we are now in the 21st century ***** \n";
221: do
222: {
223: cout <<"please Enter the century number: ";
224: cin >> century;
225: error(century);
226: switch (century)
227: {
228: case 20:
229:
century;
230:
break;
231: case 21:
232:
--century;
233:
break;
234: case 19:
235:
century+=2;
236:
break;
237: case 18:
238:
century++;
239:
break;
240: case 22:
241:
century+=2;
242:
break;
243: case 23:
244:
century+=2;
245:
break;
246: case 17:
247:
century+=2;
248:
break;
249: case 16:
250:
century+=3;
251:
break;
252: case 15:
253:
century+=3;
254:
break;
255: case 14:
256:
century-=2;
257:
break;
8|Page

CANAL HIGHER INSTITUTE OF ENGINEERING & TECHNOLOGY

258: case 13:


259:
century--;
260:
break;
261: default:
262:
cout <<"century number not in the list \n";
263:
cout <<"Day calculation may not be accurate \n";
264:
cout <<"do you want to continue (y/n) ?";
265:
cin >> ask;
266:
if(ask == 'y')
267:
break;
268:
else
269:
goto again;
270: }
271: cout <<"Enter the date (day/month/year) \n";
272: cout <<"day number = "; cin >> day;
273: error(day);
274: if (day >31)
275: {
276: cout <<"Unknown day! \n";
277: goto again;
278: }
279: cout <<"month number = "; cin >> month;
280: error(month);
281: switch(month)
282: {
283: case 1:
284:
m =6;
285:
break;
286: case 2:
287:
m =2;
288:
break;
289:
case 3:
290: m =2;
291:
break;
292: case 4:
293:
m =5;
294:
break;
295: case 5:
9|Page

CANAL HIGHER INSTITUTE OF ENGINEERING & TECHNOLOGY

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

CANAL HIGHER INSTITUTE OF ENGINEERING & TECHNOLOGY

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

CANAL HIGHER INSTITUTE OF ENGINEERING & TECHNOLOGY

372: cout << endl;


373: }
374: void factorial()
375: {
376:
int c;
377:
char ask;
378:
do
379:
{
380:
long double j=1;
381:
cout <<"Enter factorial number: ";
382:
cin >> c;
383:
error(c);
384:
for( c ; c>0; c--)
385:
{
386:
j=j*c;
387:
}
388:
cout <<"!number = "<< j << endl;
389:
cout <<"Do you want to exit the programme (y/n)? : ";
390:
cin >> ask;
391:
}while(ask == 'n');
392: }

12 | P a g e

CANAL HIGHER INSTITUTE OF ENGINEERING & TECHNOLOGY

13 | P a g e

CANAL HIGHER INSTITUTE OF ENGINEERING & TECHNOLOGY

14 | P a g e

CANAL HIGHER INSTITUTE OF ENGINEERING & TECHNOLOGY

También podría gustarte