Question

In: Computer Science

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++)
{
cout << &temp[i] << " ";
}
}
//main drive
int main()
{
int n;

char c;

cout << "Enter a for enter the rents amounts" << endl;
cout << "Enter b to display rents amounts" << endl;
cout << "Enter c to sort the rents amounts" << endl;
cout << "Enter d to total rents amounts" << endl;
cout << "Enter e to display memory alloaction" << endl;
cout << "Enter f to exit" << endl;
cout << "Enter the number of amount items stored in Amout array " << endl;
cin >> n;
int arr[n];
//while statement with switch case to call declared function
while (1)
{
cout << endl;
cout << "Enter your choice" << endl;
cin >> c;
switch (c)
{
case 'a':
cout << "Enter the " << n << " no of Rents amount" << endl;
EnterRents(arr, n);
break;
//Other switch cases
case 'b':
cout << "Display Rents" << endl;
displayRents(arr, n);
break;
case 'c':
cout << "sort Rents amounts" << endl;
selectionSort(arr, n);
cout << "sorted elemnts are" << endl;
displayRents(arr, n);
break;
case 'd':
cout << "Total Rents" << endl;
cout << sumRents(arr, n) << endl;
break;
case 'e':
cout << "Display memoryLocation" << endl;
Displaymemory(arr, n);
break;
case 'f':
cout << "f entered by user to exit" << endl;
exit(1);
default:
cout << "Invalid input.";
break;

}
}

return 0;
}
//function definition
void EnterRents(int* arr, int size)
{
for (int i = 0; i < size; i++)
{
cin >> arr[i];
}
}
void displayRents(int* arr, int n)
{
for (int i = 0; i < n; i++)
{
cout << *(arr + i) << " ";
}
}
//void selectionSort(int*,int)
void selectionSort(int* pointer, int size)
{
int* i, * j, swap;
int* end = NULL;

if (size < 2 || pointer == NULL)
return;

end = pointer + size - 1;

for (i = pointer; i < end; i++)
{
for (j = i + 1; j <= end; j++)
{
if (*j < *i)
{
swap = *i;
*i = *j;
*j = swap;
}
}
}
}

Solutions

Expert Solution

MODIFIED CODE :

#include<iostream>
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;
int memory=sizeof(temp)*size;
for (int i = 0; i < size; i++)
{
cout << &temp[i] << " ";
}
}
//main drive
int main()
{
int n;

char c;

cout << "Enter a for enter the rents amounts" << endl;
cout << "Enter b to display rents amounts" << endl;
cout << "Enter c to sort the rents amounts" << endl;
cout << "Enter d to total rents amounts" << endl;
cout << "Enter e to display memory alloaction" << endl;
cout << "Enter f to exit" << endl;
cout << "Enter the number of amount items stored in Amout array " << endl;
cin >> n;
int arr[n];
//while statement with switch case to call declared function
while (1)
{
cout << endl;
cout << "Enter your choice" << endl;
cin >> c;
switch (c)
{
case 'a':
cout << "Enter the " << n << " no of Rents amount" << endl;
EnterRents(arr, n);
break;
//Other switch cases
case 'b':
cout << "Display Rents" << endl;
displayRents(arr, n);
break;
case 'c':
cout << "sort Rents amounts" << endl;
selectionSort(arr, n);
cout << "sorted elemnts are" << endl;
displayRents(arr, n);
break;
case 'd':
cout << "Total Rents" << endl;
cout << sumRents(arr, n) << endl;
break;
case 'e':
cout << "Display memoryLocation" << endl;
Displaymemory(arr, n);
break;
case 'f':
cout << "f entered by user to exit" << endl;
exit(1);
default:
cout << "Invalid input.";
break;

}
}

return 0;
}
//function definition
void EnterRents(int* arr, int size)
{
for (int i = 0; i < size; i++)
{
cin >> arr[i];
}
}
void displayRents(int* arr, int n)
{
for (int i = 0; i < n; i++)
{
cout << *(arr + i) << " ";
}
}
//void selectionSort(int*,int)
void selectionSort(int* pointer, int size)
{
int* i, * j, swap;
int* end = NULL;

if (size < 2 || pointer == NULL)
return;

end = pointer + size - 1;

for (i = pointer; i < end; i++)
{
for (j = i + 1; j <= end; j++)
{
if (*j < *i)
{
swap = *i;
*i = *j;
*j = swap;
}
}
}
}

OUTPUT :


Related Solutions

fix the code with constant expression error exrpession below in visual studio #include <iostream> #include <cstdlib>...
fix the code with constant expression error exrpession below in visual studio #include <iostream> #include <cstdlib> #include <ctime> void insertion_sort(int array[], int size, int start); void heap_sort(int B[], int n); void build_max_heap(int B[], int n); void max_heapify(int B[], int i, int n); void quick_sort(int B[], int p, int r); int partition(int B[], int p, int r); int main() {    int m = 10, Nf = 20000, Ns = 1000, delta = 1000, A[m][Nf];    for (int i = 0;...
For each of the following Visual Basic code snippets, identify the syntax error.   If intX >...
For each of the following Visual Basic code snippets, identify the syntax error.   If intX > 100   lblResult.Text = "Invalid Data" End If   Dim str As String = "Hello" Dim intLength As Integer intLength = Length(str) If intZ < 10 Then   lblResult.Text = "Invalid Data"   Dim str As String = "123" If str.IsNumeric Then   lblResult.Text = "It is a number." End If   Select Case intX   Case < 0     lblResult.Text = "Value too low."   Case > 100     lblResult.Text = "Value too high."   Case Else     lblResult.Text = "Value...
For a regression with log(bweight) as the dependent variable, we have Variable Estimate Standard Error Constant/Intercept...
For a regression with log(bweight) as the dependent variable, we have Variable Estimate Standard Error Constant/Intercept 4.66 0.029 Male 0.03 0.010 Motheduc 0.002 0.002 lfaminc 0.02 0.006 You expect an increase in family income to increase birth weight. Test this hypothesis at the 1% level of significance. Make sure you explicitly include all of the steps.
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...
Tisla Motors needs to select an assembly line for producing their new SUV. They have two...
Tisla Motors needs to select an assembly line for producing their new SUV. They have two options: Option A is a highly automated assembly line that has a large up-front cost but low maintenance cost over the years. This option will cost $9 million today with a yearly operating cost of $2 million. The assembly line will last for 5 years and be sold for $5 million in 5 years. Option B is a cheaper alternative with less technology, a...
Ruff Motors needs to select an assembly line for producing their new SUV. They have two...
Ruff Motors needs to select an assembly line for producing their new SUV. They have two options: Option A is a highly automated assembly line that has a large up-front cost but low maintenance cost over the years. This option will cost $9 million today with a yearly operating cost of $2 million. The assembly line will last for 5 years and be sold for $5 million in 5 years. Option B is a cheaper alternative with less technology, a...
What needs must have been met previously with the clients to make this new venture a...
What needs must have been met previously with the clients to make this new venture a potentially successful idea?
You work for a shipping line and have been asked to issue a Switch Bill of...
You work for a shipping line and have been asked to issue a Switch Bill of Lading because the goods covered have been resold on the high-seas and the discharge port has now been changed to another port, at which your ship also calls. Analyze FIVE (5) points you should check to protect the shipping line from any possible claims before issuing the Switch Bill of Lading.
A new colony have been established on the moon. The colony must maintain constant communication from...
A new colony have been established on the moon. The colony must maintain constant communication from the Moon Base to the Earth ground control To reduce communication overhead and cost, only a single highspeed communication link is established from the Moon Base colony to the Earth command center. Provide the best communication strategy to compress the bandwidth from the Moon Base colony to propagate the transmission to the Earth. Describe your solution and provide illustration to support your answer. The...
Over the River Bridge Company needs to replace its CNC Machining line. They have 3 different...
Over the River Bridge Company needs to replace its CNC Machining line. They have 3 different options for the replacement. Option 1: Replace the worn-out equipment with the same equipment. The quoted price of this equipment is $16,500,000 due in full upon delivery. This equipment uses $185,000 of electricity a year. It has a service life of 5 years. It has a scrap value of $375,000. Option 2: Replace the worn-out equipment with Eco-CNC equipment. The quoted price of this...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT