C++ Help

closed account (49ECpfjN)
I am having some difficulty with this. Here is what I got so far:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// DaysOfTheWeek.cpp : main project file.
#include <iostream>
#include <string>

using namespace std;

class DaysOfTheWeek
{
public:
    // member funtions should be declared under the public section
    void setDay(string);
        // setDay(string) takes a string parameter and stores the value in the day attribute.
    void printDay();
        // printDay() prints the value of the day attribute on console output (cout).
    string getDay(string&);
        // retuns the value of the day attribute.
private:
    // data members should be declared under private section
    string day; // this is where the value of the day attribute is stored.
};
void DaysOfTheWeek::setDay(string day)
{
    string Monday = "Mon";
    string Tuesday = "Tues";
    string Wednesday = "Wed";
    string Thursday = "Thurs";
    string Friday = "Fri";
    string Saturday = "Sat";
    string Sunday = "Sun";
}
void DaysOfTheWeek::printDay()
{
    cout << "The value of the " << &DaysOfTheWeek::getDay << " object is " << &DaysOfTheWeek::setDay << endl;
}
string DaysOfTheWeek::getDay (string&)
{
    return day;
}

int main()
{
    DaysOfTheWeek monday;
    DaysOfTheWeek tuesday;
    string day = " ";
    monday.setDay("Mon");
    string day1 = monday.getDay(day);
    monday.printDay();
    tuesday.setDay("Tues");
    string day2 = tuesday.getDay(day);
    tuesday.printDay();

    // set the values of the objects
    // get the value for the Monday object and print it out
    // print out the value of the Tuesday object
    return 0;
}

I am getting "The value of the 1 object is 1" instead of Monday and Mon or Tuesday and Tues. I would appreciate any help.
Your setter function isn't assigning its parameter to anything.
Yeah, I can't see what your trying to do with setDay(), it just doesn't make sense.

Passing a string as day, initializing a rather temporary bunch of variables with constant strings.

It looks like you are required to make class with functions to get/set a private (unaccessible) variable.

Pretty simple.
1
2
3
4
5
6
7
8
9
void DaysOfTheWeek::setDay(string newDay)
{
    day = newDay;
}

string DaysOfTheWeek::getDay()
{
    return day;
}
Topic archived. No new replies allowed.