Форум С++

 

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

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

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

Автор: AI\EKCAH^P   (06.06.2009 в 12:20)
Выбираю ввод списка,ввожу данные,а просмотр показывает,что ничего не ввел.
Может ввод списка не работает? Подскажите.

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

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("\n ******* MENU *********** \n" );
    printf("(1) vvedite spisok \n" );
    printf"(2) prosmotr \n");
    printf("(3) dobavlenie \n");
    printf("(4) udalenie \n");
    printf("(5) vyhod \n" );
    
    scanf("%d",&choice);
  
    switch (choice)
    {
    case(1):
        if (!theList)
        {
             CreateList (theList);
            theList->itsFirst = 0;
            theList->itsLast = 0;
            printf(" the List has been created succesfully... \n");
        }
        else
            printf(" the List is already created...\n" );
        break;
    case(2):
        if (theList)
            PrintList(*theList);
        else
            printf(" the List is not created...\n");
        break;
    case(3):
        if (theList)
            AddItem(*theList);
        else
            printf(" the List is not created...\n");
        break;
    case 4:
        if (theList)
            DeleteItem(*theList);
        else
            printf(" the List is not created... \n");
        break;
    case(5):
        quit = true;
    }
    if (quit == true)
        break;
    }
}


void AddItem(List& theList)
{
    printf("\n *** dobavit' novuy tovar *** \n");
    printf(" vvedite nazvanie: ");
    Item* newItem = new Item;
    scanf("%s",&newItem->itsName);
    printf(" vvedite cenu: ");
    scanf("%f",&newItem->itsPrice);
    printf(" vvedite kolichestvo: ");
    scanf("%d",&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 *** \n");
}
void CreateList (List*&)
{ Item* pList,* p;
Item* itsFirst;
Item* itsLast;
    pList = NULL;
    do {p=(Item*)malloc(sizeof(Item));
  printf"*** vvedite tovar *** \n");
  printf(" vvedite nazvanie: ");
    Item* newItem = new Item;
   scanf("%s", newItem->itsName);
  printf" vvedite cenu: " );
  scanf("%f", &newItem->itsPrice);
  printf(" vvedite kolichestvo: ");
    scanf"%d",&newItem->itsCount);
    p->itsPrev=pList;
    if (pList != NULL)
    pList->itsNext=p;
    else
    itsFirst=p;
    pList=p;
    puts(" Zakonchit' - <esc>"
);
    }
 while (getch()!=27);
    itsLast=p;
    itsLast->itsNext=NULL;
    }
void PrintList(List& theList)
{
    printf("\n *** prosmotr spiska *** \n");
    Item* curItem = theList.itsFirst;
    while (curItem)
    {
        printf("%s\n",curItem->itsName);
        printf("%f\n",&curItem->itsPrice);
        printf("%d\n",&curItem->itsCount);
        curItem = curItem->itsNext;
    }
    printf("\n *** end *** \n" );
}

void DeleteItem(List& theList)
{
    Item* curItem = theList.itsFirst;
    int Pos;
    printf" Enter the position of deleted item: \n");
    scanf("%d",Pos);
    printf("%d",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]

Сообщение:

Прикрепить: