Help with Classes !!! (Homework)

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2005
Posts: 16
Reputation: cymerman is an unknown quantity at this point 
Solved Threads: 0
cymerman cymerman is offline Offline
Newbie Poster

Help with Classes !!! (Homework)

 
0
  #1
Jul 23rd, 2005
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



  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. }
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 466
Reputation: winbatch is on a distinguished road 
Solved Threads: 18
winbatch's Avatar
winbatch winbatch is offline Offline
Posting Pro in Training

Re: Help with Classes !!! (Homework)

 
0
  #2
Jul 23rd, 2005
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...
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 26
Reputation: Rearden is an unknown quantity at this point 
Solved Threads: 0
Rearden's Avatar
Rearden Rearden is offline Offline
Light Poster

Re: Help with Classes !!! (Homework)

 
0
  #3
Jul 23rd, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 16
Reputation: cymerman is an unknown quantity at this point 
Solved Threads: 0
cymerman cymerman is offline Offline
Newbie Poster

Re: Help with Classes !!! (Homework)

 
0
  #4
Jul 23rd, 2005
OK. Thanks for the explanation. I fixed.
Do you see anything else wrong ?
What am I missing ?
Coulf you please give me a hint ?
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 16
Reputation: cymerman is an unknown quantity at this point 
Solved Threads: 0
cymerman cymerman is offline Offline
Newbie Poster

Re: Help with Classes !!! (Homework)

 
0
  #5
Jul 23rd, 2005
A switch inside a function on a class ? Is that OK ?
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,039
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: Help with Classes !!! (Homework)

 
0
  #6
Jul 24th, 2005
int main();
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 16
Reputation: cymerman is an unknown quantity at this point 
Solved Threads: 0
cymerman cymerman is offline Offline
Newbie Poster

Re: Help with Classes !!! (Homework)

 
0
  #7
Jul 24th, 2005
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)
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 466
Reputation: winbatch is on a distinguished road 
Solved Threads: 18
winbatch's Avatar
winbatch winbatch is offline Offline
Posting Pro in Training

Re: Help with Classes !!! (Homework)

 
0
  #8
Jul 24th, 2005
Post the offending line or full code..
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 16
Reputation: cymerman is an unknown quantity at this point 
Solved Threads: 0
cymerman cymerman is offline Offline
Newbie Poster

Re: Help with Classes !!! (Homework)

 
0
  #9
Jul 24th, 2005
ahahahahahah

  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. }
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 466
Reputation: winbatch is on a distinguished road 
Solved Threads: 18
winbatch's Avatar
winbatch winbatch is offline Offline
Posting Pro in Training

Re: Help with Classes !!! (Homework)

 
0
  #10
Jul 24th, 2005
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();
}
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC