Search Header Logo

Final Exam Review

Authored by Elise Neubarth

Computers

University

Used 4+ times

Final Exam Review
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

13 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Declare a double array called grocery_List. Make the array with a size of 30.

double grocery_List[30];

double grocery_List=30;

grocery_List=30;

Answer explanation

When declaring an array, you do the following:

datatype arrayname[size of array]. For this example,

double grocery_List[30];

2.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Use a loop to enter elements into the following array:

double grocery_List[30];

scanf("%lf",&grocery_List);

for (int i=0; i<=30; i++)

{

scanf("%lf", &grocery_List[i]);

}

for (int i=0; i<30; i++)

{

scanf("%lf", &grocery_List[i]);

}

for (int i=0; i<30; i++)

{

scanf("%lf", &grocery_List);

}

Answer explanation

When entering elements into an array, you need to use a loop. The easiest loop to use with arrays are for loops. When you want to access a specific element within an array, you need to do the following:

arrayname[index].

Therefore, when we use a for loop to enter values within an array, we write the following:

for (int i=0; i<30; i++)

{

scanf("%lf", &grocery_List[i]);

}

When the loop runs the first time, we are adding a value into the first index of the array or grocery_List[0] because i=0. When we run the loop again, we enter the value into grocery_List[1] because i=1. This will continue for the entirety of the loop.

3.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Write the function call for the following function prototype:

double total (double list[]);

int main ()

{

double grocery_List[30];

// code that enters values into the array

total(grocery_List);

return 0;

}

int main ()

{

double grocery_List[30];

// code that enters values into the array

double sale=total(grocery_List[30]);

return 0;

}

int main ()

{

double grocery_List[30];

// code that enters values into the array

double total(grocery_List);

return 0;

}

int main ()

{

double grocery_List[30];

// code that enters values into the array

double sale=total(grocery_List);

return 0;

}

Answer explanation

When you pass the entire array from the main function to the programmer defined function, you write the following:

sale=total(grocery_List);

//where sale was previously declared as a double datatype

4.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Write a function definition that returns a double and accepts the following array from the main function:

double grocery_List[30]

Name the function: total

The function will calculate the total of the array.

double total (double list[])

{

double sum=0.0;

for (int i=0; i<30; i++){

sum+=list;

}

return sum;

double total (double list[])

{

double sum=0.0;

for (int i=0; i<30; i++){

sum+=list[i];

}

return sum;

double total (double list[30])

{

double sum=0.0;

for (int i=0; i<30; i++){

sum+=list[i];

}

return sum;

double total (double list[])

{

double sum=0.0;

for (int i=0; i<=30; i++){

sum+=list[i];

}

return sum;

Answer explanation

When we pass an array from the main function to a programmer defined function, we write the following:

returntype functionname (datatype arrayname[])

or

double total (double list[]).

When calculating the sum of the array, you need to use a loop.

When we are using a variable to store the sum, we need to initialize this variable to be 0 before we perform any calculations (0.0 if the answer is a double).

5.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Write a definition of a struct type for the following prompt:

Create a struct to store employee information such as employee ID, position, and salary.

struct employee{

int employeeID;

char position [100];

double salary;

};

struct typedef{

int employeeID;

char position [100];

double salary;

} employees;

typedef struct{

int employeeID;

char position [100];

double salary;

} employees;

typedef employees{

int employeeID;

char position[100];

double salary;

};

Answer explanation

When we write a struct definition, we write it as follows:

typedef struct{

//fields of your struct

} structname;

Dr. Sorgente did introduce you to a different way of writing structs (C++). However, she has mentioned that you need to write them as stated above.

6.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Declare employee1 as a part of the employee struct.

typedef Struct{

int employeeID;

char position [100];

double salary;

} employees;

employee1;

int main ()

{

employees employee1;

return 0;

}

int main ()

{

struct employee1

return 0;

}

I don't know

Answer explanation

When we want to declare a variable as a part of the struct, we use the struct name as the "data type" for the variable. Therefore, if the struct name is employees, when we declare a variable, employee1, we say

employees employee1 within the main function.

7.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Ask the user to enter the employeeID, the position of the employee, and the salary for the employee. Please use the following struct for reference:

typedef struct{

int employeeID;

char position [100];

double salary;

} employees;

int main void(){

employees employee1;

scanf("%d", &employee1.employeeID);

scanf("%s", employee1.position);

scanf("%lf", &employee1. salary);

}

int main void(){

scanf("%d", &employeeID);

scanf("%s", position);

scanf("%lf", &salary);

}

int main void(){

employees employee1;

scanf("%d", &employees.employeeID);

scanf("%s", employees.position);

scanf("%lf", &employees. salary);

}

Answer explanation

When we are accessing different fields within the struct, we use the ".". For example, when we want to access employee1's ID, we say:

employee1.employeeID.

Since we previously declared employee1 to be a variable for the struct, employees, we will use employee1 and not employees.

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?