Log in

View Full Version : [bingung] Kok Logic error gan ni C++ program


Darkc0der
20th November 2011, 10:56 AM
Maaf gan bukan bermaksud ngejunk, tapi mau nanya nih letak kesalahan ane apaan, ngak ada error tapi kok hasil aneh gt yg keluarnya.



mohon bantuannya yah gan, kasih tahu aja apa yg salah,

nih tugas kuliah ane nih.




Spoiler for nih soalannya gan:






A) Design and implement a class dayType that implements the day of the week in a program. The class dayType should store the day, such as Sun for Sunday. The program should be able to perform the following operations on an object of type dayType:

a. Set the day

b. Print the day

c. Return the day

d. Return the next day

e. Return the previous day

f. Calculate and return the day by adding certain days to the current day. For example if the current day is Monday and we add 4 days, the day to be returned is Friday. Similarly, if today is Tuesday and we add 13 days, the day to be returned is Monday.

g. Add the appropriate constructors.













ini nih gan hasil jerih payah ane

<div style="margin:20px; margin-top:5px">
Spoiler for codingnya:


<div class="alt2" style="margin: 0px; padding: 6px; border: 1px inset;">
<div style="display: none;">


#include

#include



using namespace std;

class dayType

{

public:

void setDay (char day);

void nextDay ();

void returnDay();

void printDay ()const

void calculate();



private:

string dayofweek [7];

int current;

char userEntry;

};



//end header file







using namespace std;



void dayType::setDay(char day)

{

if ( day == 'm' || day == 'M' )

{

(dayofweek [0] == "MONDAY");

current = 1;

userEntry = day;

}





if ( day == 't' || day == 'T' )

{

(dayofweek [1] == "TUESDAY");

current = 2;

userEntry = day;

}





if ( day == 'w' || day == 'W' )

{

(dayofweek [2] == "WEDNESDAY");

current = 3;

userEntry = day;

}





if ( day == 'r' || day == 'R' )

{

(dayofweek [3] == "THURSDAY");

current = 4;

userEntry = day;

}





if ( day == 'f' || day == 'F' )

{

(dayofweek [4] == "FRIDAY");

current = 5;

userEntry = day;

}





if ( day == 's' || day == 'S' )

{

(dayofweek [5] == "SATURDAY");

current = 6;

userEntry = day;

}



if ( day == 'u' || day == 'U' )

{

(dayofweek [6] == "SUNDAY");

current = 7;

userEntry = day;

}



}



void dayType::nextDay()

{

{

current++;

if (current = 7)

current = 0;

}



{

current++;

if (current = 6)

current = 7;

}



{

current++;

if (current = 5)

current = 6;

}



{

current++;

if (current = 4)

current = 5;

}



{

current++;

if (current = 4)

current = 5;

}



{

current++;

if (current = 3)

current = 4;

}



{

current++;

if (current = 2)

current = 3;

}



{

current++;

if (current = 1)

current = 2;

}



}



void dayType:: printDay() const

{

cout