473,511 Members | 9,983 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

containers iterators pointers. please help (urgent)

Hello,

i am struggling the whole night cos of my c++ homework. deadline is very
soon. (april 4th)

i have to implement a calender.

i store every calender entry in a list. a calender entry is a struct with
entry, date, time, type.
the problem is: if i use the change-function to add a (optional) time to an
existing entry, it seems to work.(the function gets the right Record out of
the list, the output (for testing) is fine, it seems really like the
function would set the hour and minute to the Record)
but when i use the print-function, the entry hasn't changed and there is no
time added.

i have no idea, why. no idea, how to find out where the mistake is.

thank you very much in advance for trying to help.

here the 3 parts of the code:

here is the "class-part" of the header-file:

***beginn of code***
class Calendar
{

// definition of the interface
public:

// constructor
Calendar();

// descructor
~Calendar();

bool print(int day, int month, int year,
int type
);

bool add(string entry, int type,
int day, int month, int year,
int hour, int minute,
bool noTime, bool noType
);

bool change(string entry,
int oldDay, int oldMonth, int oldYear,
int newDay, int newMonth, int newYear,
int newHour, int newMinute,
bool changeTime
);

bool del(string entry,
int day, int month, int year
);

bool readFile(string fileName);

bool writeFile(string fileName);


// hidden implementation details
private:
struct Record{

int day, month, year;
int hour, minute;
int type;
string entry;
bool noTime;
bool noType;

};
//set<Record> table;
list<Record> table;

bool equal(Record a, Record b);

// Calendar ( const Calendar& q);
// Calendar& operator = ( const Calendar& q );
};
***end of code***
and here is the "change-function"

***begin of code***
bool Calendar::change(string entry,
int oldDay, int oldMonth, int oldYear,
int newDay, int newMonth, int newYear,
int newHour, int newMinute, bool changeTime)
{
Record tmp;
tmp.entry = entry;
tmp.day = oldDay;
tmp.month = oldMonth;
tmp.year = oldYear;

//runs to the Record that should be changed
list<Record>::iterator i = table.begin();
while( i != table.end() && !equal( *i, tmp) ){
++i;
}

if( i == table.end() )
{
cerr << "Error: unknown entry" << endl;
return false;
}
else{
cout << "found:" << endl;
cout << i->entry << endl;
cout << i->day << i->month << i->year << endl;
if( changeTime )
{
i->hour = newHour;
cout << "i->hour is " << i->hour << endl;
i->minute = newMinute;
cout << "i->minute is " << i->minute << endl;

}
else
{
i->day = newDay;
i->month = newMonth;
i->year = newYear;
}
return true;
}
}

***end of code***
and last but not least the "print - function"
*beginn of code***
bool Calendar::print( int day, int month, int year,
int type)
{

for( list<Record>::iterator i = table.begin();
i != table.end(); ++i)
{
if( i->day == day && i->month == month && i->year == year
&& (i->type == type || type == ALL) )
{
cout << i->entry;
if( !i->noTime )
{
cout << " " << i->hour << " " << i->minute ;
}
cout <<endl;
}

}
return true;
}
***end of code***
Jul 23 '05 #1
1 1503
SORRY, SORRY!

I found my stupid mistake, so it was no mysterium, just a stupid wrong
thought.
So you don't need to read all the bad code.

(I wish I could erase the post).

cu

"progII" <no******@students.cc.tut.fi> schrieb im Newsbeitrag
news:d2**********@news.cc.tut.fi...
Hello,

i am struggling the whole night cos of my c++ homework. deadline is very
soon. (april 4th)

i have to implement a calender.

i store every calender entry in a list. a calender entry is a struct with
entry, date, time, type.
the problem is: if i use the change-function to add a (optional) time to an existing entry, it seems to work.(the function gets the right Record out of the list, the output (for testing) is fine, it seems really like the
function would set the hour and minute to the Record)
but when i use the print-function, the entry hasn't changed and there is no time added.

i have no idea, why. no idea, how to find out where the mistake is.

thank you very much in advance for trying to help.

here the 3 parts of the code:

here is the "class-part" of the header-file:

***beginn of code***
class Calendar
{

// definition of the interface
public:

// constructor
Calendar();

// descructor
~Calendar();

bool print(int day, int month, int year,
int type
);

bool add(string entry, int type,
int day, int month, int year,
int hour, int minute,
bool noTime, bool noType
);

bool change(string entry,
int oldDay, int oldMonth, int oldYear,
int newDay, int newMonth, int newYear,
int newHour, int newMinute,
bool changeTime
);

bool del(string entry,
int day, int month, int year
);

bool readFile(string fileName);

bool writeFile(string fileName);


// hidden implementation details
private:
struct Record{

int day, month, year;
int hour, minute;
int type;
string entry;
bool noTime;
bool noType;

};
//set<Record> table;
list<Record> table;

bool equal(Record a, Record b);

// Calendar ( const Calendar& q);
// Calendar& operator = ( const Calendar& q );
};
***end of code***
and here is the "change-function"

***begin of code***
bool Calendar::change(string entry,
int oldDay, int oldMonth, int oldYear,
int newDay, int newMonth, int newYear,
int newHour, int newMinute, bool changeTime)
{
Record tmp;
tmp.entry = entry;
tmp.day = oldDay;
tmp.month = oldMonth;
tmp.year = oldYear;

//runs to the Record that should be changed
list<Record>::iterator i = table.begin();
while( i != table.end() && !equal( *i, tmp) ){
++i;
}

if( i == table.end() )
{
cerr << "Error: unknown entry" << endl;
return false;
}
else{
cout << "found:" << endl;
cout << i->entry << endl;
cout << i->day << i->month << i->year << endl;
if( changeTime )
{
i->hour = newHour;
cout << "i->hour is " << i->hour << endl;
i->minute = newMinute;
cout << "i->minute is " << i->minute << endl;

}
else
{
i->day = newDay;
i->month = newMonth;
i->year = newYear;
}
return true;
}
}

***end of code***
and last but not least the "print - function"
*beginn of code***
bool Calendar::print( int day, int month, int year,
int type)
{

for( list<Record>::iterator i = table.begin();
i != table.end(); ++i)
{
if( i->day == day && i->month == month && i->year == year
&& (i->type == type || type == ALL) )
{
cout << i->entry;
if( !i->noTime )
{
cout << " " << i->hour << " " << i->minute ;
}
cout <<endl;
}

}
return true;
}
***end of code***

Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2370
by: Ney André de Mello Zunino | last post by:
Hello. A non-modifying algorithm I implemented uses two associative containers from STL: set and map. The elements on those containers are supposed to refer to actual elements which lie on...
4
3528
by: Merlin | last post by:
Hi, I am a C++ developer and would like to implement container classes for various types of objects. I use MS Visual C++ to compile my code. Nevertheless I like to write code that is independent...
18
2178
by: Simon | last post by:
Hi, I understand what one the differences between std::vector, std::deque and std::list is, the std::vector can have data inserted/deleted at the end. The std::deque can have data...
23
6508
by: Sanjay Kumar | last post by:
Folks, I am getting back into C++ after a long time and I have this simple question: How do pyou ass a STL container like say a vector or a map (to and from a function) ? function: ...
21
2191
by: George Exarchakos | last post by:
Hi everyone, I'd like your help... Can we have a std::list<BASEwhere BASE be the base class of a class hierarchy? I want to add to this list objects that are inherited from BASE class but not...
0
7251
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7148
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7089
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5673
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3217
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
790
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
451
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.