Question

In: Computer Science

Language:C++ Program:Visual basic I have errors on line 102 "expression must have a constant value line...

Language:C++

Program: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;
}

Solutions

Expert Solution

The given code is working just fine.

Program Sample Run:


Related Solutions

Language:C++ NEEDS TO WORK IN VISUAL BASIC error on line 41 expression must have a constant...
Language:C++ NEEDS TO WORK IN VISUAL BASIC error on line 41 expression must have a constant value #include using namespace std; //function declaration void EnterRents(int*, int); void displayRents(int*, int); void selectionSort(int*, int); int sumRents(int* temp, int size) { int sum = 0; for (int i = 0; i < size; i++) { sum += *(temp + i); } return sum; } void Displaymemory(int* temp, int size) { /*int memory; memory=sizeof(temp)*size; cout< for (int i = 0; i < size; i++)...
a) Give the mathematical equilibrium constant expression Kc and Kp (not the value!) for the reaction...
a) Give the mathematical equilibrium constant expression Kc and Kp (not the value!) for the reaction 2N2O5(g) ↔ 4NO2 (g) + O2(g) b) At 250oC the concentrations of N2O5, NO2 and O2 are 0.100 mol/L, 0.0283 mol/L and 0.0105 mol/L. Calculate the values for Kc and Kp
Net-Ionic Equation for Hydrolysis? Expression for equilibrium constant (Ka or Kb)? Value of Ka or Kb?...
Net-Ionic Equation for Hydrolysis? Expression for equilibrium constant (Ka or Kb)? Value of Ka or Kb? for NaC2H3O3, Na2CO3, NH4Cl, ZnCl2, KAl(SO4)2
So if I have KNO3 and I mix it with water, is the solution basic or...
So if I have KNO3 and I mix it with water, is the solution basic or acidic? How do I know? I'm very confused in how to know if acids or bases are made when mixing something with water.. Also, is ClO- a weak acid or a base when mixed with water? and how?
What is the value of Expression below (i^14 + i^15 + i^16 + i^17)÷(i^20 + i^21 + i^22 + i^23)
What is the value of Expression below(i^14 + i^15 + i^16 + i^17)÷(i^20 + i^21 + i^22 + i^23)
I am creating SAS code, but am receiving an errors " ERROR: Value is out of...
I am creating SAS code, but am receiving an errors " ERROR: Value is out of range or inappropriate. ERROR: No body file. HTML5(WEB) output will not be created." This is the code: option ls=65 ps=65; data one; input IQ; cards; 145 139 122 ; title 'Normal Quantile - Quantile Plot for IQ'; ods graphics on; proc univariate data=one; qqplot IQ / normal (mu=est sigma=est); run;
Java Program to Fully Parenthesize an expression. Hi guys. I have a small task which I...
Java Program to Fully Parenthesize an expression. Hi guys. I have a small task which I cannot find the solution for. It involves expressions with Infix I'll need a Java Program to convert an expression, eg. 3+6*(x-y)+x^2 to ((3 + (6 * (x-y))) + (x ^ 2)) Kindly assist. Thanks
I have a project about how is calculas related to mechanical engineer. I must have a...
I have a project about how is calculas related to mechanical engineer. I must have a total of 500 word can someone help me please?
Objects that move in a straight line with a constant speed—not speeding up or slowing down—have...
Objects that move in a straight line with a constant speed—not speeding up or slowing down—have zero acceleration. We call this kind of motion: Uniform Motion. We can identify uniform motion when the object travels equal distance intervals in equal times. We can identify non-uniform motion, or accelerated motion, when the object travels equal distance intervals in unequal times. Finally, we have two types of non-uniform motion: motion with constant acceleration and motion with a non-constant (or changing) acceleration. Activity...
I have to complete a template on the basic concept with the subject being pain ,...
I have to complete a template on the basic concept with the subject being pain , can someone tell me the effects of pain on the body system. Also how pain affects electrolytes/acid-base balance
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT