Question

In: Computer Science

We want to develop a sales system for a mobile shop. The system should keep information...

We want to develop a sales system for a mobile shop. The system should keep information about the mobile phones available at the shop. the system should allow the user the ADD new mobile phones, one at a time, along with their features. The system should also allow to search mobile phones , update their information, and delete them (one by one). Try to provide different criteria for search. When the system starts, it should load the information about the mobile phones forma file. if the file doesn't exist, the system should create the file. The system should provide a (console based) menu to interact with it. The system not use any arrays and all the changes should be reflected in the file.

Language: C++

Solutions

Expert Solution

The structure of mobile data which is have taken is:

Model No , Brand, Price, launching year, RAM, camera, Internal Storage

These all are seperated by commas in the file. Each line of the file contains info about a mobile.

I have implemented search for model no. only, but you can expand it to as many features as you want.

The program is:

#include<iostream>
#include<fstream>
#include<string.h>
#include<sstream>
using namespace std;



int main(){

    //filename of file to be manipulated
    string filename = "data.txt";

    //Loading the data_file
    fstream f;

    //It wil create file if it does not exits and will open it if it exists
    f.open(filename, std::fstream::in | std::fstream::out | std::fstream:: app );


    //Menu for the User
    cout<<"\n";
    cout<<"\t-----------------Welcome to the XYZ mobile shop----------------\n";

    //option for choosing
    int op; 

    //variables required for query
    string temp, temp1, data, model_no, brand, price, launch_yr, ram, camera, istorage;
    int flag, k;

    //while loop to take continuous inputs from user
    while(1){
        cout<<"\n\nChoose one of the following query to perfomr:\n\n";
        cout<<"1) Add a new mobile phone to record\n";
        cout<<"2) Search for mobile phones\n";
        cout<<"3) Update specs of a mobile phone\n";
        cout<<"4) Delete a mobile phone from record\n";
        cout<<"5) Exit the system\n";
        cin>>op;

        //choosing what to do on the basis of user's choice
        switch(op){

            //Add new mobile to record
            case 1:
                cout<<"Enter the following details about the phone:"<<endl;
                cout<<"Enter the model no. of mobile phone\n";
                cin>>model_no;
                cout<<"Enter the brand of mobile phone\n";
                cin>>brand;
                cout<<"Enter the year when mobile phone was launched\n";
                cin>>launch_yr;
                cout<<"Enter the price of mobile phone\n";
                cin>>price;
                cout<<"Enter the RAM of mobile phone\n";
                cin>>ram;
                cout<<"Enter the camera strength(MP) of mobile phone\n";
                cin>>camera;
                cout<<"Enter the internal storage of mobile phone\n";
                cin>>istorage;
                cout<<"saving info of the new mobile phone............."<<endl;

                data = model_no + "," + brand + "," + price + "," + launch_yr + "," + ram + "," + camera + "," + istorage + "\n";
                f << data;
                f.flush();
                cout<<"Info saved successfuly.........."<<endl;
                break;
            
            //Update record of a mobile phone
            case 3:
                cout<<"Enter the Model No of the mobile phone to Update:\n";
                cin>>model_no;
                flag = 0;
                data = "";
                f.seekg(0);
                while(getline(f, temp)){
                    stringstream check1(temp);
                    // Tokenizing w.r.t. space ' '
                    while(getline(check1, temp1, ','))
                    {   
                        if(temp1 == model_no){
                            flag = 1;
                        }
                        else data += temp + "\n";
                        break;
                    }
                }
                if(flag == 0) cout<<"The model_no is not found in record\n";
                else{
                    cout<<"Enter the brand of mobile phone\n";
                    cin>>brand;
                    cout<<"Enter the year when mobile phone was launched\n";
                    cin>>launch_yr;
                    cout<<"Enter the price of mobile phone\n";
                    cin>>price;
                    cout<<"Enter the RAM of mobile phone\n";
                    cin>>ram;
                    cout<<"Enter the camera strength(MP) of mobile phone\n";
                    cin>>camera;
                    cout<<"Enter the internal storage of mobile phone\n";
                    cin>>istorage;
                    cout<<"updating info of the new mobile phone............."<<endl;

                    data = model_no + "," + brand + "," + price + "," + launch_yr + "," + ram + "," + camera + "," + istorage + "\n";
                    f.close();
                    f.open("dt.txt", std::fstream::in | std::fstream::out | std::fstream:: app);
                    remove("data.txt");
                    rename("dt.txt", "data.txt");
                    f << data;
                    f.flush();
                    cout<<"Info updated successfuly.........."<<endl;
                }
                break;

            //Delete record of a mobile phone
            case 4:
                cout<<"Enter the Model No of the mobile phone to delete:\n";
                cin>>model_no;
                flag = 0;
                data = "";
                f.seekg(0);
                while(getline(f, temp)){
                    stringstream check1(temp);
                    // Tokenizing w.r.t. space ' '
                    while(getline(check1, temp1, ','))
                    {
                        if(temp1 == model_no){
                            flag = 1;
                            cout<<"Deletion sucessfull\n";
                        }
                        else data += temp + "\n";
                        break;
                    }
                }
                if(flag == 0) cout<<"The model_no is not found in record\n";
                if(flag == 1) {
                    f.close();
                    f.open("dt.txt", std::fstream::in | std::fstream::out | std::fstream:: app);
                    remove("data.txt");
                    rename("dt.txt", "data.txt");
                    f << data;
                    f.flush();
                }
                break;

            //Search a mobile no. on the basis of model no.
            case 2:
                cout<<"Enter the model no. to search\n";
                cin>>model_no;
                flag = 0;
                k = 0;
                data = "";
                f.seekg(0);
                while(getline(f, temp)){
                    k = 0;
                    stringstream check1(temp);
                    // Tokenizing w.r.t. space ' '
                    while(getline(check1, temp1, ','))
                    {
                        if(temp1 == model_no || k == 1){
                            flag = 1;
                            k = 1;
                            cout<<temp1<<"\t";
                        }
                    }
                    cout<<endl;
                }
                if(flag == 0) cout<<"The model_no is not found in record\n";
                break;

            //exit the system
            case 5:
                cout<<"Have a good day!"<<endl;
                f.close();
                exit(0);

        }
    }
    return 0;
}

