7 Replies - 1496 Views - Last Post: 26 October 2010 - 02:43 PM Rate Topic: -----

#1 wowdemon360  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 09-October 10

Getting the day of the week to be referenced as

Posted 25 October 2010 - 07:58 PM

Trying to get my program to work with getting the user's input of a certain to be referred as the short version. In other words Monday is Mon. I'll provide what my class is supposed to do, but I'm going a little differently.

Create a new class called DayOfTheWeek. The class should have a data member that can store the day of the week, such as Mon for Monday, Tues for Tuesday, and so on.

Create the necessary member functions that will perform the required operations outlined in the lab summary above.

Call these functions setDay(), printDay(), and getDay().

Function setDay(string) takes a string parameter (for example, Monday, Tuesday etc.) and stores the value in the day attribute.

Function printDay() prints the value of the day attribute on console output.

Function getDay() returns the value of the day attribute.


Here is my header file (don't know how to use the attach file option)
class DayofTheWeek
{
public:
	void setDay(string);
	void printDay();
	string getDay();

private:
	string day;
};

void DayofTheWeek::setDay(string day)
{
	string day = Dayofweek;
}

void DayofTheWeek::printDay()
{
	cout << "The Day is : " << day << endl;
}

string DayofTheWeek::getDay()
{
	string tempDay;

	cout << "Enter Day: ";
	cin >> tempDay;

	return tempDay;
}


And here is my .cpp file
#include <iostream>
#include "DayofTheWeek.h"
#include <string>
using namespace std;

int main()
{
	DayofTheWeek day1;
	DayofTheWeek day2;

	cout << "Please type a day of the week: ";
	cin >> day1.getDay;

	cout << day1.getDay << " is referred as to " << day1.getDay << endl;
	
	system("PAUSE");
	return 0;
}


Any help would be cool and thanks ahead of time.

MOD EDIT: When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 26 October 2010 - 03:49 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Getting the day of the week to be referenced as

#2 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: Getting the day of the week to be referenced as

Posted 25 October 2010 - 08:24 PM

Welcome to DIC!

Please edit your posting (see the "EDIT" button in lower right). (If Edit is not available make a new posting and skip (a) below.)
( a ) Delete all your code.
( b ) Get a fresh copy of the code with formatting in place from your editor / IDE.
( c ) Paste the formatted code between code tags like this :code:
( d ) Use the "Preview Post" button to check it's all good.
( e ) Use the "Submit Modified Post" button to finish the editing.



Please give us some more details of your problem.
( a ) Does your code compile?
( b ) Any errors or warnings? If there are then share them with us.
( c ) Is the program producing any output?
( d ) How is the actual output different to what you want / expect? Give details and, ideally, examples.
( e ) What have you already tried to fix it?
Was This Post Helpful? 0
  • +
  • -

#3 wowdemon360  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 09-October 10

Re: Getting the day of the week to be referenced as

Posted 25 October 2010 - 11:43 PM

Trying to get my program to work with getting the user's input of a certain to be referred as the short version. In other words Monday is Mon. I'll provide what my class is supposed to do, but I'm going a little differently.

Create a new class called DayOfTheWeek. The class should have a data member that can store the day of the week, such as Mon for Monday, Tues for Tuesday, and so on.

Create the necessary member functions that will perform the required operations outlined in the lab summary above.

Call these functions setDay(), printDay(), and getDay().

Function setDay(string) takes a string parameter (for example, Monday, Tuesday etc.) and stores the value in the day attribute.

Function printDay() prints the value of the day attribute on console output.

Function getDay() returns the value of the day attribute.
//header file
class DayofTheWeek
{
public:
void setDay(string);
void printDay();
string getDay();

private:
string day;
};

void DayofTheWeek::setDay(string day)
{
string day = Dayofweek;
}

void DayofTheWeek::printDay()
{
cout << "The Day is : " << day << endl;
}

string DayofTheWeek::getDay()
{
string tempDay;

cout << "Enter Day: ";
cin >> tempDay;

return tempDay;
}


//.cpp file
#include <iostream>
#include "DayofTheWeek.h"
#include <string>
using namespace std;

int main()
{
DayofTheWeek day1;
DayofTheWeek day2;

cout << "Please type a day of the week: ";
cin >> day1.getDay;

cout << day1.getDay << " is referred as to " << day1.getDay << endl;

system("PAUSE");
return 0;
}



Ok there we go, but yeah about the errors I'm having like 28 errors in various places like header file line 05, I'm just having some difficulty in declaring my identifiers.
Was This Post Helpful? 0
  • +
  • -

#4 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: Getting the day of the week to be referenced as

Posted 25 October 2010 - 11:48 PM

View Postwowdemon360, on 26 October 2010 - 03:43 PM, said:

I'm having like 28 errors in various places like header file line 05,

If you want help with those you would have to share them


View Postwowdemon360, on 26 October 2010 - 03:43 PM, said:

I'm just having some difficulty in declaring my identifiers.

I don't understand what you are trying to say here.
Could you expand on more on what those 9 words mean?
Was This Post Helpful? 0
  • +
  • -

#5 Alex6788  Icon User is offline

  • kitties == adorable


Reputation: 144
  • View blog
  • Posts: 1,667
  • Joined: 15-July 10

Re: Getting the day of the week to be referenced as

Posted 25 October 2010 - 11:51 PM

Don't use system("pause"); unless your teacher makes you.

instead use
cin.get();
and
cin.ignore();
cin.get(); 


If there is already input in the buffer.

Why system("pause"); is bad: http://www.gidnetwork.com/b-61.html

I hope that is of some use :)

This post has been edited by Alex6788: 25 October 2010 - 11:52 PM

Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6091
  • View blog
  • Posts: 23,605
  • Joined: 23-August 08

Re: Getting the day of the week to be referenced as

Posted 26 October 2010 - 03:50 AM

cout << day1.getDay << " is referred as to " << day1.getDay << endl;

That's not how you call a method. Go back to the book and read how to call one.
Was This Post Helpful? 0
  • +
  • -

#7 wowdemon360  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 09-October 10

Re: Getting the day of the week to be referenced as

Posted 26 October 2010 - 11:30 AM

I wrote in the errors on the code where I'm getting the errors at, hopefully it helps as you asked, thanks again for all your help.
class DayofTheWeek
{
public:
	DayofTheWeek();
	void setDay(string);/*syntax error: identifier 'string'*/
	void printDay();
	string getDay();/*syntax error: missing ';' before identifier 'getDay', missing type specifier - int assumed. Note: C++ does not support default-int (x2), (Warning) 'getDay': missing return type; assumed to be a member function retuning 'int'*/

private:
	string day;/*syntax error: missing ';' before identifier 'day', missing type specifier - int assumed. Note C++ does not support default - int (x2)*/
};

void DayofTheWeek::setDay(string day)/*'string': undeclared identifier, syntax error: missing ')' before identifier 'day', 'void DayofTheWeek::setDay(void)': member function redeclaration not allowed, syntax : ')'*/
{/*syntax error: missing ';' before '(', '(': missing function header (old-style formal list?)*/
	string day = Dayofweek;
}

void DayofTheWeek::printDay()
{
	cout << "The Day is : " << day << endl;/*'cout': undeclared identifier, 'day': undeclared identifier, 'endl': undeclared identifier*/
}

string DayofTheWeek::getDay()/*syntax error: missing ';' before 'DayofTheWeek::getDay', missing type specifier - int assumed. Note: C++ does not support default-int*/ 
{/*missing type specifier - int assumed. Note: C++ does not support default-int*/
	string tempDay;/*syntax error: missing ';' before identifier 'tempDay', 'tempDay' : undeclared identifier*/

	cout << "Enter Day: ";/*'cout': undeclared identifier*/
	cin >> tempDay;/*'cin': undeclared identifier, 'tempDay': undeclared identifier*/

	return tempDay;/*'tempDay': undclared identifier*/
}



//Day Program
//Moded by: Gustavo F. Fiscer
//Ver. 10/25/10
#include <iostream>
#include "DayofTheWeek.h"
#include <string>
using namespace std;

int main()
{
	DayofTheWeek day1;
	DayofTheWeek day2;

	cout << "Please type a day of the week: ";
	cin >> day1.getDay;//binary '>>': no operator found which takes a right-hand operand of type 'overloaded-function'(or there is no acceptable conversion)

	cout << day1.getDay << " is referred as to " << day1.getDay << endl;//"DayofTheWeek::getDay':function call missing argument list; use '&DayofTheWeek::getDay' to create a point to member (x2)
	
	
	return 0;
}




The errors are followed by /* */ and //, thanks again.
Was This Post Helpful? 0
  • +
  • -

#8 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: Getting the day of the week to be referenced as

Posted 26 October 2010 - 02:43 PM

Okay.
This is the first error
/*syntax error: missing ';' before identifier 'getDay', missing type specifier - int assumed. Note: C++ does not support default-int (x2), (Warning) 'getDay': missing return type; assumed to be a member function retuning 'int'*

You have not told the compiler what a "string" is.
You need to add an include to include the string library to that piece of code.
If you are writing classes you know how to do an include.

What you may not understand is the order that your compiler does thinks things in.
Worth Googling for "compiler preprocessor linker" or some search like that to see the order things are done in so you can understand why includes need to be where they need to be.

If you try for a while and can't fix it come back and ask some more showing us your full list of includes for every file.

This post has been edited by janotte: 26 October 2010 - 02:44 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1