SlideShare a Scribd company logo
1 | P a g e C A N A L H I G H E R I N S T I T U T E O F E N G I N E E R I N G & T E C H N O L O G Y
Task 4:
//daycalculation.cpp
C++ program: shows the day of the
week by date given
Khalid Waleed
CANAL HIGH INSTITUTE OF ENGINEERING & TECHNOLOGY
Prepared By:
2 | P a g e C A N A L H I G H E R I N S T I T U T E O F E N G I N E E R I N G & T E C H N O L O G Y
1: // daycalculation.cpp
2: // shows the day of the week by date given
3: #include <iostream>
4: using namespace std;
5: void error(int &);
6: int main()
7: {
8: int day, month, m, year, century, day_of_week;
9: char ask;
10: cout <<" program to show the day of the week by date n";
11: cout <<"-------------------------------------------------------------"<<endl;
12: cout <<"centuries availiable : 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23";
13: cout <<"n ***** Note: we are now in the 21st century ***** n";
14: do
15: {
16: cout <<"please Enter the century number: ";
17: cin >> century;
18: error(century);
19: switch (century)
20: {
21: case 20:
23: break;
22: century;
24: case 21:
25: --century;
26: break;
27: case 19:
28: century+=2;
29: break;
30: case 18:
3 | P a g e C A N A L H I G H E R I N S T I T U T E O F E N G I N E E R I N G & T E C H N O L O G Y
31: century++;
32: break;
33: case 22:
34: century+=2;
35: break;
36: case 23:
37: century+=2;
38: break;
39: case 17:
40: century+=2;
41: break;
42: case 16:
43: century+=3;
44: break;
45: case 15:
46: century+=3;
47: break;
48: case 14:
49: century-=2;
50: break;
51: case 13:
52: century--;
53: break;
54: default:
55: cout <<"century number not in the list n";
56: cout <<"Day calculation may not be accurate n";
57: cout <<"do you want to continue (y/n) ?";
58: cin >> ask;
59: if(ask == 'y')
60: break;
61: else
4 | P a g e C A N A L H I G H E R I N S T I T U T E O F E N G I N E E R I N G & T E C H N O L O G Y
62: goto again;
63: }
64: cout <<"Enter the date (day/month/year) n";
65: cout <<"day number = "; cin >> day;
66: error(day);
67: if (day >31)
68: {
69: cout <<"Unknown day! n";
70: goto again;
71: }
72: cout <<"month number = "; cin >> month;
73: error(month);
74: switch(month)
75: {
76: case 1:
77: m =6;
78: break;
79: case 2:
80: m =2;
81: break;
82: case 3:
83: m =2;
84: break;
85: case 4:
86: m =5;
87: break;
88: case 5:
89: m =0;
90: break;
91: case 6:
92: m =3;
5 | P a g e C A N A L H I G H E R I N S T I T U T E O F E N G I N E E R I N G & T E C H N O L O G Y
93: break;
94: case 7:
95: m =5;
96: break;
97: case 8:
98: m =1;
99: break;
100: case 9:
101: m =4;
102: break;
103: case 10:
104: m =6;
105: break;
106: case 11:
107: m =2;
108: break;
109: case 12:
110: m =4;
111: break;
112: default:
113: cout <<"Unknown month! n";
114: goto again;
115: }
116: cout <<"year number = "; cin >> year;
117: error(year);
118: day_of_week =( day + m + year +(year/4)+ century )%7;
119: switch(day_of_week)
120: {
121: case 6:
122: cout <<"the day was a Saturday n";
123: break;
6 | P a g e C A N A L H I G H E R I N S T I T U T E O F E N G I N E E R I N G & T E C H N O L O G Y
124: case 0:
125: cout <<"the day was a Sunday n";
126: break;
127: case 1:
128: cout <<"the day was a Monday n";
129: break;
130: case 2:
131: cout <<"the day was a Tuesday n";
132: break;
133: case 3:
134: cout <<"the day was a Wednesday n";
135: break;
136: case 4:
137: cout <<"the day was a Thursday n";
138: break;
139: case 5:
140: cout <<"the day was a Friday n";
141: break;
142: default:
143: cout <<"ERROR!! n";
144: }
145: again:
146: cout <<"Do again (y/n)? : ";
147: cin >> ask;
148: }while(ask == 'y');
149: return 0;
150: }
151: void error(int &x)
152: {
153: while (cin.fail())
154: {
7 | P a g e C A N A L H I G H E R I N S T I T U T E O F E N G I N E E R I N G & T E C H N O L O G Y
155: cin.clear();// clear input buffer to restore cin to a usable state
156: cin.ignore(INT_MAX, 'n');// ignore last input
157: cout <<"You can only enter numbers.n";
158: cout <<"Enter a number : ";
159: cin >> x;
160: }
161: }

