Question

I know I'm on the right path, but don't know where to continue from here. This is a C++ assignmen...

I know I'm on the right path, but don't know where to continue from here. This is a C++ assignment

Your job is to write that will display a calendar for any given month of a given year. The user will need to type the number of the month as an integer from 1 to 12 (1 is for January, etc.), and the year as a 4-digit integer. This assignment simply requires that your program make use of more than one loop statements and as many functions as possible to breakdown the problem into simpler sub-problems. Also, you must have at least one valued function and one void function. In addition, your program should keep the calendar neatly tabulated.

#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#include <iomanip>
#include <sstream>
using namespace std;

void grabTheDValues(int &m, int &y, int &century, int month, int year);
int DGrabbed(int m, int y, int century, int d);
bool leapYearIf(int y);
int leapYear(int y);
int daysInMonth(int m, int y);
void printCa1endarHead(int m);
void skipws(int i);
string monthName(int month);
void skipDay(int dy);
void displayMonth(int numOfDays, int dOfWeek);

int main() {

   int month = 0;
   int year = 0;
   int m = 0, y = 0, century = 0, d = 0;
   int itsTheFirstOfTheMonth;
   int numOfDays;

   itsTheFirstOfTheMonth = DGrabbed(m, y, century, d);

   cout << "Enter a month as an integer (3 for March ... 12 for December, 13 for January, 14 for February, etc.): ";
   cin >> month;
   cout << "Enter a year as a four digit integer: ";
   cin >> year;

   grabTheDValues(m, y, century, month, year);
   if (month >= 3 && month <= 14) {
       numOfDays = dayInMonth(m);
       printCa1endarHead(m);
       displayMonth(numOfDays, itsTheFirstOfTheMonth);
       cout << endl << endl;
   }
   cout << setw(15) << DGrabbed << endl;

   system("pause");
   return 0;
}

void grabTheDValues(int &m, int &y, int &century, int month, int year) {
   m = month;
   century = (year - y) / 100;
   y = year - 100 * century;
}

int DGrabbed(int m, int y, int century, int d) {
   d = ((26 * (m + 1) / 10) + y + (y / 4) + (century / 4) + (5 * century)) % 7;
   return d;
}

bool leapYearIf(int y) {
   return(y % 400 == 0) || (y % 4 == 0) && (y % 100 == 0);
}

int leapYear(int y) {
   return (y/4) - (y/100) + (y/400);
}

string monthName(int month) {
   string nameOfMonth[] = { "January", "February", "March", "April", "May", "June",
       "July", "August", "September", "Octoher", "November", "December" };
   return (nameOfMonth[month]);
}

int daysInMonth(int m, int y) {
   if (m == 14) {
       if (y % 400 == 0 || y % 4 == 0 && y % 100 != 0)
           return(29);
       else
           return(28);
   }
   else if (m == 3 || m = 5 || m == 7 || m == 8 || m == 10 || m == 12){
       return (31);
   }
   else{
       return(30);
   }
}

void printCa1endarHead(int m) {
   if (m == 13) {
       skipws(7);
       cout << "January" << endl;
   }
   else if (m == 14) {
       skipws(7);
           cout << "February" << endl;
   }
   else if (m == 3) {
       skipws(7);
       cout << "March" << endl;
   }
   else if (m == 4) {
       skipws(7);
       cout << "April" << endl;
   }
   else if (m == 5) {
       skipws(7);
       cout << "May" << endl;
   }
   else if (m == 6) {
       skipws(7);
       cout << "June" << endl;
   }
   else if (m == 7) {
       skipws(7);
       cout << "July" << endl;
   }
   else if (m == 8) {
       skipws(7);
       cout << "August" << endl;
   }
   else if (m == 9) {
       skipws(7);
       cout << "September" << endl;
   }
   else if (m == 10) {
       skipws(7);
       cout << "October" << endl;
   }
   else if (m == 11) {
       skipws(7);
       cout << "November" << endl;
   }
   else if (m == 12) {
       skipws(7);
       cout << "December" << endl;
   }
   cout << "Sun\tMon\tTu\tWed\tTh\tFri\tSat" << endl;
   cout << "-------------------------------";
}

void skipws(int i) {
   while (i > 0) {
       cout " ";
       i = i - 1;
   }
}
void displayMonth(int numOfDays, int dOfWeek) {
   int day = 1;
   skipDay(dOfWeek);
   while (day <= numOfDays) {
       cout << setw(2) << day << " ";
       if (dOfWeek == 6) {
           cout << endl;
           dOfWeek = 0;
       }
       else {
           dOfWeek = dOfWeek + 1;
           day = day + 1;
       }
   }
}
void skipDay(int dy) {
   return skipDay(3 * dy);
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#include <iomanip>
#include <sstream>
using namespace std;

void grabTheDValues(int &m, int &y, int &century, int month, int year);
int DGrabbed(int m, int y, int century, int d);
bool leapYearIf(int y);
int leapYear(int y);
int daysInMonth(int m, int y);
void printCa1endarHead(int m);
void skipws(int i);
string monthName(int month);
void skipDay(int dy);
void displayMonth(int numOfDays, int dOfWeek);

int main() {

int month = 0;
int year = 0;
int m = 0, y = 0, century = 0, d = 0;
int itsTheFirstOfTheMonth;
int numOfDays;

cout << "Enter a month as an integer (3 for March ... 12 for December, 13 for January, 14 for February, etc.): ";
cin >> month;
cout << "Enter a year as a four digit integer: ";
cin >> year;

m = month;
y = year;
itsTheFirstOfTheMonth = DGrabbed(m, y, 1, d);

grabTheDValues(m, y, century, month, year);
if (month >= 3 && month <= 14) {
numOfDays = daysInMonth(m,y);
printCa1endarHead(m);
displayMonth(numOfDays, itsTheFirstOfTheMonth);
cout << endl << endl;
}
// cout << setw(15) << DGrabbed << endl;

system("pause");
return 0;
}

void grabTheDValues(int &m, int &y, int &century, int month, int year) {
m = month;
century = (year - y) / 100;
y = year - 100 * century;
}

int DGrabbed(int m, int y, int century, int d) {
d = ((26 * (m + 1) / 10) + y + (y / 4) + (century / 4) + (5 * century)) % 7;
return (d+1)%7;
}

bool leapYearIf(int y) {
return(y % 400 == 0) || (y % 4 == 0) && (y % 100 == 0);
}

int leapYear(int y) {
return (y/4) - (y/100) + (y/400);
}

string monthName(int month) {
string nameOfMonth[] = { "January", "February", "March", "April", "May", "June",
"July", "August", "September", "Octoher", "November", "December" };
return (nameOfMonth[month]);
}

int daysInMonth(int m, int y) {
if (m == 14) {
if (y % 400 == 0 || y % 4 == 0 && y % 100 != 0)
return(29);
else
return(28);
}
else if ((m == 3) || (m = 5) || (m == 7) || (m == 8) || (m == 10) || (m == 12)){
return (31);
}
else{
return(30);
}
}

void printCa1endarHead(int m) {
if (m == 13) {
skipws(7);
cout << "January" << endl;
}
else if (m == 14) {
skipws(7);
cout << "February" << endl;
}
else if (m == 3) {
skipws(7);
cout << "March" << endl;
}
else if (m == 4) {
skipws(7);
cout << "April" << endl;
}
else if (m == 5) {
skipws(7);
cout << "May" << endl;
}
else if (m == 6) {
skipws(7);
cout << "June" << endl;
}
else if (m == 7) {
skipws(7);
cout << "July" << endl;
}
else if (m == 8) {
skipws(7);
cout << "August" << endl;
}
else if (m == 9) {
skipws(7);
cout << "September" << endl;
}
else if (m == 10) {
skipws(7);
cout << "October" << endl;
}
else if (m == 11) {
skipws(7);
cout << "November" << endl;
}
else if (m == 12) {
skipws(7);
cout << "December" << endl;
}
cout << "Sun\tMon\tTu\tWed\tTh\tFri\tSat" << endl;
cout << "--------------------------------------------------"<<endl;
}

void skipws(int i) {
while (i > 0) {
cout << " ";
i = i - 1;
}
}
void displayMonth(int numOfDays, int dOfWeek) {
int day = 1;
skipDay(dOfWeek);
while (day <= numOfDays) {
cout << day<< "\t";
if (dOfWeek == 6) {
cout << endl;
dOfWeek = 0;
}
else {
dOfWeek = dOfWeek + 1;
}
   day = day + 1;
}
}
void skipDay(int dy) {
   if(dy == 7){
       dy=0;
   }
for(int i =0 ;i<dy;i++){
   cout<<"\t"<<" ";
}
}

SCREEN SHOT:

rcluce estnng using namespnce std; vo d grabTheDValunt&m, int &y, int &century, int morth, int yearl 10 int 13 in daysinMan ,dr(ps * {m + 1)/ IC) + y + (y , △] + (century , 1+15 * century]} 56 7; return (d+1)%7; 60 71 72 73 retum relurn 1 86 09 nt m)kipw sops skipa) cout e October end; skipw sopas() ec endl; 4 oid daplayMontr nt numatDays, int durick) めweek dCweek + 1; da:/Programs/CPP$ g++ Calendar.cpp :/Programs/CPP$ /a.out Enter a month as an integer (3 for March 12 for December, 13 for Janu

Add a comment
Know the answer?
Add Answer to:
I know I'm on the right path, but don't know where to continue from here. This is a C++ assignmen...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • How can I make this compatible with older C++ compilers that DO NOT make use of...

    How can I make this compatible with older C++ compilers that DO NOT make use of stoi and to_string? //Booking system #include <iostream> #include <iomanip> #include <string> using namespace std; string welcome(); void print_seats(string flight[]); void populate_seats(); bool validate_flight(string a); bool validate_seat(string a, int b); bool validate_book(string a); void print_ticket(string passenger[], int i); string flights [5][52]; string passengers [4][250]; int main(){     string seat, flight, book = "y";     int int_flight, p = 0, j = 0;     int seat_number,...

  • Hello, I have a bug in my code, and when I run it should ask the...

    Hello, I have a bug in my code, and when I run it should ask the user to enter the month and then the year and then print out the calendar for the chosen month and year. My problem with my code is that when I run it and I enter the month, it doesn't ask me for the year and it prints all the years of the month I chose. Please help! Code: #include "calendarType.h" #include <iostream> using namespace...

  • Please help fix my code C++, I get 2 errors when running. The code should be...

    Please help fix my code C++, I get 2 errors when running. The code should be able to open this file: labdata.txt Pallet PAG PAG45982IB 737 4978 OAK Container AYF AYF23409AA 737 2209 LAS Container AAA AAA89023DL 737 5932 DFW Here is my code: #include <iostream> #include <string> #include <fstream> #include <vector> #include <cstdlib> #include <iomanip> using namespace std; const int MAXLOAD737 = 46000; const int MAXLOAD767 = 116000; class Cargo { protected: string uldtype; string abbreviation; string uldid; int...

  • I need to add something to this C++ program.Additionally I want it to remove 10 words...

    I need to add something to this C++ program.Additionally I want it to remove 10 words from the printing list (Ancient,Europe,Asia,America,North,South,West ,East,Arctica,Greenland) #include <iostream> #include <map> #include <string> #include <cctype> #include <fstream> #include <iomanip> using namespace std; void addWord(map<std::string,int> &words,string s); void readFile(string infile,map<std::string,int> &words); void display(map<std::string,int> words);    int main() { // Declaring variables std::map<std::string,int> words;       //defines an input stream for the data file ifstream dataIn;    string infile; cout<<"Please enter a File Name :"; cin>>infile; readFile(infile,words);...

  • The following is a sample inventory in C++, i want to ask the user to input a item number for removing from inventory. //CPP #include <iostream> #include <fstream> #include <cstdlib>...

    The following is a sample inventory in C++, i want to ask the user to input a item number for removing from inventory. //CPP #include <iostream> #include <fstream> #include <cstdlib> #include <iomanip> #define MAX 1000 using namespace std; //Function to Add a new inventory item to the data into the array in memory void addItem(string desc[],string idNum[], float prices[], int qty[],int &num) { cout<<"Enter the names:"; cin>>desc[num]; cout<<"Enter the item number:"; cin>>idNum[num]; cout<<"Enter the price of item:"; cin>>prices[num]; cout<<"Enter the...

  • I want to change this code and need help. I want the code to not use...

    I want to change this code and need help. I want the code to not use parallel arrays, but instead use one array of struct containing the data elements, String for first name, String for last name,Array of integers for five (5) test scores, Character for grade. If you have any idea help would be great. #include #include #include #include using namespace std; const int NUMBER_OF_ROWS = 10; //number of students const int NUMBER_OF_COLUMNS = 5; //number of scores void...

  • c++, I am having trouble getting my program to compile, any help would be appreciated. #include...

    c++, I am having trouble getting my program to compile, any help would be appreciated. #include <iostream> #include <string> #include <string.h> #include <fstream> #include <stdlib.h> using namespace std; struct record { char artist[50]; char title[50]; char year[50]; }; class CD { //private members declared private: string artist; //asks for string string title; // asks for string int yearReleased; //asks for integer //public members declared public: CD(); CD(string,string,int); void setArtist(string); void setTitle(string); void setYearReleased(int); string getArtist() const; string getTitle() const; int...

  • #include "stdafx.h" #include <iostream> using namespace std; class dateType {    private:        int dmonth;...

    #include "stdafx.h" #include <iostream> using namespace std; class dateType {    private:        int dmonth;        int dday;        int dyear;       public:       void setdate (int month, int day, int year);    int getday()const;    int getmonth()const;    int getyear()const;    int printdate()const;    bool isleapyear(int year);    dateType (int month=0, int day=0, int year=0); }; void dateType::setdate(int month, int day, int year) {    int numofdays;    if (year<=2008)    {    dyear=year;...

  • I need to make a few changes to this C++ program,first of all it should read...

    I need to make a few changes to this C++ program,first of all it should read the file from the computer without asking the user for the name of it.The name of the file is MichaelJordan.dat, second of all it should print ,3 highest frequencies are: 3 words that occure the most.everything else is good. #include <iostream> #include <map> #include <string> #include <cctype> #include <fstream> #include <iomanip> using namespace std; void addWord(map<std::string,int> &words,string s); void readFile(string infile,map<std::string,int> &words); void display(map<std::string,int>...

  • Can anyone help me with my C++ assignment on structs, arrays and bubblesort? I can't seem...

    Can anyone help me with my C++ assignment on structs, arrays and bubblesort? I can't seem to get my code to work. The output should have the AVEPPG from highest to lowest (sorted by bubbesort). The output of my code is messed up. Please help me, thanks. Here's the input.txt: Mary 15 10.5 Joseph 32 6.2 Jack 72 8.1 Vince 83 4.2 Elizabeth 41 7.5 The output should be: NAME             UNIFORM#    AVEPPG Mary                   15     10.50 Jack                   72      8.10 Elizabeth              41      7.50 Joseph                 32      6.20 Vince                  83      4.20 ​ My Code: #include <iostream>...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT