Ceriwis  

Go Back   Ceriwis > HOBI > Komputer & Teknologi > Programming

Programming Share, tanya jawab, saling bantu antar programmer dengan berbagai macam bahasa pemrograman.

Reply
 
Thread Tools
  #1  
Old 20th November 2011
Darkc0der Darkc0der is offline
Ceriwiser
 
Join Date: Nov 2011
Posts: 598
Rep Power: 14
Darkc0der mempunyai hidup yang Normal
Default [bingung] Kok Logic error gan ni C++ program

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


Spoiler for codingnya:






#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

Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


 


All times are GMT +7. The time now is 05:59 PM.


no new posts