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

Chrome File Edit View History Bookmarks People Window Help x Quests-201830 Summe

ID: 3908443 • Letter: C

Question

Chrome File Edit View History Bookmarks People Window Help x Quests-201830 Summer 1: D x , e 1. You will Pick 10 Stocks Fron CSecure https:/www.chegg.com/homework-help/questions-and-answers/1-pick-10-stocks-list Chegg Study TEXTBOOK SOLUTIONS EXPERT O&A; 1. You will pick 10 stocks from this list: https://finance.yahoo.com/quote/%5EDJI/components?p.965EDJI 2. create a program that takes the stock's symbol, company name, last price, change, and volume as input from a file. How the file is formatted and inputed is up to you and you can put underscores between words in the companies name instead of using spaces. Store these values in either -a 2 dimensional array or vector of strings (may require converting strings to floats using: stoffstringVariable,nullptr);) -5 individual arrays or vectors of their correct types -You may create a class or struct with the proper members for the data for each company, then create an array or vector of the class or struct type. 3. After input, it will isplay the information on the terminal. Users will have the option of sorting the information by any of the five categories of information. Depending on which sorted by, you will sort using a different sorting algorithm. category the data is being 4. The user will also be able to change the stock price the user should input the stock symbol. -The array will be searched using a binary search When this option is selected, if the symbol is found, all the information for that company will be displayed, else an error message will be displayed. The user will be able to enter a new price for the stock. This value will be updated in the array 5. When the user exits, all data will be written back to the file. The language for this program should be in C++ 23

Explanation / Answer

Implemented Source Code:-
-----------------------------------
#include<iostream>
#include<iomanip>
#include<string.h>
#include<stdlib.h>
#include<fstream>
using namespace std;
struct Inventary
{
int id;
char item_name[100];
int noof_pieces_ordered;
int NoofCurrently_store;
int pieces_sold;
double manufacturers;
double sellingprice;
struct Inventary *next;
};
struct Inventary *first=NULL,*last=NULL,*swapping ,*temp1=NULL,*head;
class Inventary_record
{
public:
void ReadFile()
{
ifstream myfile;
myfile.open("InventaryData.txt");
for(int i=1;i<=4;i++)
{
head=(struct Inventary*)malloc(sizeof(struct Inventary));
myfile>>head->id;
myfile>>head->item_name;
myfile>>head->noof_pieces_ordered;
myfile>>head->NoofCurrently_store;
myfile>>head->pieces_sold;
myfile>>head->manufacturers;
myfile>>head->sellingprice;
head->next=swapping;
swapping=head;
}
myfile.close();
reverse(&head);
}
public:
void Print_data()
{
struct Inventary *temp;
temp=head;
if(temp!=NULL)
{
cout<<" Item_Id Item_Name ordered current_pieces pieces_sold manufacturerPrice SellingPrice"<<endl;
cout<<"---------------------------------------------------"<<endl;
while(temp!=NULL)
{
cout<<temp->id<<" "<<temp->item_name<<" "<<temp->noof_pieces_ordered<<" "<<temp->NoofCurrently_store<<" "<<temp->pieces_sold<<" "<<temp->manufacturers<<" "<<temp->sellingprice<<endl;
temp=temp->next;
}
}
else
{
cout<<"The list is Empty: "<<endl;
}
}
public:
void reverse(struct Inventary** head)
{
struct Inventary* prev = NULL;
struct Inventary* current = *head;
struct Inventary* next = NULL;
while (current != NULL)
{
next=current->next;  
current->next = prev;
prev = current;
current = next;
}
*head = prev;
}
public:
void BuyItem(struct Inventary **head, int position)
{
if (*head == NULL)
return;
struct Inventary* temp = *head;
if (position == 0)
{
*head = temp->next;
free(temp);
return;
}
for(int i=0; temp!=NULL && i<position-1; i++)
temp = temp->next;
if(temp == NULL || temp->next == NULL)
return;
last = temp->next->next;
free(temp->next);
temp->next = last;
cout<<" The Item Buyed Successfully"<<endl;
}
public:
int search(char name[])
{
int index=0;
struct Inventary *temp=head;
while(temp!=NULL)
{
if(!(strcmp(name,temp->item_name)))
{
cout<<" Item Found:"<<endl;
cout<<temp->id<<" "<<temp->item_name<<" "<<temp->noof_pieces_ordered<<" "<<temp->NoofCurrently_store<<" "<<temp->pieces_sold<<" "<<temp->manufacturers<<" "<<temp->sellingprice<<endl;
return index;
}
temp=temp->next;
index++;   
}
return -1;
}
};
int main()
{
Inventary_record obj;
obj.ReadFile();
int option;
char itemName[100];
int retval;
cout<<" the content from the file is: "<<endl;
cout<<" -------------------------------"<<endl;
obj.Print_data();
while(true)
{
cout<<" **** MENU ****"<<endl;
cout<<" 1: To see if an item is in the store."<<endl;
cout<<" 2: To buy an item."<<endl;
cout<<" 3. To check the price of an item"<<endl;
cout<<" 4: To print the inventory (print the inventory report."<<endl;
cout<<" 9: To end the program."<<endl;
cout<<" Please select any Option: " <<endl;
cin>>option;
switch(option)
{
case 1 :
cout<<" Please Enter item Name"<<endl;
cin>>itemName;
retval=obj.search(itemName);
if(retval==-1)
cout<<" Sorry Item Details are Not Found"<<endl;
break;
case 2:
cout<<" Please Enter Name"<<endl;
cin>>itemName;
retval=obj.search(itemName);
if(retval==-1)
cout<<" Sorry Item Details are Not Found"<<endl;
else
obj.BuyItem(&head,retval);
break;
case 3:
cout<<" Please enter the Item Name:"<<endl;
cin>>itemName;
retval=obj.search(itemName);
if(retval==-1)
cout<<" Sorry Item Details are Not Found"<<endl;
break;
case 4:
obj.Print_data();
break;
case 9:
cout<<" End"<<endl;
exit(0);
default:
cout<<" Invalid Option"<<endl;
}
}
}


inputfile(InventaryData.txt): -   
-----------------------------------
1111 Basketball 100 100 20 10.00 30.00
2222 Frisbeebal 75 75 10 5.00 15.00
3333 Baseball 100 100 40 7.00 21.00
4444 Baseball 150 150 100 12.00 36.00

Sample output:-
--------------------
the content from the file is:
-------------------------------
Item_Id Item_Name ordered current_pieces pieces_sold manufacturerPrice SellingPrice
---------------------------------------------------
1111 Basketball 100 100 20 10 30
2222 Frisbeebal 75 75 10 5 15
3333 Baseball 100 100 40 7 21
4444 Baseball 150 150 100 12 36
**** MENU ****
1: To see if an item is in the store.
2: To buy an item.
3. To check the price of an item
4: To print the inventory (print the inventory report.
9: To end the program.
Please select any Option:
1
Please Enter item Name
Baseball
Item Found:
3333 Baseball 100 100 40 7 21
**** MENU ****
1: To see if an item is in the store.
2: To buy an item.
3. To check the price of an item
4: To print the inventory (print the inventory report.
9: To end the program.
Please select any Option:
3
Please enter the Item Name:
Baseball
Item Found:
3333 Baseball 100 100 40 7 21
**** MENU ****
1: To see if an item is in the store.
2: To buy an item.
3. To check the price of an item
4: To print the inventory (print the inventory report.
9: To end the program.
Please select any Option:
2
Please Enter Name
Baseball
Item Found:
3333 Baseball 100 100 40 7 21
The Item Buyed Successfully
**** MENU ****
1: To see if an item is in the store.
2: To buy an item.
3. To check the price of an item
4: To print the inventory (print the inventory report.
9: To end the program.
Please select any Option:
4
Item_Id Item_Name ordered current_pieces pieces_sold manufacturerPrice SellingPrice
---------------------------------------------------
1111 Basketball 100 100 20 10 30
2222 Frisbeebal 75 75 10 5 15
4444 Baseball 150 150 100 12 36
**** MENU ****
1: To see if an item is in the store.
2: To buy an item.
3. To check the price of an item
4: To print the inventory (print the inventory report.
9: To end the program.
Please select any Option:
9
End
--------------------------------
Process exited after 78.99 seconds with return value 0
Press any key to continue . . .  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote