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

1.We decide to ask user to key in the length of the table and the data that need

ID: 3531396 • Letter: 1

Question

1.We decide to ask user to key in the length of the table and the data that needs to go into the table. One may think they can do something like this:

int n;

std::cout << " Please key in the mumber of entries in your table";

std::cin >> n;

double t[n];

double T[n];

Explain why this can not be done.

2. Instead we allocate two large arrays of size 1000 for t and T and simply use as many entries as needed based on the user input. We can use do-while loops make sure the number of entries will be in the acceptable range of 2<=n<=1000, explain why n must be less than 1000?

Explanation / Answer

1> this is because when we declear the array double t[n] the memory allocation in this statement has to be defined

n should be "const" mean no variable should be used to state how many memory of the type double should be allocated

it is not dynamically allocated;hence report an error

2> When we declear an array as t[1000] here 1000 memory blook of double type is researbed for array t

on doing do-while we can access 1000 blook of double type in the array

int i=0;

double t[1000];

do{

int num=0;

std:cin>>num;

if(num>=2 || num<=100){

t[i]=num;

i++;

}


}while(i<1000);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote