1. (1 point) Write a single statement to create an array that contains values fo
ID: 3664351 • Letter: 1
Question
1. (1 point) Write a single statement to create an array that contains values for daily water usage over a week (in gallons). (You should make up these values using any numbers between 50 and 500.) Name your array/variable water_usage. There should be one entry in the array for each day of the week.
2. (2 point) Create a new variable, current_day, and set it to an integer from 1 to 7. Then use the current_day to print out the water usage for that day (ie, index into the water_usage array you created in problem 1.
3. (1 points) Given an array monthly_water_usage, show how you would create a variable named number_of_days and assign to it the number of elements contained in monthly_water_usage. You may not hardcode the number of elements.
4. (1 point) Write a statement to create an array of 20 integers, all set to zero, and store this array in a variable named counts.
5. (1 point) If you want to repeatedly ask a user to enter 10 grades, what is the best MATLAB programming construct to use? (Just give one MATLAB keyword.)
6. (2 points) What are the differences between a function and a script in MATLAB? List at least two differences, and describe each one.
7. (2 points) Suppose you see this in a MATLAB script:
sine(4)
Is there an easy way to determine if this is a call to a function named sine, or an array access to the array stored in sine? How would you figure this out?
Explanation / Answer
1.int waterusage[7];
for(int i=0;i<7;i++)
cin>>wateusage[i];
2.int currentday;
cin>>currentday; /* values from 1 to 7 */
if currentday==1
cout<<waterusage[0];
this will continue for 7 days.
3. int monthly_water_usage[n];
int numberofdays
numberofdays=n;
4.int a[20]={0};
int counts;
for (i=0;i<20;i++)
counts=a[i];
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.