This is my specification file, and my implementation file isnt working.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#ifndef DATE_H
#define DATE_H
#include <string>
class Date {
private:
int monthDefault;
int dayDefault;
int yearDefault;
std::string monthName;
public:
~Date(){}
int dayNumber(int);
void monthWord(int);
int yearNumber(int);
void showDates(int, int, int);
};
#endif
I know the main is supposed to be in another file, but if i do that it tells me some thing about winmain error, and im just testing it in the implementation file.
I know the main is supposed to be in another file, but if i do that it tells me some thing about winmain error,
This probably means that you selected the wrong type of program when you created your project. To use main() you should probably select a console program, not a Win32 program.
By the way it would help if you actually told us what is wrong with your code. If you're getting error messages post the complete messages, all of them exactly as they appear in your development environment.
You're missing a constructor. Also, in your main, dates.showDates requires 3 inputs, while you aren't giving any.
You already have a destructor, ~Date(){}, however you don't have a constructor. This would be your constructor Date(){}. The constructor doesn't have the ~.
When you create your object: Date dates(1, 1, 2000);, the (1, 1, 2000) part of it is the constructor, which takes in arguments when you create an object.
//this is in Date.h
#ifndef DATE_H
#define DATE_H
#include <string>
class Date {
public:
//this is your constructor here
Date(int day, int month, int year);
};
#endif
//this is Date.cpp
#include "Date.h"
#include <string>
#include <iostream>
//define what your constructor does
Date::Date(int day, int month, int year) {
//do whatever you want your constructor to do here
}
int main() {
//create your object
Date dates(1, 1, 2000);
//you were missing arguments here in your showDates call.
//did you mean for this to have no inputs, or did your forget to add any?
dates.showDates(2, 24, 2010);
}
PS the switch structure is workable but another way is to have an array of
std::string month_names[]= {'dummy", "January", "February", ...}, so you end up with the month name for a particular date =month_name[date.monthDefault]
You have a couple of "shadowed" warnings you need to fix.
ie:
1 2 3
int Date::yearNumber(int year)
{
int yearDefault = 2000;
Do you realize that that second line is creating another int variable named yearDefault that is local to that function? Any changes to that variable doesn't alter the class variable named yearDefault.
Also you don't initialize the month name in your constructor and you never call the monthWord function so the name will never have a value.