Output:


Related Solutions

We want to design and develop a text statistical analyzer. This analyzer should consider an input...
We want to design and develop a text statistical analyzer. This analyzer should consider an input text as a finite sequence of characters, including letters (‘a’, .., ‘z’, ‘A’, ..., ‘Z’), digits (0,…, 9), special characters (space and new line), and punctuation characters (‘.’, ‘,’, ‘;’). The input text must end with ‘#’. A word is defined as a sequence of alphanumeric characters (letters and numbers, 0 to 9) delimited by two separators. A separator is any non-alphanumeric character. Use...
Benis firm has hired you to develop a database to keep information about its sales offices....
Benis firm has hired you to develop a database to keep information about its sales offices. It has a number of sales offices in several towns. We need to store unique office number and location for each sales office. Each sales office is assigned to one or more employees. You need to store the following information for each employee; unique employee id, employee name, salary and phone number(s). An employee must be assigned to only one sales office. For each...
Using c++ Design a system to keep track of employee data. The system should keep track...
Using c++ Design a system to keep track of employee data. The system should keep track of an employee’s name, ID number and hourly pay rate in a class called Employee. You may also store any additional data you may need, (hint: you need something extra). This data is stored in a file (user selectable) with the id number, hourly pay rate, and the employee’s full name (example): 17 5.25 Daniel Katz 18 6.75 John F. Jones Start your main...
Scenario: An auto shop is designing a database to keep track of repairs. So far, we...
Scenario: An auto shop is designing a database to keep track of repairs. So far, we have this UNF relation, with some sample data shown. Normalize to 1NF. REPAIRS: # VIN, Make, Model, Year, ( Mileage, Date, Problem, Technician, Cost ) VIN Make Model Year Mileage Date Problem Technician Cost 15386355 Ford Taurus 2000 128242 6/6/2014 Won’t start Gary $300 15386355 Ford Taurus 2000 129680 6/20/2014 Tail light out Trisha 43532934 Honda Civic 2010 38002 6/18/2014 Brakes slow Gary $240...
Develop a set of test cases for the algorithm In a scheduling program, we want to...
Develop a set of test cases for the algorithm In a scheduling program, we want to check whether two appointments overlap. For simplicity, appointments start at a full hour, and we use military time (with hours 0–24). The following pseudocode describes an algorithm that determines whether the appointment with start time start1 and end time end1 overlaps with the appointment with start time start2 and end time end2. If start1 > start2 s = start1 Else s = start2 If...
Should we keep the electoral college or go to straight popular vote? Why?
Should we keep the electoral college or go to straight popular vote? Why?
Consider the following set of requirements for a university information system that is used to keep...
Consider the following set of requirements for a university information system that is used to keep track of students’ transcripts. R1: The university keeps track of each student's name, student number, class, and degree program. R2. The university consists of various departments. Each department is described by a name, department code and phone. R3. Each course has a course number, course name, and credits. R4. Each section has an instructor, course number, and section number. There might be multiple sections...
We stay healthy because our bodies keep everything in balance. Which system, that we studied this...
We stay healthy because our bodies keep everything in balance. Which system, that we studied this semester, do you think is the most important in maintaining homeostasis? In your discussion be sure to include the main function of the system, cells and tissues that are involved, and how it maintains homeostasis. You can also include how it helps regulate other systems if you think that is important
We stay healthy because our bodies keep everything in balance. Which system that we studied this...
We stay healthy because our bodies keep everything in balance. Which system that we studied this semester, do you think is the most important in maintaining homeostasis? In your discussion be sure to include the main function of the system, cells and tissues that are involved, and how it maintains homeostasis. You can also include how it helps regulate other systems if you think that is important. To answer this question you can draw a diagram, but please be sure...
1. How do you keep Compensation fair? 2. How do you keep employees motivated? Should we...
1. How do you keep Compensation fair? 2. How do you keep employees motivated? Should we increase salaries when an employee complains? 3. How should managers handle a no raise? 4. What role does the government play in maintaining equity and fairness?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT