Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,140 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,089 people online right now. Registration is fast and FREE... Join Now!




Problems with my code

 
Reply to this topicStart new topic

Problems with my code, Just need a little Debugging

kendel
post 4 Oct, 2008 - 07:10 PM
Post #1


New D.I.C Head

*
Joined: 4 Oct, 2008
Posts: 4

I just need a little help eliminating the errors... right now the problem seems to be here:


string FancyDateClass::getDayOfWeek(void){
// return the day of week (M, Tu, Wed...) based on the date.
// Use the follow equation to calculate a day of week integer:

int day = julianDate() % 7;


return day;

// Where: Monday = 0, Tues = 1, Wed = 3

}


Error:

error C2664: 'std::basic_string<_Elem,_Traits,_Ax>::basic_string(std::basic_string<_Elem,_Traits,_Ax>::_Has_debug_it)' : cannot convert parameter 1 from 'int' to 'std::basic_string<_Elem,_Traits,_Ax>::_Has_debug_it'

CODE

// DateProject.cpp : Defines the entry point for the console application.
//
/*specification: Create a date class with constructors and a destructor */
#include "stdafx.h"


#include <iostream>
#include <sstream>
#include <string>

using namespace std;



class FancyDateClass {
private:
    int day;
    int month;
    int year;    
    static int objectCount;
public:

    string toString(void);
    string getMonth(void);
    string getDayOfWeek(void);
    int julianDate(void);
    bool isLeapYear(void);
    
    
    
    
    
    int setDate(int theDay, int theMonth, int theYear);
//    int subtract(FancyDateClass &aDateObj);  
     void getDate(int &theDay, int &theMonth, int &theYear);
     void displayDate(void);

    
    //constructors
    FancyDateClass();
    FancyDateClass(int theDay, int theMonth, int theYear);
    FancyDateClass(const FancyDateClass &aDateObj);     
     //destructor
    ~FancyDateClass();  
};

int FancyDateClass::objectCount = 0;

// ================================================================================
=====================================


int main (void){
  


















}



// ================================================================================
=====================================
FancyDateClass::FancyDateClass(){
    //default constructor
    day = 0;
    month = 0;
    year = 0;
    objectCount++;

}

FancyDateClass::FancyDateClass(int theDay, int theMonth, int theYear){
     //parameterized constructor
     setDate(theDay, theMonth, theYear);
     objectCount++;
}

FancyDateClass::FancyDateClass(const FancyDateClass &aDateObj) {
    //copy constructor
    day = aDateObj.day;
    month = aDateObj.month;
    year = aDateObj.year;
    objectCount++;
}



FancyDateClass::~FancyDateClass() {
    //destructor
    objectCount--;
    cout << "Number of DateClass objects instantiated " << objectCount << endl;
}

int FancyDateClass::julianDate(void){
    //return the Julian date for the current date.  The equation to calculate the Julian date is:
    //this conversion algorithm is thanks to the work of Fliegel & Van Flandern

    int theJulianDate = ( 1461 * ( year + 4800 + ( month - 14 ) / 12 ) ) / 4 + ( 367 * ( month - 2 - 12 * ( ( month - 14 ) / 12 ) ) ) / 12 - ( 3 * ( ( year + 4900 + ( month - 14 ) / 12 ) / 100 ) ) / 4 + day - 32075;

    return theJulianDate;
}

string FancyDateClass::getDayOfWeek(void){
    // return the day of week (M, Tu, Wed...) based on the date.  
    // Use the follow equation to calculate a day of week integer:
    
    int day = julianDate() % 7;
    

    return day;

    // Where: Monday = 0, Tues = 1, Wed = 3
        
}

bool FancyDateClass::isLeapYear(){

    bool leapYear = (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0));

    return leapYear;
    
}
/*
    string FancyDateClass::toString(void){
    std::stringstream ss;
    int month = 10;
    string str;
    ss << month;
    ss >> str;

    return month;

}
*/



int FancyDateClass::setDate(int theDay, int theMonth, int theYear){
    //gives the member variables a value
    //returns an error code if invalid date is entered
    //Error codes: 0 -valid date, 3 - bad year, 2 - bad month, 1 bad day
    
    //check each arguement to ensure it is valid
    int dateCode = 0;

    //check the year
    //check the year
    if(theYear < 1)
        dateCode = 3;
    //check the month

    if(theMonth < 1 || theMonth > 12)
        dateCode = 2;

    //check the day
    int maxDays = 31;
    switch (theMonth) {
        case 2:
            maxDays = 28;
            break;
        case 4:
        case 6:
        case 9:
        case 11:
            maxDays = 30;
            break;
        break;
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
            maxDays = 31;
            break;
    }
    if (theDay < 1 || theDay > maxDays)
        dateCode = 1;
    
    //set the values right or wrong...
    month = theMonth;
    day = theDay;
    year = theYear;
    
    return dateCode;
}
void FancyDateClass::getDate(int &theDay, int &theMonth, int &theYear){
//set the value of the arguements
    theDay = day;
    theMonth = month;
    theYear = year;
}

void FancyDateClass::displayDate(void) {
    //display the date to the screen
    cout <<"\n\n";
    cout << "day : " << day << endl
        << "month : " << month << endl
        << "year : " << year << endl;
}


User is offlineProfile CardPM

Go to the top of the page

JackOfAllTrades
post 4 Oct, 2008 - 07:27 PM
Post #2


D.I.C Addict

Group Icon
Joined: 23 Aug, 2008
Posts: 501



Thanked 44 times

Dream Kudos: 25
My Contributions


Right, so your method signature says you are going to return a string, but you're trying to return an int. I think you need to change your method to return an int.

This post has been edited by JackOfAllTrades: 4 Oct, 2008 - 07:27 PM
User is offlineProfile CardPM

Go to the top of the page

kendel
post 4 Oct, 2008 - 09:02 PM
Post #3


New D.I.C Head

*
Joined: 4 Oct, 2008
Posts: 4

I tried adding this switch statement to it but the errors changed to:

error C2015: too many characters in constant
error C2593: 'operator =' is ambiguous
'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(_Elem)'
error C2106: '=' : left operand must be l-value
error C2664: 'std::basic_string<_Elem,_Traits,_Ax>::basic_string(std::basic_string<_Elem,_Traits,_Ax>::_Has_debug_it)' : cannot convert parameter 1 from 'int' to 'std::basic_string<_Elem,_Traits,_Ax>::_Has_debug_it'

How would you change that?

CODE

string FancyDateClass::getDayOfWeek(void){
    // return the day of week (M, Tu, Wed...) based on the date.  
    // Use the follow equation to calculate a day of week integer:
    
    int day = julianDate() % 7;
    std:string sday;

    switch(day){
        case 0:
            if(day == 0)
            sday = 'monday';  // monday = 0
            break;
        case 1:
            if(day == 1)
            sday = 'tuesday';                 
            break;
        case 2:
            if(day == 2)
            sday = 'wednesday'    
            break;
        case 3:
            if(day == 3)
            sday = 'thursday';
            break;
        case 4:
            if(day == 4)
            sday = 'friday';
            break;
        case 5:
            if(day == 5)
            sday = 'saturday';
            break;
        case 6:
            if(day == 6)
            sday = 'sunday';
            break;
    }
                
    

    return sday;

    // Where: Monday = 0, Tues = 1, Wed = 3
        
}


This post has been edited by kendel: 4 Oct, 2008 - 09:21 PM
User is offlineProfile CardPM

Go to the top of the page

JackOfAllTrades
post 4 Oct, 2008 - 09:18 PM
Post #4


D.I.C Addict

Group Icon
Joined: 23 Aug, 2008
Posts: 501



Thanked 44 times

Dream Kudos: 25
My Contributions


You're not understanding. It looks to me like the assignment is to return an integer *representing* the day of the week, *not* a string.
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/21/08 12:27PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month