Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You (the programmer) were contacted by one of the online car retail stores with

ID: 3663934 • Letter: Y

Question

You (the programmer) were contacted by one of the online car retail stores with a request to create a car inventory management system. Unfortunately, the app will be running on a propriety mobile hardware, so the conventional database systems as a back end is out. Instead you are asked to create an object oriented inventory system for a very large inventory of vehicles. The presentation layer (that you are not responsible for implementing) will be a browser that the customer and managers use to search for different types of vehicles by make, by engine type, and by carrying capacity. In addition to these search features, your app will have to support deletion and addition of vehicle inventory. The initial data load will be from a tab delimited text file – this is the only section of the code that you are allowed to use tokenizer to parse individual lines of text to create objects.

Methodology:

Each vehicle will be an object of Vehicle type with the following slots: int::id, string::make, string::model, char::engineType (D:diesel, G:gas, H:hybrid,E:electric), int::carryingCapacity, 0-5::customerRating. To keep track of the vehicles and support the search functionality of your application, you need to create 4 linked lists. The first one will keep track of all vehicles (allVehicles) and will be search-able by id, the reminder 3 lists will be skip-lists where objects will be inserted in order and search-able byMake, byEngineType, byCarryingCapacity (in 100 lbs increment steps – input example 735 means search for all engines 735-835lbs). The add function will contain 5 values for each object, and the delete command will be followed by an id of an object to be deleted. The final command is t for terminate the application.

Design note: You might consider each vehicle object to have an internal linked list to the SkipListNode objects for the ease of implementing the deletefunction. The problem is if you delete a vehicle object, first locate the vehicle using the allVehicles LList, but if you delete the object, it is still being pointed to by the other SkipListNodes. One option, is to search all other link lists to delete the individual SkipListNodes in byMake, byEngineType, byCarryingCapacityOR have a doubly linked lists in each vehicle object that point to the individual SkipListNodes to be deleted.

Commands to the API:

byMake string

byEngineType (D|G|H|E)

byCarryingCapacity int

add int::id string::make string::model char::engineType int::carryingCapacity 0-5::customerRating

delete int

Example:

example.txt

1 ford escort G 750 2

2 ford mustang G 920 4

3 ford scorpion G 710 3

4 subaru outback G 950 5

5 subaru impreza D 875 4

6 subaru forrester G 980 3

7 ford T G 510 5

8 ford F-150 D 1250 4

9 ford F-350 D 1500 3

10 ford F-150 G 1050 2

11 ford F-350 G 1200 4

12 ford F-150 H 950 5

13 ford F-350 H 1100 4

>> byMake subaru

<<4 subaru outback G 950 5

<<5 subaru impreza G 875 4

<<6 subaru forrester G 980 3

>> byEngineType D

<<8 ford F-150 D 1250 4

<<9 ford F-350 D 1500 3

<<5 subaru impreza D 875 4

>> byCarryingCapacity 910

<<2 ford mustang G 920 4

<<4 subaru outback G 950 5

<<6 subaru forrester G 980 3

<<13 ford F-350 H 1100 4

>>delete 10

<<deleted: 10 ford F-150 G 1050 2

>> delete: 12

<< not found id 12

>> add 16 subaru baha h 972 2

<< added 16 subaru baha h 972 2

>> add 9 ford F-350 D 1500 3

<< could not add: duplicate id

Design:

Implement the following functionality of the UJS:

Implementation in C++

You cannot use built-in libraries, only tokenizer for parsing in the input

Read-in unlimited number of vehicles (NO ARRAYS)

Implement all necessary setter, getter, and manipulation methods

Allocate all data-structures on the heap (not the stack)

Graceful termination: deallocate all allocated memory before exiting the application

Memory management in C++ is a must!

Explanation / Answer

#include<stdio.h>

#include<process.h>

#include<conio.h>

#include<dos.h>

#include<fstream.h>

extern float vattax=0 ;

class head

{

   char Iname[50][50];

   char cname[50];

   protected:

       int totalitems;

       float Qty[3];

       float price[3];

       int vatprice[3];

       void input(void);

       void output(void);

};

class vat:public head

{

   float vats;

   public:

       void vatcal(void);

       void outputs(void);

};

// input customer name and item details

void head::input(void)

{

   cout<<“Enter Customer Name : “;

   cin>>cname;

   cout<<“How many items ” << cname << ” purchased?”;

   cin>>totalitems;

   for(int i=0; i<totalitems; i++)

   {

       cout<<“ Enter Item Name “<<i+1<<“: “;

       gets(Iname[i]);

       cout<<” Cost : “<<i+1<<“: Rs. “;

       cin>>price[i];

       cout<<” Quantity: “;

       cin>>Qty[i];

       price[i]=Qty[i]*price[i];

   }

}

void head::output(void)

{

   int a;

   ifstream infile(“COUNT.TXT”);

   infile>>a;

   ofstream outfile(“COUNT.TXT”);

   a+=1;

   outfile<<a;

   outfile.close();

   struct date d;

   getdate(&d);

   printf(“Date: %d”, d.da_day);

   printf(“/%d”, d.da_mon);

   printf(“/%d ”, d.da_year);

   struct time t;

   gettime(&t);

   printf(“Time: %2d:%02d:%02d Bill No: %d ”,t.ti_hour, t.ti_min, t.ti_sec, a);

   int day, mon, year, hour, min, sec;

   day=d.da_day;mon=d.da_mon;year=d.da_year;

   hour=t.ti_hour;min=t.ti_min;sec=t.ti_sec;

   char *mer[4];

   if(hour>12)

   {

       hour=hour-12;

       *mer=”P.M.”;

   }

   else

   {

       *mer=”A.M.”;

   }

   {ofstream outfile(“HIS.TXT”, ios::app);

   outfile<<endl<<“Bill No.: “<<a<<“ On day: “<<day<<“/”<<mon<<“/”<<year<<“ & time: “<<hour<<“:”<<min<<“:”<<sec<<” “<<*mer<<endl;

   outfile<<“————————————————————————“<<endl;

   cout<<“Name of item Quantity Price ”;

   for(int i=0;i<totalitems;i++)

   {

       outfile<<“Name: “<<Iname[i]<<” Qty: “<<Qty[i]<<” Price: “<<price[i]<<endl;

       cout<<Iname[i]<<“ ”<<Qty[i]<<“ ”<<price[i]<<‘ ’;

   }

   outfile<<“————————————————————————“<<endl;

   outfile.close();

   }

}

void vat::vatcal(void)

{

   input();

   for(int i=0;i<totalitems;i++)

   {

       vatprice[i]=price[i]+(0.1*price[i]);

       vattax = vattax + (0.1*price[i]);

   }

}

void vat::outputs(void)

{

   output();

   float cash=0,sum=0,qty=0;

   for(int i=0;i<totalitems;i++)

   {

       sum+=vatprice[i];

       qty+=Qty[i];

           //   vattax += vatprice[i];

   }

   cout<<“Total:————————————————————————“;

   cout<<“ Tax :                  Rupees :” <<vattax;

   cout<<“ Quantity= “<<qty<<“ Rupees= “<<sum;

   cout<<“ ******************************************************************************”;

   pay:

   cout<<“ Transaction Details ”;

   cout<<” Total cash given: Rupees : “;

   cin>>cash;

   if(cash>=sum)

       cout<<“Total cash repaid: Rupees : “<<cash-sum<<‘ ’;

   else

   {   cout<<“Cash given is less than total amount!!!”;

       getch();

       goto pay;

   }

}

void main()

{

   vat obj;

   char opt, ch;

   start:

   clrscr();

   cout<<“**************************** ******** Sales Inventory ************* ******************************************** Please Enter Number 1 to enter new sales Record or enter 2 to view sales records…”;

   cout<<“ 1.Add New sales Record 2. To view previous entries 3. Exit ”;

   cout<<“Enter your option: “;

   cin>>opt;

   switch(opt)

   {

       // purchase item

       case’1:clrscr();

           obj.vatcal();

           cout<<“Items Entered Successfully… Press any key to continue……..”;

           getch();

           clrscr();

           obj.outputs();

           getch();

           goto start;

           //view item details

       case’2:clrscr();

           ifstream fin;

           fin.open(“HIS.TXT”, ios::in);

           while(fin.get(ch))

           {

               cout<<ch;

           }

       fin.close();

           getch();

           goto start;

           // close application

       case’3:cout<<“ Thanks for using Sales Inventory “;

           delay(1000);

           exit(0);

   }

   getch();

}