7 Replies - 2928 Views - Last Post: 14 April 2011 - 10:25 AM Rate Topic: -----

#1 CodeWomanSRQ1234  Icon User is offline

  • New D.I.C Head

Reputation: 17
  • View blog
  • Posts: 34
  • Joined: 08-August 09

Using Classes - program won't compile

Posted 12 April 2011 - 12:53 PM

Here is what I am trying to do:
Assuming that a year has 365 days, write a class named DayOfYear that takes an integer representing a day of the year and translates it to a string consisting of the month followed by day of the month. For example,

Day 2 would be January 2
Day 32 would be February 1
Day 365 would be December 31

The constructor for the class should take as parameter an integer representing the day of the year, and the class should have a member function print() that prints the day in the month-day format. The class should have an integer member variable to represent the day, and should have static member variables of type string to assist in the translation from the integer format to the month-day format.

Test your class by inputting various integers representing days and printing out their representation in the month-day format.

This is the only error message I received: \dayofyear.cpp(52): error C2660: 'DayOfYear::print' : function does not take 1 arguments

#include<iostream>
#include<iomanip>
using namespace std;

// Class declaration
class DayOfYear
{
private:
	int day;

public:
	static const int MonthDays[];
	static const string MonthName[];
	void print();
};


int main()
{
	// Define array for consecutive days
	const int MonthDays[] = {31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
	// Define array for strings with name of month
	const string MonthName[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
	
	int day;
	// Get user input
	cout << "\nEnter a number you would like to convert into a month and day";
	cin >> day;

	// Validation - do not allow a negative number or a number > 365
	if(day <= 0 || day > 365)
	{
		cout << "You must enter a valid number (1 thru 365)" << endl;
	}

	// Send entered day number to the print() function
	DayOfYear::print(day);

	system("Pause");
	return 0;
}




Is This A Good Question/Topic? 0
  • +

Replies To: Using Classes - program won't compile

#2 LaughingBelly  Icon User is offline

  • D.I.C Head

Reputation: 47
  • View blog
  • Posts: 103
  • Joined: 11-April 11

Re: Using Classes - program won't compile

Posted 12 April 2011 - 01:01 PM

The error is because you declared print function to accept no arguments.
    void print();


and you are calling it like this with one argument
    // Send entered day number to the print() function
    DayOfYear::print(day);



Also I don't see the definition of print() in your code listing - so even if it compiles, it will fail to link.

This post has been edited by LaughingBelly: 12 April 2011 - 01:02 PM

Was This Post Helpful? 2
  • +
  • -

#3 jimblumberg  Icon User is online

  • member icon


Reputation: 4074
  • View blog
  • Posts: 12,563
  • Joined: 25-December 09

Re: Using Classes - program won't compile

Posted 12 April 2011 - 01:05 PM

Since you have not shown us the class implementation file look at line 14. How many parameters does this function take? Look at line 37 how many parameters are in this function call?

Also where have you declared a variable of type DayOfYear?



Jim
Was This Post Helpful? 2
  • +
  • -

#4 CodeWomanSRQ1234  Icon User is offline

  • New D.I.C Head

Reputation: 17
  • View blog
  • Posts: 34
  • Joined: 08-August 09

Re: Using Classes - program won't compile

Posted 12 April 2011 - 03:09 PM

I am redoing the project a different way. will have to re-post. Sorry for the inconvenience.
Was This Post Helpful? 0
  • +
  • -

#5 CodeWomanSRQ1234  Icon User is offline

  • New D.I.C Head

Reputation: 17
  • View blog
  • Posts: 34
  • Joined: 08-August 09

Re: Using Classes - program won't compile

Posted 13 April 2011 - 04:22 PM

I redid it and submitted it and got a 95 and the instructor gave me a video of what i did wrong. Now I am jamming to get 4 other hard questions done by May 1. lol
Was This Post Helpful? 0
  • +
  • -

#6 CodeWomanSRQ1234  Icon User is offline

  • New D.I.C Head

Reputation: 17
  • View blog
  • Posts: 34
  • Joined: 08-August 09

Re: Using Classes - program won't compile

Posted 14 April 2011 - 06:11 AM

Here is the NEW program I redid:
#include<iostream>
#include<iomanip>
#include<cstring>
#include<string>

using namespace std;

// Static member variable type string to translate from integer to month-day format

// Class declaration
class DayOfYear
{
public:
	int day;
	string Month;

	// Constructor function
	DayOfYear(int dayEntered)
	{
		day = dayEntered;
		//cout << "Please enter a number from 1 to 365" << endl;
		//cin >> dayEntered;
		 
	} // end constructor function

	void print()
	{
		
			if(day >= 1 && day <= 31)
			{
				cout << "January" << day << endl;
			}
	
			if(day >= 32 && day <= 59)
			{
				cout << "February" << (day - 31) << endl;
			}

			if(day >= 60 && day <= 90)
			{
				cout << "March" << (day - 59)  << endl;
			}

			if(day >= 91 && day <= 120)
			{
				cout << "April" << (day - 90)  << endl;
			}

			if(day >= 121 && day <= 151)
			{
				cout << "May" << (day - 120)  << endl;
			}

			if(day >= 152 && day <= 181)
			{
				cout << "June" << (day - 151)  << endl;
			}

			if(day >= 182 && day <= 212)
			{
				cout << "July" << (day - 181)  << endl;
			}

			if(day >= 213 && day <= 243)
			{
				cout << "August" << (day - 212)  << endl;
			}

			if(day >= 244 && day <= 273)
			{
				cout << "September" << (day - 243)  << endl;
			}

			if(day >= 274 && day <= 304)
			{
				cout << "October" << (day - 273)  << endl;
			}

			if(day >= 305 && day <= 334)
			{
				cout << "November" << (day - 304)  << endl;
			

			if(day >= 335 && day <= 365)
			{
				cout << "December" << (day - 334)  << endl;
			}
		

	} // end print function

		
}; // end Class DayOfYear



int main()
{
	// choose a day to print
	DayOfYear d(78);
	// print day 78 in Month and Day format
	d.print();

	system("Pause");
	return 0;

}


Here are the error messages:
1>------ Build started: Project: DayOfYear, Configuration: Debug Win32 ------
1> DayOfYear.cpp
1>c:\users\kim\documents\visual studio 2010\projects\dayofyear\dayofyear\dayofyear.cpp(125): fatal error C1075: end of file found before the left brace '{' at 'c:\users\kim\documents\visual studio 2010\projects\dayofyear\dayofyear\dayofyear.cpp(29)' was matched
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Was This Post Helpful? 0
  • +
  • -

#7 jimblumberg  Icon User is online

  • member icon


Reputation: 4074
  • View blog
  • Posts: 12,563
  • Joined: 25-December 09

Re: Using Classes - program won't compile

Posted 14 April 2011 - 06:25 AM

You have an opening brace on line 80 that has no closing brace.

Jim
Was This Post Helpful? 1
  • +
  • -

#8 CodeWomanSRQ1234  Icon User is offline

  • New D.I.C Head

Reputation: 17
  • View blog
  • Posts: 34
  • Joined: 08-August 09

Re: Using Classes - program won't compile

Posted 14 April 2011 - 10:25 AM

thanks Jim! Sometimes it helps to have another eye!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1