Could someone please assist me with my program errors.
I am writing a program using the List class that implements a To-Do list.
- The items in the list are strings.
The user should be prompted to enter a command:
- Mark an item as done or partially done
- Print the items in the list
Simply storing items in the list is easy, but the List class doesn't directly support the recording of the status of each task. When an item is created, it entes the Undone list. When its status is changed, it moves to one of the other lists as appropriate. Choose the approach that you prefer, and implement the application using proper style.
Any suggestions or help will be greatly appreciated. I would like to thank you in advance.
Here's my code for Main:
Code:
#include <iostream>
#include <fstream>
#include <string>
#include "list.h"
using namespace std;
int main()
{
ofstream outList;
outList.open("list.out");
int count;
int limit;
int optionNum;
List ToDo;
ItemType item[MAX_LENGTH];
ItemType status[MAX_LENGTH];
count = 0;
if (!outList)
{
cout << "Can't open file outList.out." << endl;
return 1;
}
cout << "Choose an option to perform " << endl;
cout << "on the To-Do list." << endl;
cout << " 1) Add an item" << endl;
cout << " 2) Mark an item as done or partial done" << endl;
cout << " 3) Delete an item" << endl;
cout << " 4) Print the list of item" << endl;
cout << "Enter your option number( 0 - quit ): ";
cin >> optionNum;
if (optionNum == 1)
{
cout << "Enter item name: ";
cin >> item[count];
status[count] = "Undone";
ToDo.Length();
ToDo.Insert(item[count], status[count]);
outList << item[count] << " " << status[count] << endl;
count++;
}
else if (optionNum == 2)
{
//cout << "You choice to mark an item." << endl;
cout << "Enter item name: ";
cin >> item[count];
cout << "Enter status: ";
cin >> status[count];
if (ToDo.IsPresent(item[count], status[count]))
{
cout << "Enter the new status: ";
cin >> status[count];
}
//cout << "Now what do I do?";
cout << endl;
}
else if (optionNum == 3)
{
cout << "You choice to delete an item." << endl;
cout << "Enter item name: ";
cin >> item[count];
while ( !ToDo.IsEmpty() && ToDo.IsPresent(item[count], status[count]))
ToDo.Delete(item[count], status[count]);
ToDo.Reset();
limit = ToDo.Length();
}
else if (optionNum == 4)
{
ToDo.Reset();
limit = ToDo.Length();
cout << "You choice to print the item in the list.";
cout << endl;
cout << "Item #" << "Item Name " << endl;
cout << "------" << "-----------" << endl;
for (count = 0; count < limit; count++)
{
//ToDo.GetNextItem();
cout << item[count] << " " << status[count];
cout << endl;
}
}
while (optionNum <= 4 && optionNum != 0)
{
cout << "Enter your option number: ";
cin >> optionNum;
if (optionNum == 1)
{
cout << "Enter item name: ";
cin >> item[count];
status[count] = "Undone";
ToDo.Length();
ToDo.Insert(item[count], status[count]);
outList << item[count] << " " << status[count] << endl;
count++;
}
else if (optionNum == 2)
{
//cout << "You choice to mark an item." << endl;
cout << "Enter item name: ";
cin >> item[count];
cout << "Enter status: ";
cin >> status[count];
if (ToDo.IsPresent(item[count], status[count]) )
{
cout << "Enter the new status: ";
cin >> status[count];
}
//cout << "Now what do I do?";
cout << endl;
}
else if (optionNum == 3)
{
cout << "You choice to delete an item." << endl;
cout << "Enter item name: ";
cin >> item[count];
while ( !ToDo.IsEmpty() && ToDo.IsPresent(item[count], status[count]))
ToDo.Delete(item[count], status[count]);
ToDo.Reset();
limit = ToDo.Length();
}
else if (optionNum == 4)
{
//ToDo.SelSort(); // Sort list
ToDo.Reset();
limit = ToDo.Length();
cout << "You choice to print the item in the list.";
cout << endl;
cout << "Item #" << "Item Name " << endl;
cout << "------" << "-----------" << endl;
for (count = 0; count < limit; count++)
{
//ToDo.GetNextItem();
cout << item[count] << " " << status[count];
cout << endl;
}
}
}
outList.close();
return 0;
}
Here is my code in list.cpp that cause the errors.
Code:
//**********************************************************************
void List::Delete ( /* in */ ItemType item, /* in */ ItemType status)
// Pre: length > 0 && item is assigned
// Post: IF item is in data array at entry
// First occurrence of item is no longer in array
// && length == length@entry - 1
// ELSE
// length and data array are unchanged
{
int index = 0; // Index variable
while ( index < length ) // if you use this code it will right to the list
// but if you comment it out and uncomment next line
// of code it will display 7 Build Errors
// for some reason it do not like
// item[length] != data[index]
//while ( index < length && item[length] != data[index] )
index++;
if (index < length )
{
data[index] = data[length-1]; // Remove item
dataStatus[index] = dataStatus[length-1]; // Remove status
length--;
}
}
//**********************************************************************
bool List::IsPresent( /* in */ ItemType item, /* in */ ItemType status) const
// Searches the list for item, reporting whether found
// Post: Function value is true, if item is in
// data[0 . . length-1] and is false otherwise
{
int index = 0;
while ( index < length ) // if you use this code it will right to the list
// but if you comment it out and uncomment next line
// of code it will display 7 Build Errors
// for some reason it do not like
// item[length] != data[index]
//while ( index < length && item[length] != data[index] )
index++;
return ( index < length );
}
Errors:
c:\Documents and Settings\Owner\Desktop\Assignment 3\list.cpp(71): error C2784: 'bool std::operator !=(const std::allocator<_Ty> &,const std::allocator<_Other> &)' : could not deduce template argument for 'const std::allocator<_Ty> &' from 'char'
c:\Documents and Settings\Owner\Desktop\Assignment 3\list.cpp(71): error C2784: 'bool std::operator !=(const std::istreambuf_iterator<_Elem,_Traits> &,const std::istreambuf_iterator<_Elem,_Traits> &)' : could not deduce template argument for 'const std::istreambuf_iterator<_Elem,_Traits> &' from 'char'
c:\Documents and Settings\Owner\Desktop\Assignment 3\list.cpp(71): error C2784: 'bool std::operator !=(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'char'
c:\Documents and Settings\Owner\Desktop\Assignment 3\list.cpp(71): error C2784: 'bool std::operator !=(const std::_Ptrit<_Ty,_Diff,_Pointer2,_Reference2,_Point er2,_Reference2> &,const std::_Ptrit<_Ty,_Diff,_Pointer,_Reference,_Pointer 2,_Reference2> &)' : could not deduce template argument for 'const std::_Ptrit<_Ty,_Diff,_Pointer2,_Reference2,_Point er2,_Reference2> &' from 'char'
c:\Documents and Settings\Owner\Desktop\Assignment 3\list.cpp(71): error C2784: 'bool std::operator !=(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'char'
c:\Documents and Settings\Owner\Desktop\Assignment 3\list.cpp(71): error C2677: binary '!=' : no global operator found which takes type 'ItemType' (or there is no acceptable conversion)
//c:\Documents and Settings\Owner\Desktop\Assignment 3\list.cpp(71): fatal error C1903: unable to recover from previous error(s); stopping compilation