944,194 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 5719
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Jul 23rd, 2005
0

Help with Classes !!! (Homework)

Expand Post »
I am doing an assignment that has to use a class dayType.
The program has to set the day, print the day and return the next day.
I am receiving the error:
--------------------Configuration: Program9 - Win32 Debug--------------------
Compiling...
Program9.cpp
C:\Documents and Settings\Faculdade\ISM3232\Assig9\Program9\Program9.cpp(45) : error C2447: missing function header (old-style formal list?)
Error executing cl.exe.

Program9.exe - 1 error(s), 0 warning(s)

Can somebody help me please ?
I am reading the book 100 times but can figure out what is happening.
Thanks a lot



C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class dayType
  7. {
  8. public:
  9. void setDay(char day);
  10. void nextDay();
  11. void printDay() const;
  12.  
  13. private:
  14. string dayofweek[7];
  15. int current;
  16. char userEntry;
  17. };
  18.  
  19. int main();
  20. {
  21. dayType myDay;
  22. char day;
  23.  
  24. cout << "Please enter M for Monday, T for Tuesday, W for Wednesday" << endl;
  25. cout << "R for Thursday, F for Friday, S for Saturday or U for Sunday" << endl;
  26. cout << endl;
  27.  
  28. cin >> day;
  29.  
  30. myDay.setDay(day); // set the day
  31. cout << endl;
  32. myDay.printDay() const; // print the day
  33. cout << endl;
  34. myDay.nextDay(); // return the next day
  35. cout << endl;
  36.  
  37. cout << myDay.printDay() << endl;
  38.  
  39. return 0;
  40. } // end of main
  41.  
  42. void dayType::setDay(char day)
  43. {
  44. if (day = "m" || "M")
  45. {
  46. (dayofweek [0] == "MONDAY");
  47. current = 1;
  48. userEntry = day;
  49. }
  50.  
  51. if (day = "t" || "T")
  52. {
  53. (dayofweek [1] == "TUESDAY");
  54. current = 2;
  55. userEntry = day;
  56. }
  57.  
  58. if (day = "w" || "W")
  59. {
  60. (dayofweek [2] == "WEDNESDAY");
  61. current = 3;
  62. userEntry = day;
  63. }
  64.  
  65. if (day = "r" || "R")
  66. {
  67. (dayofweek [3] == "THURSDAY");
  68. current = 4;
  69. userEntry = day;
  70. }
  71.  
  72. if (day = "f" || "F")
  73. {
  74. (dayofweek [4] == "FRIDAY");
  75. current = 5;
  76. userEntry = day;
  77. }
  78.  
  79. if (day = "s" || "S")
  80. {
  81. (dayofweek [5] == "SATURDAY");
  82. current = 6;
  83. userEntry = day;
  84. }
  85.  
  86. if (day = "u" || "U")
  87. {
  88. (dayofweek [6] == "SUNDAY");
  89. current = 7;
  90. userEntry = day;
  91. }
  92. }
  93.  
  94. void dayType::nextDay()
  95. {
  96. {
  97. current++;
  98. if (current = 7)
  99. current = 0;
  100. }
  101.  
  102. {
  103. current++;
  104. if (current = 6)
  105. current = 7;
  106. }
  107.  
  108. {
  109. current++;
  110. if (current = 5)
  111. current = 6;
  112. }
  113.  
  114. {
  115. current++;
  116. if (current = 4)
  117. current = 5;
  118. }
  119.  
  120. {
  121. current++;
  122. if (current = 3)
  123. current = 4;
  124. }
  125.  
  126. {
  127. current++;
  128. if (current = 2)
  129. current = 3;
  130. }
  131.  
  132. {
  133. current++;
  134. if (current = 1)
  135. current = 2;
  136. }
  137. }
  138.  
  139. void dayType::printDay() const
  140. {
  141. cout << "The day is: " << dayofweek << endl;
  142. printDay();
  143. }
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cymerman is offline Offline
16 posts
since Mar 2005
Jul 23rd, 2005
0

Re: Help with Classes !!! (Homework)

Couple of problems:

if (day = "m" || "M")

must be

if ( day == 'm' || day == 'M' )
because day is a single character. (Even if it were a string you couldn't do a comparison like that, you'd need to use strcmp)

You must specify day once for each comparison. Plus, you want to do double = if you are checking for equality. A single = sets a variable...
Reputation Points: 68
Solved Threads: 18
Posting Pro in Training
winbatch is offline Offline
466 posts
since Feb 2005
Jul 23rd, 2005
0

Re: Help with Classes !!! (Homework)

The setday and nextday functions may be candidates for a switch. Which would be good because you can have it do something then in the default case if the user inputs something besides a char that corresponds to a day of the week.
Reputation Points: 10
Solved Threads: 0
Light Poster
Rearden is offline Offline
26 posts
since Jul 2005
Jul 23rd, 2005
0

Re: Help with Classes !!! (Homework)

OK. Thanks for the explanation. I fixed.
Do you see anything else wrong ?
What am I missing ?
Coulf you please give me a hint ?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cymerman is offline Offline
16 posts
since Mar 2005
Jul 23rd, 2005
0

Re: Help with Classes !!! (Homework)

A switch inside a function on a class ? Is that OK ?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cymerman is offline Offline
16 posts
since Mar 2005
Jul 24th, 2005
0

Re: Help with Classes !!! (Homework)

int main();
Team Colleague
Reputation Points: 1135
Solved Threads: 173
Super Senior Demiposter
Rashakil Fol is offline Offline
2,480 posts
since Jun 2005
Jul 24th, 2005
0

Re: Help with Classes !!! (Homework)

How do I get rid of this error:

Deleting intermediate files and output files for project 'Program9 - Win32 Debug'.
--------------------Configuration: Program9 - Win32 Debug--------------------
Compiling...
Program9.cpp
c:\documents and settings\faculdade\ism3232\assig9\program9\program9.cpp(45) : error C2447: missing function header (old-style formal list?)
Error executing cl.exe.

Program9.exe - 1 error(s), 0 warning(s)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cymerman is offline Offline
16 posts
since Mar 2005
Jul 24th, 2005
0

Re: Help with Classes !!! (Homework)

Post the offending line or full code..
Reputation Points: 68
Solved Threads: 18
Posting Pro in Training
winbatch is offline Offline
466 posts
since Feb 2005
Jul 24th, 2005
0

Re: Help with Classes !!! (Homework)

ahahahahahah

C++ Syntax (Toggle Plain Text)
  1. #include <iostream> // library to use cin and cout
  2. #include <string> // library to strings
  3.  
  4. using namespace std;
  5.  
  6. class dayType
  7. {
  8. public:
  9. void setDay(char day);
  10. void nextDay();
  11. void printDay() const;
  12.  
  13. private:
  14. string dayofweek[7];
  15. int current;
  16. char userEntry;
  17. };
  18.  
  19. int main();
  20. {
  21. dayType myDay; // class named dayType - object named myDay
  22. char day;
  23.  
  24. cout << "Please enter M for Monday, T for Tuesday, W for Wednesday" << endl;
  25. cout << "R for Thursday, F for Friday, S for Saturday or U for Sunday" << endl;
  26. cout << endl;
  27.  
  28. cin >> day;
  29.  
  30. myDay.setDay(day); // set the day
  31. cout << endl;
  32. myDay.printDay() const; // print the day
  33. cout << endl;
  34. myDay.nextDay(); // return the next day
  35. cout << endl;
  36.  
  37. cout << myDay.printDay() << endl;
  38.  
  39. return 0;
  40. } // end of main
  41.  
  42. void dayType::setDay(char day)
  43. {
  44. if ( day == 'm' || day == 'M' )
  45. {
  46. (dayofweek [0] == "MONDAY");
  47. current = 1;
  48. userEntry = day;
  49. }
  50.  
  51. if ( day == 't' || day == 'T' )
  52. {
  53. (dayofweek [1] == "TUESDAY");
  54. current = 2;
  55. userEntry = day;
  56. }
  57.  
  58. if ( day == 'w' || day == 'W' )
  59. {
  60. (dayofweek [2] == "WEDNESDAY");
  61. current = 3;
  62. userEntry = day;
  63. }
  64.  
  65. if ( day == 'r' || day == 'R' )
  66. {
  67. (dayofweek [3] == "THURSDAY");
  68. current = 4;
  69. userEntry = day;
  70. }
  71.  
  72. if ( day == 'f' || day == 'F' )
  73. {
  74. (dayofweek [4] == "FRIDAY");
  75. current = 5;
  76. userEntry = day;
  77. }
  78.  
  79. if ( day == 's' || day == 'S' )
  80. {
  81. (dayofweek [5] == "SATURDAY");
  82. current = 6;
  83. userEntry = day;
  84. }
  85.  
  86. if ( day == 'u' || day == 'U' )
  87. {
  88. (dayofweek [6] == "SUNDAY");
  89. current = 7;
  90. userEntry = day;
  91. }
  92. }
  93.  
  94. void dayType::nextDay()
  95. {
  96. {
  97. current++;
  98. if (current = 7)
  99. current = 0;
  100. }
  101.  
  102. {
  103. current++;
  104. if (current = 6)
  105. current = 7;
  106. }
  107.  
  108. {
  109. current++;
  110. if (current = 5)
  111. current = 6;
  112. }
  113.  
  114. {
  115. current++;
  116. if (current = 4)
  117. current = 5;
  118. }
  119.  
  120. {
  121. current++;
  122. if (current = 3)
  123. current = 4;
  124. }
  125.  
  126. {
  127. current++;
  128. if (current = 2)
  129. current = 3;
  130. }
  131.  
  132. {
  133. current++;
  134. if (current = 1)
  135. current = 2;
  136. }
  137. }
  138.  
  139. void dayType::printDay() const
  140. {
  141. cout << "The day is: " << dayofweek << endl;
  142. printDay();
  143. }
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cymerman is offline Offline
16 posts
since Mar 2005
Jul 24th, 2005
0

Re: Help with Classes !!! (Homework)

A couple of issues:


int main(); should be int main() (no ;)

myDay.printDay() const; should be myDay.printDay();
You can't do this:
cout << myDay.printDay() << endl;

because printDay() does not return anything (it returns void)

Also,

You'll end up with some kind of endless loop/recursion here as you are calling your self inside:
void dayType::printDay() const
{
cout << "The day is: " << dayofweek << endl;
printDay();
}
Reputation Points: 68
Solved Threads: 18
Posting Pro in Training
winbatch is offline Offline
466 posts
since Feb 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: side-effect of the point assignment
Next Thread in C++ Forum Timeline: Enabling ACK's with UDP, how to? - C++





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC