Форум С++

 

Ответить на сообщение

Вернуться к теме

Вы отвечаете на сообщение:

Автор: AI\EKCAH^P   (05.06.2009 в 20:08)
Программу переделал. Пункт в меню выбираю и все начинает мелькать.
Подскажите в чем дело.




#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <list>


struct Item
{
    char itsName[10];
    int itsPrice;
    int itsCount;
    Item* itsNext;
    Item* itsPrev;
};

struct List
{
    Item* itsFirst;
  Item* itsLast;
};

void menu();
void AddItem(List&);
void DeleteItem(List&);
void PrintList(List&);
void CreateList (List*&);
List* theList = 0;

int main()

{
List* itsFirst=0;
List* itsLast=0;
   menu();
   getche();
   return 0;
}

void menu()
{
    bool quit = false;
    while (true)
    {
    int choice;
    printf(" ******* MENU *********** \n\n\n" );
    printf("(1) vvedite spisok \n" );
    printf"(2) prosmotr \n");
    printf("(3) dobavlenie \n");
    printf("(4) udalenie \n");
    printf("(5) vyhod \n" );
    
    scanf(" ",choice);
  
    switch (choice)
    {
    case(1):
        if (!theList)
        {
             CreateList (theList);
            theList->itsFirst = 0;
            theList->itsLast = 0;
            printf("the List has been created succesfully...");
        }
        else
            printf("the List is already created..." );
        break;
    case(2):
        if (theList)
            PrintList(*theList);
        else
            printf("the List is not created...");
        break;
    case(3):
        if (theList)
            AddItem(*theList);
        else
            printf("the List is not created...");
        break;
    case 4:
        if (theList)
            DeleteItem(*theList);
        else
            printf("the List is not created...");
        break;
    case(5):
        quit = true;
    }
    if (quit == true)
        break;
    }
}


void AddItem(List& theList)
{
    printf("*** dobavit' novuy tovar ***");
    printf("vvedite nazvanie: ");
    Item* newItem = new Item;
    gets(newItem->itsName);
    printf("vvedite cenu: ");
    scanf(" ",newItem->itsPrice);
    printf("vvedite kolichestvo: ");
    scanf(" ",newItem->itsCount);
    if (theList.itsLast)
    {
        theList.itsLast->itsNext = newItem;
        newItem->itsPrev = theList.itsLast;
    }
    else
    {
        theList.itsFirst = newItem;
        newItem->itsPrev = 0;
    }
    theList.itsLast = newItem;
    newItem->itsNext = 0;
    printf("*** item was added successfully ***");
}
void CreateList ( List*& pList)
{
    pList = new List;
  printf"*** vvedite tovar ***");
  printf("vvedite nazvanie: ");
    Item* newItem = new Item;
   scanf(" ", newItem->itsName);
  printf"vvedite cenu: " );
  printf(" ", newItem->itsPrice);
  printf("vvedite kolichestvo: ");
    scanf" ",newItem->itsCount);
    }
void PrintList(List& theList)
{
    printf("*** list content ***");
    Item* curItem = theList.itsFirst;
    while (curItem)
    {
        printf(curItem->itsName , " " ,curItem->itsPrice , "$ " ,curItem->itsCount ," ones." );
        curItem = curItem->itsNext;
    }
    printf("*** end ***" );
}

void DeleteItem(List& theList)
{
    Item* curItem = theList.itsFirst;
    int Pos;
    printf("Enter the position of deleted item: ");
    scanf(" ",Pos);
    printf(" ",Pos);
    for (int i=0; i<Pos ; i++) 
    {
        if (curItem)
            curItem = curItem->itsNext;
    }
    if (curItem && (Pos >= 0))
    {
        if (curItem->itsPrev)
        {
            curItem->itsPrev->itsNext = curItem->itsNext;
        }
        else
        {
            theList.itsFirst = curItem->itsNext;
        }
        if (curItem->itsNext)
        {
            curItem->itsNext->itsPrev = curItem->itsPrev;
        }
        else
        {
            theList.itsLast = curItem->itsPrev;
        }
        delete curItem;
        printf("Item № ", Pos ," has been deleted successfully..." ); 
    }
    else
        printf("Item № ", Pos , " not found..." );

}


Ваше имя:

Пароль:

Цитировать

Используйте тэги для выделения текста:
Код: [code][/code]
Жирный: [b][/b]
Наклонный: [i][/i]
URL: [url][/url]

Сообщение:

Прикрепить: