Question

In: Computer Science

Language: c++ using visual basic Write a program to open a text file that you created,...

Language: c++

using visual basic

Write a program to open a text file that you created, read the file into arrays, sort the data by price (low to high), by box number (low to high), search for a price of a specific box number and create a reorder report. The reorder report should alert purchasing to order boxes whose inventory falls below 100. Sort the reorder report from high to low. Inventory data to input. Box number Number boxes in stock Price per box 202020 120 2.99 121202 50 .92 201620 340 1.03 242424 10 3.50 373737 200 9.00 723636 2 10.00 241206 100 2.10 363636 120 9.50 101010 1000 .10 101210 200 6.80 Requirements: 1. Save the data to a text file. Create the file in either Note Pad or other text editor. 2. In the program, read the data into arrays. 3. Use a menu driven program with the following choices: a. Display the data b. Sort the data by price, low to high c. Sort the data by box number, low to high d. Look up the price of a box given the box number (do a binary search) e. Reorder report. Report any item with number of boxes below 100. Sort the output from high to low. f. Exit the program 4. Each of the above options should be a function 5. Output must be labeled and easy to read 6. Appropriately pass parameters, declare local variables and use arrays. 7. Program must be documented with comments explaining what the code does

Solutions

Expert Solution

Answer:(In C++)

Code:

#include<iostream>
#include <fstream>
using namespace std;
#define size 10000

// Displays the current Inventory Data
void Display(int box_nums[],int nboxes[],double ppBox[],int n) // Prints Box number , number of boxes and price per box.
{
cout<<"Box number Number of boxes in stock Price per box"<<"\n";
cout<<"-------------------------------------------------------------\n";
for(int i=0; i<n; i++)
{
cout<<box_nums[i]<<" "<<nboxes[i]<<" "<<ppBox[i]<<"\n";
}
}

// sort's the inventory data according to the price per box from low to high
void sortByPrice(int box_nums[],int nboxes[],double priceBox[],int n)
{
int i, j, min_idx , temp2;
double temp;
for (i = 0; i < n-1; i++)
{
min_idx = i; // min_idx is used to store data in ascending order
for (j = i+1; j < n; j++) // used selection sort to sort the data based on price per box
{
if (priceBox[j] < priceBox[min_idx])
min_idx = j;
}
temp = priceBox[min_idx];
priceBox[min_idx] = priceBox[i]; // temp is a variable to swap data
priceBox[i] = temp;

temp2 = nboxes[min_idx];
nboxes[min_idx] = nboxes[i]; // temp2 is a variable to swap data
nboxes[i] = temp2;

temp2 = box_nums[min_idx];
box_nums[min_idx] = box_nums[i];
box_nums[i] = temp2;
  
}   
}

// sort's the inventory data according to Box number from low to high
void sortByBoxNumber(int box_nums[],int nboxes[],double priceBox[],int n)
{
int i, j, min_idx , temp2;
double temp;
for (i = 0; i < n-1; i++)
{
min_idx = i; // min_idx is used to store data in ascending order
for (j = i+1; j < n; j++)
{
if (box_nums[j] < box_nums[min_idx]) // used selection sort to sort the data based on price per box
min_idx = j;
}

temp2 = box_nums[min_idx];
box_nums[min_idx] = box_nums[i];
box_nums[i] = temp2;

temp = priceBox[min_idx];
priceBox[min_idx] = priceBox[i];
priceBox[i] = temp;

temp2 = nboxes[min_idx];
nboxes[min_idx] = nboxes[i];
nboxes[i] = temp2;
}   
}

// Searches for the price per box of the corresponding box number entered by user.
double lookUpByBoxNumber(int boxNumber,int box_nums[],double priceBox[],int n)
{
int low =0, high = n-1;
int mid;
while(low <= high) // used binary search to search for the corresponding box number and its price-per-box
{
mid = low + (high-low)/2;

if(box_nums[mid] > boxNumber)
{
high = mid - 1;
}
else if(box_nums[mid] == boxNumber)
{
return priceBox[mid];
}
else
{
low = mid + 1;
}
  
}
return -1;
}

