Am at wits end,following code so far but am not sure how to fix it for the arrays & what to do next? Have some of vector information written but left out of this post since it compiles, need to fix rest of code for arrays. Reslly not getting how arrays work here, help? explain what to do to fix?
#include <cstring>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include "CinReader.h"
using namespace std;
CinReader reader;
struct entry
{
int date;
string dayOfWeek;
string text;
string timestamp;
};
//functions for use by program
int calcDaysSoFar(int year, int month);
void printCalendar(int month, int year, int firstDay);
void repeatChar(char ch, int numChar);
void printTop(int innerWidth);
void drawDivide(int innerWidth);
void printBottom(int innerWidth);
//function allowing your program to start, prompts user for input and
//outputs information to user, uses structs, calls functions, cleans up arrays when done
int main()
{
int year, month;
int days;
cout << " Please enter the number of the month and year to access the calendar\n" << endl;
cout << " Please leave a space in between the month and year when you enter them: \n";
cin >> month >> year;
do
{
days = calcDaysSoFar(year, month);
int firstDayOfWeek = days % 7;
printCalendar(month, year, firstDayOfWeek);
month++;
}
while(month < 13);
system("pause");
return 0;
}
//declares the array for the names of a month for a year
void monthName(string monthNameArray, int sizeOfMonthArray = 12)
{
cout << "Enter the month name" << monthName << "." "\n";
string monthName[12] = {"January","February","March","April","May","June",
"July","August","September","October","November","December"};
for(int i = 0; i< sizeOfMonthArray; i++)
{
cout << "Please enter the name of the month " << monthName << " " << i+1 << "\n";
monthNameArray[i] = reader.readInt();
}
}
//declares the array for the # days per month per year
void daysPast(int daysPastArray[],int sizeOfDaysPastArray)
{
int daysPast[] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
for(int i = 0; i < sizeOfDaysPastArray; i++)
{
cout << "Please enter the number of days in this " << daysPast << " month" << i+1 << ": \n";
daysPastArray[i] = reader.readInt();
}
}
//declares the array for the # days in a month for a year
void daysInMonth(int monthArray[], int sizeOfMonthArray = 12)
{
int monthArray[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
for(int i = 0; i < sizeOfMonthArray; i++)
{
cout << "Please enter the number of days in this " << daysInMonth << " month " << i+1 << ": \n";
month[i] = reader.readInt();
}
}
//function calculates the number of days passed from the start of May 2010
int calcDaysSoFar(int daysPassed[12] = ( 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334);
,int year, int month)
{
const int firstYear = 2010;
int dayOffset = 3;
int days;
days = (year - firstYear) * 365;
days += dayOffset;
days += daysPassed[month-1];
return days;
}
//Prints Month & Year followed by the day headings followed
//by the numbers
void printCalendar(int month, int year, int firstDay)
{
string dayHeader = string("Sun") + char(186) + "Mon" + char(186) + "Tues" +
char(186) + "Wed" + char(186) + "Thu" + char(186) + "Fri" + char(186) + "Sat";
int innerWidth = dayHeader.length();
//converts year to a string
stringstream sstream;
string tempStr;
cout << '\n';
printTop(innerWidth);
//print the month and year line
sstream << year;
tempStr = string(" ") + monthName[month-1] + string(" ") + sstream.str();
cout << char(186);
cout << tempStr;
repeatChar(' ', innerWidth - tempStr.length());
cout << char(186);
// draws a dividing line
cout << '\n';
cout << char(204);
for (int count = 0; count < 7; count ++)
{
repeatChar(char(205),4);
if(count != 6)
{
cout << char(203);
}
}
cout << char(185);
cout << '\n';
//print the day header line
cout << char(186);
cout << dayHeader;
cout << char(186) << '\n';
//draws a horizontal line
drawDivide(innerWidth);
int count.offset;
offset = 1 - firstDay;
//get the number of days in this month
count = daysInMonth[month-1]
//loop to fill in rows
int dayNum = 0;
for (int x = offset; x <= count; x +=7)
{
cout << char(186);
for dayNum = x; (dayNum < x+7); dayNum++)
{
if (dayNum <= 0 || dayNum > count)
{
cout << setw(4) << left << setprecision(3) << " " << char(186);;
}
else
{
cout << setw(4) << left << setprecision(3) << setfill(' ') << dayNum << char(186);
}
}
cout << '\n';
if(dayNum <= count)
{
//draws a divide line after each row except last
drawDivide(innerWidth);
}
}
printBottom(innerWidth);
}
//function to set up top of calendar grid
void printTop(int innerWidth)
{
cout << char (201);
repeatChar((char)205, innerWidth);
cout << char (187);
cout << '\n';
}
//repeats a char a number of times
void repeatChar(char ch, int numChar)
{
string aString (numChar, ch);
cout << aString;
}
void drawDivide(int innerWidth)
{
cout << char(204);
for (int count = 0; count < 7; count ++)
{
repeatChar(char(205), 4);
if( count !=6)
{
cout << char(206);
}
}
cout << char(185);
cout << '\n';
}
//draws bottom of grid
void printBottom(int innerWidth)
{
cout << char(200);
for (int count = 0; count <7; count ++)
{
repeatChar(char(205), 4);
if( count !=6)
{
cout << char(202);
}
}
cout << char(188);
cout << '\n';
}
This post has been edited by JackOfAllTrades: 05 May 2010 - 10:25 AM
Reason for edit:: Added code tags.

New Topic/Question
Reply




MultiQuote





|