#include using namespace std; struct item { int id; float price; } s[50]; int size = 0; void addData() { cout > s[size].id; cout > s[size].price; cout s[j].price) { struct item t = s[i]; s[i] =...


#include
using namespace std;
struct item
{
    int id;
    float price;
} s[50];
int size = 0;
void addData() {
    cout < "enter="" an="" item="" data="" "=""><>
    cout < "enter="" id:="">
    cin >> s[size].id;
    cout < "enter="" price:="">
    cin >> s[size].price;
    cout < "successfully="" added"="">< endl=""><>
    size++;
    for (int i = 0; i < size;="">
    {
        for (int j = i + 1; j < size;="">
        {
            if (s[i].price > s[j].price)
            {
                struct item t = s[i];
                s[i] = s[j];
                s[j] = t;
            }
        }
    }
}
void retrivePrice() {
    int id;
    cout < "enter="" the="" element="">
    cin >> id;
    cout <>
    int i;
    for (i = 0; i < size;="">
    {
        if (id == s[i].id) {
            cout < "price="" for="" this="" item:="" "="">< s[i].price="">< endl=""><>
            break;
        }
    }
    if (i == size) cout < "item="" not="" found"="">< endl=""><>
}
void displayItems() {
    float range;
    cout < "enter="" the="">
    cin >> range;
    cout <>
    for (int i = 0; i < size;="">
    {
        if (range >= s[i].price) {
            cout < "id:="" "="">< s[i].id="">< "="" price="" :="" "="">< s[i].price="">< endl=""><>
        }
    }
}
void deleteItem() {
    int id;
    cout < "enter="" the="" element="">
    cin >> id;
    cout <>
    int index = -1;
    for (int i = 0; i < size;="">
    {
        if (id == s[i].id) {
            index = i;
            cout < "item="" deleted"="">< endl=""><>
            break;
        }
    }
    if (index == -1)
        cout < "item="" not="" found"="">< endl=""><>
    else
    {
        for (int i = index; i < size="" -="" 1;="" i++)="">
            s[i] = s[i + 1];
        }
    }
    size--;
}
void displayAll() {
    if (size == 0)
        cout < "no="" items="" founded..."="">< endl=""><>
    if (size > 0)
    {
        cout < "the="" items="" founded="" are:"="">< endl=""><>
        for (int i = 0; i < size;="">
        {
            cout < "id=" << s[i].id << ">
            cout < "price=" << s[i].price << endl << endl;
        }
    }
}
void deleteAll() {
    if (size == 0)
        cout << " no="" items="" founded="" "="">< endl=""><>
    else
    {
        cout < "all="" items="" deleted="" successfully"="">< endl=""><>
        size = 0;
    }
}
int main()
{
    while (true) {
        int x;
        cout < "enter="" 1="" for="" enter="" item="" id="" and="" price"=""><>
        cout < "enter="" 2="" for="" retrieve="" price="" for="" a="" specific="" item"=""><>
        cout < "enter="" 3="" for="" display="" all="" items="" in="" specific="" range="" of="" prices"=""><>
        cout < "enter="" 4="" for="" delete="" an="" item"=""><>
        cout < "enter="" 5="" for="" display="" all="" items"=""><>
        cout < "enter="" 6="" for="" delete="" all="" items"=""><>
        cout < "enter="" 0="" for="" exit"="">< endl=""><>
        cin >> x;
        cout <>
        switch (x) {
        case 1: addData();
            break;
        case 2: retrivePrice();
            break;
        case 3: displayItems();
            break;
        case 4: deleteItem();
            break;
        case 5:displayAll();
            break;
        case 6:deleteAll();
            break;
        default:exit(1);
            break;
        }
    }
    return 0;
} this code does mot run on visual studio what is the soloution ?

Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here