Quiz 100% Result

  • Re: CS201 Assignment 3 Solution and Discussion

    Assignment No.  3
    

    Semester: Fall 2020
    CS201 – Introduction to Programming Total Marks: 20
    Due Date:
    29-01-2021

    Instructions
    Please read the following instructions carefully before submitting assignment:
    It should be clear that your assignment will not get any credit if:

    o Assignment is submitted after due date.
    o Submitted assignment does not open or file is corrupt.
    o Assignment is copied (From internet/students).
    o Assignment is not in .cpp format.

    Software allowed to develop Assignment

    • Dev C++

    Objectives:
    In this assignment, the students will learn:
    • Use of class in programming
    • How to deal with a file in programming
    • How to implement switch statement for Class based functions.

    ABC bakery is using a console based inventory management system for the receipt generation purposes. Console application will help the cashier in calculating total price of each item with respect to its price. Menu list will provide Add an item option to take data about an inventory item, include Item Id, Item name, price and quantity. Relevant data of all items will be displayed on screen with the help of menu option. Quantity amount of items will changeable if user wants to add quantity of an item.

    Problem Statement
    Write a C++ program to manage the inventory item using your knowledge about file handling and classes. User will manage details of an Inventory item using menu list that will provide three options:

    ENTER CHOICE

    1. ADD AN INVENTORY ITEM
    2. DISPLAY FILE DATA
    3. INCREASE QUANTITY

    Prompt will show to the user for continue the program after dealing with each option, until user will press a key other than ‘y’.

    Instructions to write C++ program:

    You will use class “Inventory” to declare inventory data and info
    Make “Inventory.txt” file to save inventory item record
    “Inventory.txt” file will delete each time when the program will run
    “ERROE IN OPENING FILE” will be shown if user not press ‘1’ when program will execute first time.
    You will use switch statement to handle different conditions and to perform different actions based on the different actions, that is, choice 1, 2, and 3.

    Code structure [ Demonstration]:
    You will be using the following class and other functions to develop the assignment:

    class Inventory
    {
          private:
                  int itemID;
                  char itemName[20];
                  float itemPrice;
                  float quantity;
                  float totalPrice;
    
          public:
                 void readItem();
                 void displayItem();
                 int getItemID() ;
                 float getPrice() ;
                 float getQuantity() ;
                void updateQuantity(float q);    
    };
    
    //Deleting existing file
    void deleteExistingFile(){--------}
    
    //Appending item in file
    void appendToFille(){------------}
    
    //Displaying items
    void displayAll(){------------}
    
    //Increasing Quantity of item
    void increaseQuanity(){------------}
    

    Program Output:

    1. User’s prompt when program will execute for the first time.
      6bcfa578-bdbb-4d1a-afd3-1f50ec8dd32b-image.png

    2. When user press ‘1’ , It will take data about an inventory item as an input from the user.
      02679a3e-f114-43f3-b38a-0f9596a53d86-image.png

    3. When user press ‘2’, it will read data from “Inventory.txt” file and display record of all inventory items on the screen
      fc208996-9a2a-44fa-ad1e-c4734f3368ab-image.png

    4. If user press ‘3’, it will ask to enter Item id against which user want to increase item quantity.
      799bf532-032e-4891-bac8-795fefea34b5-image.png

    5. Now, when the user will press ‘2’, the inventory item record will be shown as:
      559a0b14-878a-400f-a916-a2ce8fd4e3fc-image.png

    Assignment#3 covers course contents from lecture 17 to 30.

    Best of Luck!

  • Cyberian's Gold

    @zaasmi said in CS201 Assignment 3 Solution and Discussion:

    Re: CS201 Assignment 3 Solution and Discussion

    Assignment No. 3
    Semester: Fall 2020
    CS201 – Introduction to Programming Total Marks: 20
    Due Date:
    29-01-2021

    Instructions
    Please read the following instructions carefully before submitting assignment:
    It should be clear that your assignment will not get any credit if:

    o Assignment is submitted after due date.
    o Submitted assignment does not open or file is corrupt.
    o Assignment is copied (From internet/students).
    o Assignment is not in .cpp format.

    Software allowed to develop Assignment

    • Dev C++

    Objectives:
    In this assignment, the students will learn:
    • Use of class in programming
    • How to deal with a file in programming
    • How to implement switch statement for Class based functions.

    ABC bakery is using a console based inventory management system for the receipt generation purposes. Console application will help the cashier in calculating total price of each item with respect to its price. Menu list will provide Add an item option to take data about an inventory item, include Item Id, Item name, price and quantity. Relevant data of all items will be displayed on screen with the help of menu option. Quantity amount of items will changeable if user wants to add quantity of an item.

    Problem Statement
    Write a C++ program to manage the inventory item using your knowledge about file handling and classes. User will manage details of an Inventory item using menu list that will provide three options:

    ENTER CHOICE

    1. ADD AN INVENTORY ITEM
    2. DISPLAY FILE DATA
    3. INCREASE QUANTITY

    Prompt will show to the user for continue the program after dealing with each option, until user will press a key other than ‘y’.

    Instructions to write C++ program:

    You will use class “Inventory” to declare inventory data and info
    Make “Inventory.txt” file to save inventory item record
    “Inventory.txt” file will delete each time when the program will run
    “ERROE IN OPENING FILE” will be shown if user not press ‘1’ when program will execute first time.
    You will use switch statement to handle different conditions and to perform different actions based on the different actions, that is, choice 1, 2, and 3.

    Code structure [ Demonstration]:
    You will be using the following class and other functions to develop the assignment:

    class Inventory
    {
          private:
                  int itemID;
                  char itemName[20];
                  float itemPrice;
                  float quantity;
                  float totalPrice;
    
          public:
                 void readItem();
                 void displayItem();
                 int getItemID() ;
                 float getPrice() ;
                 float getQuantity() ;
                void updateQuantity(float q);    
    };
    
    //Deleting existing file
    void deleteExistingFile(){--------}
    
    //Appending item in file
    void appendToFille(){------------}
    
    //Displaying items
    void displayAll(){------------}
    
    //Increasing Quantity of item
    void increaseQuanity(){------------}
    

    Program Output:

    1. User’s prompt when program will execute for the first time.
      6bcfa578-bdbb-4d1a-afd3-1f50ec8dd32b-image.png

    2. When user press ‘1’ , It will take data about an inventory item as an input from the user.
      02679a3e-f114-43f3-b38a-0f9596a53d86-image.png

    3. When user press ‘2’, it will read data from “Inventory.txt” file and display record of all inventory items on the screen
      fc208996-9a2a-44fa-ad1e-c4734f3368ab-image.png

    4. If user press ‘3’, it will ask to enter Item id against which user want to increase item quantity.
      799bf532-032e-4891-bac8-795fefea34b5-image.png

    5. Now, when the user will press ‘2’, the inventory item record will be shown as:
      559a0b14-878a-400f-a916-a2ce8fd4e3fc-image.png

    Assignment#3 covers course contents from lecture 17 to 30.

    Best of Luck!

    #include<iostream>
    #include<fstream>
    #include<stdio.h>
     
    using namespace std;
    
    class Inventory
    {
          private:
                  int itemID;
                  char itemName[20];
                  float itemPrice;
                  float quantity;
                  float totalPrice;
          public:
                 void readItem();
                 void displayItem();
                 int getItemID()   { return itemID;}
                 float getPrice()    { return itemPrice;}
                 float getQuantity()    { return quantity;}
                 void updateQuantity(float q)    
                 { 
                      quantity=q;
                      totalPrice = (itemPrice*quantity);
                 }
    };
    
    //    Getting Item 
    void Inventory::readItem(){
        cout << "Please enter item id: ";
        cin >> itemID;
        cout << "Please enter item name: ";
        cin.ignore(1);
        cin.getline(itemName,20);
        cout << "Please enter price: ";
        cin >> itemPrice;
        cout << "Please enter quantity: ";
        cin >> quantity;
        totalPrice = (itemPrice*quantity);
    }
    
    //  Displaying Item
    void Inventory::displayItem()
    {
        cout << "Item id:" << itemID << "\tItem name:" << itemName << "\t ItemPrice:" << itemPrice << "\t Quantity:" << quantity << "\t TotalPrice:" << totalPrice << endl;
    }
    
    //  Deleting existing file
    void deleteExistingFile(){
        remove("Inventory.txt");
    }
    
    //  Appending item in file
    void appendToFille(){
         Inventory x;
         x.readItem();
      
         ofstream file;   
         file.open("Inventory.txt",ios::binary | ios::app);
    
        if(!file){
            cout << "ERROR WHILE CREATING A FILE!\n";
            return;
        }
        
        file.write((char*)&x,sizeof(x));
        file.close();
        cout<<"Inventory record(s) added sucessfully.\n";
    }
    
    //  Displaying items
    void displayAll(){
        Inventory x;
        ifstream file;
        file.open("Inventory.txt",ios::binary | ios::in);
    
        if(!file){
            cout<<"ERROR IN OPENING FILE \n";
            return;
        }
        while(file){
        if(file.read((char*)&x,sizeof(x)))
           x.displayItem();
        }
      file.close();
    }
    
    //  Increasing Quantity of item
    void increaseQuanity(){
        int itemValue;
        int isFound=0;
        int q;
        Inventory x;
     
        cout<<"Enter item id: \n";
        cin >> itemValue;
     
        ifstream fileRead;
        fileRead.open("Inventory.txt",ios::binary | ios::in);
        
        if(!fileRead){
            cout<<"ERROR IN OPENING FILE \n";
            return;
        }
        
        while(fileRead){    
            if(fileRead.read((char*)&x,sizeof(x))){
                if(x.getItemID() == itemValue){
                    cout << "Add quantity? ";
                    cin >> q;
                    x.updateQuantity(x.getQuantity() + q); 
                    isFound=1;
                    break;
                }
            }
        }
        
        if(isFound==0){
            cout<<"Record not found!!!\n";
        }
    
        fileRead.close();
    
        deleteExistingFile();
    
        ofstream fileWrite;
        fileWrite.open("Inventory.txt",ios::binary | ios::app);
        fileWrite.write((char*)&x,sizeof(x));
    
        fileWrite.close();
        cout << "Item Quantity updated successfully."<<endl;
    }
    
    int main()
    {
         char ch;
        
        
         do
         {
          char n;
          
     
          cout << "ENTER CHOICE\n" << "1. ADD AN INVENTORY ITEM\n" << "2. DISPLAY FILE DATA\n" << "3. INCREASE QUANTITY\n";
          cout << "Please select a choice: ";
        
          cin >> n;
    
          switch(n)
          {
              case '1':
                appendToFille();
                break;
              case '2' :
                displayAll();
                break;
              case '3':
              	increaseQuanity();
                break;
               default :
                    cout << "Invalid Choice\n";
                    break;
          }
       
      /*    else
          cout<<"Enter integer value only";
          }
     */
         cout << "Do you want to continue? : ";
         cin >> ch;
     
         }
         while(ch=='Y'||ch=='y');
         
        return 0;
        
        
    }
    
    

50% Off on Your FEE Join US!

Quiz 100% Result If you want to know how you can join us and get 50% Discout on your FEE ask Cyberian in Chat Room! Quiz 100% Result Quiz 100% Result
| |