Question

Language:C++ HAS TO WORK IN VISUAL BASIC I have errors on line 102 "expression must have...

Language:C++

HAS TO WORK IN VISUAL BASIC

I have errors on line 102 "expression must have a constant value

line 107,108,123,124,127,128: array type int[n] not assignable

#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;
}

Homework Answers

Answer #1

#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=new int[n];
int *reorderBoxes=new int[n];
int 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;
}

//////////////Just need to change the initialization of arrays as highlighted above///

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Do a theta analysis and count the number of computations it performed in each function/method of...
Do a theta analysis and count the number of computations it performed in each function/method of the following code: import java.io.*; import java.util.Scanner; class sort { int a[]; int n; long endTime ; long totalTime; long startTime; static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public sort(int nn) // Constructor { a = new int[nn]; n = nn; endTime= 0; totalTime =0; startTime =0; } public static void main(String args[]) throws IOException { System.out.print("\nEnter number of students: "); int nn =...
Below is the problem that I have and here is the code that I have in...
Below is the problem that I have and here is the code that I have in c++. Can someone help me on what I am doing wrong or the correct code. A teacher has asked all her students to line up according to their first name. For example, in one class Amy will be at the front of the line, and Yolanda will be at the end. Write a program that prompts the user to enter the number of students...
How to stop the program from exiting after display detail. When there is food detail, it...
How to stop the program from exiting after display detail. When there is food detail, it will display and exit the program. What can i do to make it not exit the program and back to main menu. #include <iostream> #include <iomanip> #include<string.h> using namespace std; struct food{ int order_id; string food_code,flavor,customer_id; string address,name; int weight,unit_price,qty,contact_number; struct food *next; };    class Foodsystem{ food *head,*temp,*temp2,*end; static int id;    public: Foodsystem(){ head=NULL;end=NULL;} void Place_Order(); void View_food_details(); void Modify_food_details(); void Delete_food_details();...
i want to complete this code to insert a new node in the middle of list...
i want to complete this code to insert a new node in the middle of list (take a node data from user, search the node and insert new node after this node). this is the code #include <iostream> #include <stdlib.h> using namespace std ; struct Node{                int data;                Node *link ;}; struct Node *head=NULL, *tail=NULL; /* pointers to Node*/ void InsertFront(); void InsertRear(); void DeleteFront(); void DeleteRear(); int main(){                int choice;                do{                               cout << "1:...
JAVA please Arrays are a very powerful data structure with which you must become very familiar....
JAVA please Arrays are a very powerful data structure with which you must become very familiar. Arrays hold more than one object. The objects must be of the same type. If the array is an integer array then all the objects in the array must be integers. The object in the array is associated with an integer index which can be used to locate the object. The first object of the array has index 0. There are many problems where...
Topics Arrays Accessing Arrays Description Write a C++ program that will display a number of statistics...
Topics Arrays Accessing Arrays Description Write a C++ program that will display a number of statistics relating to data supplied by the user. The program will ask the user to enter the number of items making up the data. It will then ask the user to enter data items one by one. It will store the data items in a double array. Then it will perform a number of statistical operations on the data. Finally, it will display a report...
Need someone to fix my code: #include<iostream> using namespace std; struct student { double firstQuizz; double...
Need someone to fix my code: #include<iostream> using namespace std; struct student { double firstQuizz; double secondQuizz; double midTerm; double finalTerm; string name; }; int main() { int n; cout<<"enter the number of students"<<endl; cin>>n; struct student students[n]; int i; struct student istudent; for(i=0;i<n;i++) {    cout<<"Student name?"; cin >> istudent.name; cout<<"enter marks in first quizz , second quizz , mid term , final term of student "<<i+1<<endl; cin>>students[i].firstQuizz>>students[i].secondQuizz>>students[i].midTerm>>students[i].finalTerm; } for(i=0;i<n;i++) { double marks=0; double score=students[i].firstQuizz+students[i].secondQuizz+students[i].midTerm+students[i].finalTerm; marks=(students[i].firstQuizz*0.25)+(students[i].secondQuizz*0.25)+(students[i].midTerm*0.25)+(students[i].finalTerm*0.50); double totalArrgegateMarks =...
My assignment: Triplet Template Class Directions: Define a template class for a generic triplet. The private...
My assignment: Triplet Template Class Directions: Define a template class for a generic triplet. The private data member for the triplet is a generic array with three elements. The triplet ADT has the following functions:  default constructor  explicit constructor: initialize the data member using parameters  three accessors (three get functions) which will return the value of each individual element of the array data member  one mutator (set function) which will assign values to the data member...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the codes below. Requirement: Goals for This Project:  Using class to model Abstract Data Type  OOP-Data Encapsulation You are asked to write an app to keep track of a relatively small music library. The app should load song information from a data file once the app is started. It should allow user to view, add, remove, and search for songs. The app should...
my code has several functions; delete and backward functions are not working, rewrite the code for...
my code has several functions; delete and backward functions are not working, rewrite the code for both functions and check them in the main: #include<iostream> #include<cassert> using namespace std; struct nodeType {    int info;    nodeType *link; }; class linkedList { public:    void initializeList();    bool isEmptyList();    void print();    int length();    void destroyList();    void insertFirst(int newItem);    void insertLast(int newItem);    int front();    linkedList();    void copyList(const linkedList otherList);    void insertNewValue(int value);...