More Related Content

Similar to C++ program: Day calculation .cpp

C++ program: All tasks .cpp
C++ program: All tasks .cppC++ program: All tasks .cpp
C++ program: All tasks .cpp
Khalid Waleed
 
ตัวอย่างการเขียนโปรแกรม โดยใช้ฟังก์ชัน
ตัวอย่างการเขียนโปรแกรม โดยใช้ฟังก์ชันตัวอย่างการเขียนโปรแกรม โดยใช้ฟังก์ชัน
ตัวอย่างการเขียนโปรแกรม โดยใช้ฟังก์ชัน
Warawut
 
201801 CSE240 Lecture 15
201801 CSE240 Lecture 15201801 CSE240 Lecture 15
201801 CSE240 Lecture 15
Javier Gonzalez-Sanchez
 
CCE management system
CCE management systemCCE management system
CCE management system
Trish004
 
Pushandpullproductionsystems chap7-ppt-100210005527-phpapp01[1]
Pushandpullproductionsystems chap7-ppt-100210005527-phpapp01[1]Pushandpullproductionsystems chap7-ppt-100210005527-phpapp01[1]
Pushandpullproductionsystems chap7-ppt-100210005527-phpapp01[1]Pankaj Rathod
 

Similar to C++ program: Day calculation .cpp (7)

C++ program: All tasks .cpp
C++ program: All tasks .cppC++ program: All tasks .cpp
C++ program: All tasks .cpp
 
Ch4
Ch4Ch4
Ch4
 
ตัวอย่างการเขียนโปรแกรม โดยใช้ฟังก์ชัน
ตัวอย่างการเขียนโปรแกรม โดยใช้ฟังก์ชันตัวอย่างการเขียนโปรแกรม โดยใช้ฟังก์ชัน
ตัวอย่างการเขียนโปรแกรม โดยใช้ฟังก์ชัน
 
Rkf
RkfRkf
Rkf
 
201801 CSE240 Lecture 15
201801 CSE240 Lecture 15201801 CSE240 Lecture 15
201801 CSE240 Lecture 15
 
CCE management system
CCE management systemCCE management system
CCE management system
 
Pushandpullproductionsystems chap7-ppt-100210005527-phpapp01[1]
Pushandpullproductionsystems chap7-ppt-100210005527-phpapp01[1]Pushandpullproductionsystems chap7-ppt-100210005527-phpapp01[1]
Pushandpullproductionsystems chap7-ppt-100210005527-phpapp01[1]
 

Recently uploaded

The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
ankuprajapati0525
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
AmarGB2
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 

Recently uploaded (20)

The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 

C++ program: Day calculation .cpp

  • 1. 1 | P a g e C A N A L H I G H E R I N S T I T U T E O F E N G I N E E R I N G & T E C H N O L O G Y Task 4: //daycalculation.cpp C++ program: shows the day of the week by date given Khalid Waleed CANAL HIGH INSTITUTE OF ENGINEERING & TECHNOLOGY Prepared By:
  • 2. 2 | P a g e C A N A L H I G H E R I N S T I T U T E O F E N G I N E E R I N G & T E C H N O L O G Y 1: // daycalculation.cpp 2: // shows the day of the week by date given 3: #include <iostream> 4: using namespace std; 5: void error(int &); 6: int main() 7: { 8: int day, month, m, year, century, day_of_week; 9: char ask; 10: cout <<" program to show the day of the week by date n"; 11: cout <<"-------------------------------------------------------------"<<endl; 12: cout <<"centuries availiable : 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23"; 13: cout <<"n ***** Note: we are now in the 21st century ***** n"; 14: do 15: { 16: cout <<"please Enter the century number: "; 17: cin >> century; 18: error(century); 19: switch (century) 20: { 21: case 20: 23: break; 22: century; 24: case 21: 25: --century; 26: break; 27: case 19: 28: century+=2; 29: break; 30: case 18:
  • 3. 3 | P a g e C A N A L H I G H E R I N S T I T U T E O F E N G I N E E R I N G & T E C H N O L O G Y 31: century++; 32: break; 33: case 22: 34: century+=2; 35: break; 36: case 23: 37: century+=2; 38: break; 39: case 17: 40: century+=2; 41: break; 42: case 16: 43: century+=3; 44: break; 45: case 15: 46: century+=3; 47: break; 48: case 14: 49: century-=2; 50: break; 51: case 13: 52: century--; 53: break; 54: default: 55: cout <<"century number not in the list n"; 56: cout <<"Day calculation may not be accurate n"; 57: cout <<"do you want to continue (y/n) ?"; 58: cin >> ask; 59: if(ask == 'y') 60: break; 61: else
  • 4. 4 | P a g e C A N A L H I G H E R I N S T I T U T E O F E N G I N E E R I N G & T E C H N O L O G Y 62: goto again; 63: } 64: cout <<"Enter the date (day/month/year) n"; 65: cout <<"day number = "; cin >> day; 66: error(day); 67: if (day >31) 68: { 69: cout <<"Unknown day! n"; 70: goto again; 71: } 72: cout <<"month number = "; cin >> month; 73: error(month); 74: switch(month) 75: { 76: case 1: 77: m =6; 78: break; 79: case 2: 80: m =2; 81: break; 82: case 3: 83: m =2; 84: break; 85: case 4: 86: m =5; 87: break; 88: case 5: 89: m =0; 90: break; 91: case 6: 92: m =3;
  • 5. 5 | P a g e C A N A L H I G H E R I N S T I T U T E O F E N G I N E E R I N G & T E C H N O L O G Y 93: break; 94: case 7: 95: m =5; 96: break; 97: case 8: 98: m =1; 99: break; 100: case 9: 101: m =4; 102: break; 103: case 10: 104: m =6; 105: break; 106: case 11: 107: m =2; 108: break; 109: case 12: 110: m =4; 111: break; 112: default: 113: cout <<"Unknown month! n"; 114: goto again; 115: } 116: cout <<"year number = "; cin >> year; 117: error(year); 118: day_of_week =( day + m + year +(year/4)+ century )%7; 119: switch(day_of_week) 120: { 121: case 6: 122: cout <<"the day was a Saturday n"; 123: break;
  • 6. 6 | P a g e C A N A L H I G H E R I N S T I T U T E O F E N G I N E E R I N G & T E C H N O L O G Y 124: case 0: 125: cout <<"the day was a Sunday n"; 126: break; 127: case 1: 128: cout <<"the day was a Monday n"; 129: break; 130: case 2: 131: cout <<"the day was a Tuesday n"; 132: break; 133: case 3: 134: cout <<"the day was a Wednesday n"; 135: break; 136: case 4: 137: cout <<"the day was a Thursday n"; 138: break; 139: case 5: 140: cout <<"the day was a Friday n"; 141: break; 142: default: 143: cout <<"ERROR!! n"; 144: } 145: again: 146: cout <<"Do again (y/n)? : "; 147: cin >> ask; 148: }while(ask == 'y'); 149: return 0; 150: } 151: void error(int &x) 152: { 153: while (cin.fail()) 154: {
  • 7. 7 | P a g e C A N A L H I G H E R I N S T I T U T E O F E N G I N E E R I N G & T E C H N O L O G Y 155: cin.clear();// clear input buffer to restore cin to a usable state 156: cin.ignore(INT_MAX, 'n');// ignore last input 157: cout <<"You can only enter numbers.n"; 158: cout <<"Enter a number : "; 159: cin >> x; 160: } 161: }