Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

I having a problem with the status function..plz help

here what I have so far..
and here is the output result should be..
I having trouble with the status as notdone and done..
when you insert a thing that u need to do, it need to included the status of thing done or not done. and this is the problem I have to create a status function...thx

List[0]=Buy Groceries notDone

List[1]=Call friend notDone

List[2]=Study notDone

#include <iostream>
#include <string>
#include "ToDolist.h"

using namespace std;

TodoList::TodoList()

// Constructor

// Postcondition:
// length == 0

{
length = 0;
}

int TodoList::Length() const

{
return length;
}

void TodoList::Insert( /* in */ ItemType item )

// Inserts item

{
int index; // Index and loop control variable
index = length - 1;
while ((index >= 0) && (item < (data[index])))
{
data[index+1] = data[index];
data[index+1] = data[index];
index--;
}
data[index+1] = item;
TodoList::status(); // Insert item

length++;
}

void TodoList::BinSearch(
/* in */ ItemType item, // Item to be found
/* out */ bool& found, // True if item is found
/* out */ int& position ) const // Location if found

// Searches list for item, returning the indexof item if item was found.

{
int first = 0; // Lower bound on list
int last = length - 1; // Upper bound on list
int middle; // Middle index

found = false;
while (last >= first && !found)
{
middle = (first + last) / 2;
if (item < (data[middle]))
// Assert: item is not in data[middle..last]
last = middle - 1;
else if (data[middle] < (item))
// Assert: item is not in data[first..middle]
first = middle + 1;
else
// Assert: item == data[middle]
found = true;
}
if (found)
position = middle;
}

void TodoList::Delete( /* in */ ItemType item )

// Deletes item from the list, if it is there

{
bool found; // True if item is found
int position; // Position of item, if found
int index; // Index and loop control variable

BinSearch(item, found, position);
if (found)
{
// Shift data[position..length-1] up one position

for (index = position; index < length - 1; index++)
data[index] = data[index+1];
length--;
}
}

void TodoList::todotype()
{
cout<<"What would you like to do?"<<endl<<endl;

cout<<"Type 1 to add an item"<<endl;
cout<<"Type 2 to delete item"<<endl;
cout<<"Type 3 to mark item as done"<<endl;
cout<<"Type 4 to print to list of uncompleted items"<<endl;
cout<<"Type 5 to print the list of all items"<<endl<<endl;

}

void TodoList::status()
{
const int Num_row =2;

const string done="done";
const string Notdone="Notdone";

string donefunction[Num_row]={done,Notdone};

}

int TodoList::Typelist(int type)
{
string item;

if(type==1)
{
cout<<"ADD an item,please type your item"<<endl;
cin>>item;
TodoList::Insert(item);

}
if(type==2)
{
cout<<"DELETE an item, please type your item"<<endl;
cin>>item;
TodoList::Delete(item);
}
if(type==3)
{
cout<<"MARK ITEM DONE an item, please type your item"<<endl;
}
if(type==4)
{
cout<<"PRINT LIST OF UNCOMPLETED ITEMS"<<endl;
}

if(type==5)
{
cout<<"PRINT LIST OF ALL ITEMS"<<endl;
TodoList::Print();
}

return type;
}

void TodoList::Print()const
{
for (int i = 0; i < length; i++)
{
cout << data[i]<<endl;

}

}
[4465 byte] By [leoyous] at [2007-11-11 10:21:05]
# 1 Re: I having a problem with the status function..plz help
it would seem to me that you need a bool or a char or enum here (use a char for up to 255 states, use a bool if you know it will only ever have 2 states: for example if you wanted done, not done, in progress, on hold, other stuff you would use the char or an enum)

something like

void SetStatus(bool IsDone)
{
inserted_guy = IsDone;
}

void PrintStatus()
{
if (IsDone) cout << "Done"; else cout << "Not done";
}

etc where you will need to provide a scope for the things I assumed exist. I was unable to determine if you are using globals or a class or what to provide this?

Anyway, I think this is what you meant, to mark the data with a status, but it was very unclear what you really wanted to do with the strings?? if this is not what you want please explain it better.
jonnin at 2007-11-11 20:59:06 >