//Reordered the data whose number of boxes are less than 100
void reorderReport(int box_nums[],int nboxes[],int n)
{
int reorderBoxNums[n],reorderBoxes[n],k=0;
for(int i=0; i<n; i++)
{
if(nboxes[i] < 100)
{
reorderBoxNums[k] = box_nums[i];
reorderBoxes[k] = nboxes[i];
k++;
}
}
int i, j, max_idx , temp2;
for (i = 0; i < k-1; i++) // sorts the data in reordered data according to number of boxes in inventory from low to high
{
max_idx = i;
for (j = i+1; j < k; j++)
{
if (reorderBoxes[j] > reorderBoxes[max_idx])
max_idx = j;
}

temp2 = reorderBoxes[max_idx];
reorderBoxes[max_idx] = reorderBoxes[i];
reorderBoxes[i] = temp2;

temp2 = reorderBoxNums[max_idx];
reorderBoxNums[max_idx] = reorderBoxNums[i];
reorderBoxNums[i] = temp2;
}
cout<<"REORDERED REPORT IS: \n";
cout<<"The boxes in invetory whose stock are less than 100 are: \n";
cout<<"Box number Number of boxes in stock"<<"\n";
cout<<"------------------------------------------"<<"\n";
for(int i=0 ; i<k; i++)
{
cout<<reorderBoxNums[i]<<" "<<reorderBoxes[i]<<"\n";
}
}
int main()
{

std::fstream myfile("inventory.txt");
int box_number[size] , numberOfBoxes[size] ;
double pricePerBox[size],sp;
int bn ,nb,i = 0;
while(myfile >> bn >> nb >> sp) // fetch data from file inventory.txt
{
box_number[i] = bn;
numberOfBoxes[i] = nb;
pricePerBox[i] = sp;
i++;
}

int n = i, bnumber ; // n stores number of records in file , bnumber is the box number which is to be searched for price-per-box by user
double val; // val is variable used for value stored from lookup by box-number
char option;
bool exit = true; // exit variable to exit the while loop

// Menu for the user
cout<<"\nChoose a option in the Menu a/b/c/d/e/f :"<<"\n";
cout<<"a. Display the data"<<"\n";
cout<<"b. Sort data by price, low to high"<<"\n";
cout<<"c. Sort data by box number, low to high"<<"\n";
cout<<"d. Look up the Price of the box given the box number"<<"\n";
cout<<"e. Generate Reorder Report"<<"\n";
cout<<"f. Exit"<<"\n";

while(exit)
{
cout<<"Enter your choice a/b/c/d/e/f : ";
cin>>option;

switch(option)
{
case 'a':
Display(box_number,numberOfBoxes,pricePerBox,n);
break;
case 'b':
sortByPrice(box_number,numberOfBoxes,pricePerBox,n);
cout<<"Data has been Successfully sorted by price"<<"\n";
cout<<"Please, choose option 'a' to display sorted data"<<"\n";
break;
case 'c':
sortByBoxNumber(box_number,numberOfBoxes,pricePerBox,n);
cout<<"Data has been Successfully sorted by Box Number"<<"\n";
cout<<"Please, choose option 'a' to display sorted data"<<"\n";
break;
case 'd':
sortByBoxNumber(box_number,numberOfBoxes,pricePerBox,n);
cout<<"Enter the box number for which you want to search the price : ";
cin>>bnumber;
val = lookUpByBoxNumber(bnumber,box_number,pricePerBox,n);
if(val < 0)
{
cout<<"There is no price of the box for the box number you are searching for\n";
}
else
{
cout<<"The price-per-box of the Box-Number you searched is "<<val<<"\n";
}
break;
case 'e':
reorderReport(box_number,numberOfBoxes,n);
break;
case 'f':
exit = false;
break;
default :   
cout<<"Invalid options , enter a valid option"<<"\n";
break;

}

}
return 0;
}

Output:

Note: If you have any further doubts or queries please comment I will get back to you.


Related Solutions

Language: c++ using visual basic Write a program to open a text file that you created,...
Language: c++ using visual basic Write a program to open a text file that you created, read the file into arrays, sort the data by price (low to high), by box number (low to high), search for a price of a specific box number and create a reorder report. The reorder report should alert purchasing to order boxes whose inventory falls below 100. Sort the reorder report from high to low. Inventory data to input. Box number Number boxes in...
Present a screenshot of the following Program to open up the created file in C++ language....
Present a screenshot of the following Program to open up the created file in C++ language. The list of random numbers will be below the instructions I have provided for you a file named Random.txt for use in this program. This file contains a long list of random numbers. You are to write a program that opens the file, reads all the numbers from the file and calculates the following: A. The number of numbers in the file B. The...
In C Programming Language Write a program to output to a text log file a new...
In C Programming Language Write a program to output to a text log file a new line starting with day time date followed by the message "SUCCESSFUL". Please screenshot the results.
Language: c++ works in visual basic Write a program that uses an array of nested structs...
Language: c++ works in visual basic Write a program that uses an array of nested structs to store the addresses for your store’s customers.  Each customer has a name and two addresses: home address and business address.  Each address has a street, city, state, and zip code. Requirements: 1. Data structure a. Define an Address struct with street, city, state and zip fields b. Define a Customer struct with lastNm and firstNm fields, plus homeAddr and busAddr fields...
Write a C program using system call I/O to a) open an existing text file passed...
Write a C program using system call I/O to a) open an existing text file passed to your program as a command line argument, then b) display the content of the file, c) ask the user what information he/she wants to append d) receive the info from the user via keyboard e) append the info received in d) to the end of the file f) display the updated content of the file
C++ Code You will write a program to process the lines in a text file using...
C++ Code You will write a program to process the lines in a text file using a linked list and shared pointers. You will create a class “Node” with the following private data attributes: • Line – line from a file (string) • Next (shared pointer to a Node) Put your class definition in a header file and the implementation of the methods in a .cpp file. The header file will be included in your project. If you follow the...
Using C++, write a code that this program always stores text file output into a text...
Using C++, write a code that this program always stores text file output into a text file named "clean.txt". -The program should read one character at a time from "someNumbers.txt", and do the following. -If it is a letter, print that letter to the screen, AND also store it in the text file. All letters should be converted to lowercase beforehand. -If it is a number, print that number to screen, but do NOT store it in the text file....
Write a C++ program to open and read a text file and count each unique token...
Write a C++ program to open and read a text file and count each unique token (word) by creating a new data type, struct, and by managing a vector of struct objects, passing the vector into and out of a function. Declare a struct TokenFreq that consists of two data members: (1) string value; and (2) int freq; Obviously, an object of this struct will be used to store a specific token and its frequency. For example, the following object...
Use Visual Basic Language In this assignment you will need to create a program that will...
Use Visual Basic Language In this assignment you will need to create a program that will have both a “for statement” and an “if statement”. Your program will read 2 numbers from the input screen and it will determine which is the larger of the 2 numbers. It will do this 10 times. It will also keep track of both the largest and smallest numbers throughout the entire 10 times through the loop. An example of the program would be...
Make a Program in Visual Studio / Console App (.NET Framework) # language Visual Basic You...
Make a Program in Visual Studio / Console App (.NET Framework) # language Visual Basic You will be simulating an ATM machine as much as possible Pretend you have an initial deposit of 1000.00. You will Prompt the user with a Main menu: Enter 1 to deposit Enter 2 to Withdraw Enter 3 to Print Balance Enter 4 to quit When the user enters 1 in the main menu, your program will prompt the user to enter the deposit amount....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT