we started classes, i need some pointers on my code if you can help
please.

Define a class called Month. Your class will have one attribute of type int to
represent a month (1 for January, 2 for February, and so forth). Include all the
following methods in this class:
(a) a constructor to set the month using the first three letters in the name of
the month as three arguments (‘J’ ‘A’ ‘N’ for January, ‘F’ ‘E’ ‘B’ for
February, and so forth),
( a constructor to set the month using an integer as an argument (1 for
January, 2 for February, and so forth),
a default constructor,
(d) an input function that reads the month as an integer,
(e) an input function that reads the month as the first three letters in the
name of the month,
(f) an output function that outputs the month as an integer,
(g) an output function that outputs the month as the first three letters in the
name of the month,
(h) and a member function that returns the next month as a value of type
Month.

heres my start
[#include<iostream>
#include<string>
using namespace std;

class Month{
public:
int month;
Month(int month);
Month(string& one,string& two,string& three);
Month();
void input1(intgoo month);
void input2(string one,string two,string three);
void output1();
void output2();
};


int main(){
Month month;
int m;
string one,two,three;

month.input1(m);
month.input2(one,two,three);


system("pause");
}

Month::Month(){
//nothing
}


void input1(int month){
cout<<"Enter the month as an integer: ";
cin>>month;
while(month<1||month>12){
cout<<"Wrong number.";
cin>>month;
}

}

void input2(string one,string two,string three){
int count=0;
cout<<"Enter the month as an string(3 letters): ";
while(count<3){
cin>>one;
cin>>two;
cin>>three;
count+=4;
}


}
]

Dani AI

Generated

— good start. The main conceptual problem is that your input functions are modifying local parameters, not the object. As suggested, member functions should set the class member directly (or you should pass by reference/return a value). Also avoid reading three separate strings/chars for a month; treat the three-letter abbreviation as one string and do a case-insensitive match.

Recommended design:

  • Keep the month as a private int (1..12).
  • Provide constructors: default, from int, from a 3-letter string.
  • Provide member I/O methods that operate on the object's member (e.g., readInt() / readAbbrev() and printInt() / printAbbrev()).
  • Provide next() that returns the following month (wrap from 12 to 1).
  • Validate input and use a fixed table of abbreviations for mapping.

Example implementation sketch (uses different names than your original code; reads the abbrev as one string and sets the object member):

#include <iostream>
#include <string>
#include <algorithm>
#include <limits>

class Month {
    int m_;
    static const char* const names_[12];
public:
    Month(): m_(1) {}
    explicit Month(int x): m_((x>=1 && x<=12) ? x : 1) {}
    Month(const std::string& abbr) { setFromAbbrev(abbr); }

    void setFromInt(int x) { if (x>=1 && x<=12) m_=x; }
    void setFromAbbrev(const std::string& s) {
        std::string t = s.substr(0,3);
        std::transform(t.begin(), t.end(), t.begin(), ::tolower);
        for (int i=0;i<12;++i) {
            std::string n(names_[i]);
            std::transform(n.begin(), n.end(), n.begin(), ::tolower);
            if (t == n) { m_ = i+1; return; }
        }
        m_ = 1; // fallback
    }

    void readInt() {
        int x;
        while (std::cout << "Month number: " && (std::cin >> x)) {
            if (x>=1 && x<=12) { m_ = x; break; }
            std::cout << "Invalid. Try again.\n";
        }
    }

    void readAbbrev() {
        std::string s;
        while (std::cout << "Month (3 letters): " && (std::cin >> s)) {
            if (s.size() >= 3) { setFromAbbrev(s); break; }
            std::cout << "Enter at least 3 letters.\n";
        }
    }

    void printInt() const { std::cout << m_; }
    void printAbbrev() const { std::cout << names_[m_-1]; }
    Month next() const { return Month(m_==12 ? 1 : m_+1); }
};

const char* const Month::names_[12] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};

Notes: avoid system("pause") (platform-specific). Prefer reading one string for the 3-letter input and normalizing case. Keep the object state private and have member functions operate on it rather than on parameters passed by value.

Use code tags.

[code]

// code here

[/code]

What's the question?

One thing that jumps out is that you are passing variables by value to a void function, changing those variables inside the function, then exiting the function, which does nothing. You need to either pass by reference instead of value or return something here:

void input1(int month){
cout<<"Enter the month as an integer: ";
cin>>month;
while(month<1||month>12){
cout<<"Wrong number.";
cin>>month;
}

}

Or if month is a class variable and this is a class function, don't pass month, since it will be passed with the class object. But the way you have it doesn't make sense.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.