Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Inventory Schildt*/
- #include "stdafx.h"
- #include <iostream>
- #include <cctype>
- #include <cstring>
- #include <cstdlib>
- #include <conio.h>
- using namespace std;
- const int SIZE = 2;
- struct int_type {
- char item[40];
- double cost;
- double retail;
- int on_hand;
- int lead_time;
- } invtry[SIZE];
- int status = 0;
- void enter(), init_list(), display();
- void update(), input(int i);
- int menu();
- int find_product();
- void delete_product(), remove_sklad();
- int testEmpty();
- int main() {
- char choice;
- init_list();
- choice = menu();
- for (;;) {
- switch (choice)
- {
- case 'e': enter();
- break;
- case 'd': display();
- break;
- case 'u': update();
- break;
- case 'f': find_product();
- break;
- case 'w': delete_product();
- break;
- case 'r': remove_sklad();
- break;
- case 'q': return 0;
- }
- if (status == -1) {
- cout << "Choise a new comand: " << endl;
- choice = menu();
- }
- }
- return 0;
- }
- void init_list() {
- for (int i = 0; i < SIZE; i++) {
- *invtry[i].item = '\0';
- }
- }
- int menu() {
- char ch;
- do {
- cout << "(E)nter" << endl;
- cout << "(D)isplay" << endl;
- cout << "(U)pdate" << endl;
- cout << "(F)ind product" << endl;
- cout << "(W)ithdrawal product" << endl;
- cout << "(R)emove inventory" << endl;
- cout << "(Q)uit" << endl << endl;
- if(status != -1) cout << "Choise a comand: ";
- cin >> ch;
- } while (!strchr("eduqfwr", tolower(ch)));
- return tolower(ch);
- }
- void enter() {
- int i;
- for (i = 0; i < SIZE; i++) {
- if (!*invtry[i].item) break;
- }
- if (i == SIZE) {
- cout << "List is full" << endl << endl;
- status = -1;
- return;
- }
- input(i);
- }
- void input(int i) {
- cout << "Name: ";
- cin >> invtry[i].item;
- cout << "Cost: ";
- cin >> invtry[i].cost;
- cout << "Retail cost: ";
- cin >> invtry[i].retail;
- cout << "On hand: ";
- cin >> invtry[i].on_hand;
- cout << "Time: ";
- cin >> invtry[i].lead_time;
- cout << endl;
- }
- void update() {
- int i;
- i = find_product();
- if (i != -1) {
- cout << "Enter new information's." << endl;
- input(i);
- }
- }
- void display() {
- if (testEmpty() == 1) {
- for (int i = 0; i < SIZE; i++) {
- if (*invtry[i].item) {
- cout << invtry[i].item << endl;
- cout << "Cost: " << invtry[i].cost << endl;
- cout << "Retail cost: " << invtry[i].retail << endl;
- cout << "On hand: " << invtry[i].on_hand << endl;
- cout << "Time: " << invtry[i].lead_time << endl << endl;
- }
- }
- }
- else {
- cout << "Inventory is empty." << endl << endl;
- }
- }
- int find_product() {
- int i;
- char name[40];
- cout << "Enter name of product: ";
- cin >> name;
- for (i = 0; i < SIZE; i++) {
- if (!strcmp(name, invtry[i].item)) break;
- }
- if (i == SIZE) {
- cout << "Product is not found" << endl << endl;
- return -1;
- }
- else {
- cout << "Product is found. His index: " << i << endl << endl;
- return i;
- }
- }
- void delete_product() {
- int index;
- cout << "Deliting product. ";
- index = find_product();
- if (index != -1) {
- *invtry[index].item = '\0';
- }
- }
- void remove_sklad() {
- for (int i = 0; i < SIZE; i++) {
- *invtry[i].item = '\0';
- }
- }
- int testEmpty() {
- int i;
- for (i = 0; i < SIZE; i++) {
- if (*invtry[i].item) break;
- }
- if (i == SIZE) {
- status = -1;
- return -1;
- }
- else return 1;
- }
Add Comment
Please, Sign In to add comment