Mark the following statements as true or false.
A double type is an example of a simple data type. (1)
A one-dimensional array is an example of a structured data type. (1)
The size of an array is determined at compile time. (1,6)
Given the declaration:
int list[10];
the statement:
list[5] - list[3] * list[2];
updates the content of the fifth component of the array list. (2)
If an array index goes out of bounds, the program always terminates in an error. (3)
The only aggregate operations allowable on int arrays are the increment and decrement operations. (5)
Arrays can be passed as parameters to a function either by value or by reference. (6)
A function can return a value of type array. (6)
In C++, some aggregate operations are allowed for strings. (11,12,13)
The declaration:
char name [16] = "John K. Miller";
declares name to be an array of 15 characters because the string "John K. Miller" has only 14 characters. (11)
The declaration:
char str = "Sunny Day";
declares str to be a string of an unspecified length. (11)
As parameters, two-dimensional arrays are passed either by value or by reference. (15,16)
a.
A double type is a simple data type. Hence, the given statement is “True”.
A data type is called simple if variables of that type can store only one valueat a time. In contrast, in a structured data type, each data item is a collection of otherdata items. Simple data types are building blocks of structured data types.
A double type is a simple data type. Hence, the given statement is “True”.
Explanation of Solution
Since a double type can store a single value at a time it is a simple data type.
b.
One-dimensional array is an example of a structured data type. Hence, the given statement is “True”.
A data type is called simple if variables of that type can store only one valueat a time. In contrast, in a structured data type, each data item is a collection of otherdata items. Simple data types are building blocks of structured data types.
One-dimensional array is an example of a structured data type. Hence, the given statement is “True”.
Explanation of Solution
One-dimensional array is an example of a structured data type, as it can store a collection of other data items.
c.
The size of an array is determined at compile time. Hence, the given statement is “True”.
An array is a collection of a fixed number of components (also called elements)all of the same data type and in contiguous (that is, adjacent) memory space.
The size of an array is determined at compile time. Hence, the given statement is “True”.
Explanation of Solution
An array is a collection of a fixed number of components hence the size of an array is determined at compile time.
d.
The statement does not update the fifth component. Hence, the given statement is “False”.
In C++[ ] is an operator called the array subscripting operator and the array index starts at 0.
The statement does not update the fifth component. Hence, the given statement is “False”.
Explanation of Solution
The statement updates the sixth component of the array list as the subscript begins with 0.
e.
If an array index goes out of bounds, the program does not necessarily terminatein an error. Hence, the given statement is “False”.
C++ does not check whether the index value is within range. If the index goes out of bounds and the program tries toaccess the component specified by the index, then whatever memory location is indicatedby the index that location is accessed. This can result in altering or accessingthe data of a memory location that was never intended to be modified or accessed. It can also lead to accessing a protected memory that causes the program to instantly halt. Hence, several unknown things can happen if the index goes out of bounds during execution.
If an array index goes out of bounds, the program does not necessarily terminatein an error. Hence, the given statement is “False”.
Explanation of Solution
If the index goes out of bounds and the program tries to access the component specified by the index, then whatever memory location is indicated by the index that location is accessed. This may or may not cause the program to instantly halt or terminate in an error.
f.
C++ does not allow aggregateoperations on an array. Hence, the given statement is “False”.
An aggregate operation on an array is any operation thatmanipulates the entire array as a single unit.
C++ does not allow aggregateoperations on an array. Hence, the given statement is “False”.
Explanation of Solution
C++ does not allow aggregate operations on an array.
g.
Arrays can be passed as parameters to a function never by value but only by reference. Hence, the given statement is “False”.
In C++, arrays are passed by reference only. Because arrays are passed by reference only, the &symbol is never used when declaringan array as a formal parameter.
Arrays can be passed as parameters to a function never by value but only by reference. Hence, the given statement is “False”.
Explanation of Solution
In C++, arrays are passed by reference only and never by value.
h.
A function cannot return a value of type array. Hence, the given statement is “False”.
A function cannot return a value of type array.
A function cannot return a value of type array. Hence, the given statement is “False”.
Explanation of Solution
A function cannot return a value of type array.
i.
In C++, some aggregate operations are allowed for strings. Hence, the given statement is “True”.
Most rules that apply to arrays apply to C-strings as well. Aggregateoperations, such as assignment and comparison, are not allowed on arrays. Also the input/output of arrays is done component-wise. But, C++ allows aggregate operations of the input and output on C-strings which are nothing but character arrays terminated with the null character.
In C++, some aggregate operations are allowed for strings. Hence, the given statement is “True”.
Explanation of Solution
C++ allows aggregate operations of the input and output on C-strings which are nothing but character arrays.
j.
The name array is of size 16 and not 15. Hence, the given statement is “False”.
The name array is of size 16 which is mentioned in the declaration of the variable and not the size of string stored into it. There remains 1 unused component in the name array.
The name array is of size 16 and not 15. Hence, the given statement is “False”.
Explanation of Solution
The name array is of size 16 which is mentioned in the declaration of the variable and not the size of string stored into it. There remains 1 unused component in the name array.
k.
Aggregate operation such as assignment is not allowed on arrays and the statement is illegal. Hence, the given statement is “False”.
Aggregate operation such as assignment is not allowed on arrays and the statement is illegal. For assignment operation on c-strings (char arrays) c-string functions are needed.
Aggregate operation such as assignment is not allowed on arrays and the statement is illegal. Hence, the given statement is “False”.
Explanation of Solution
Aggregate operation such as assignment is not allowed on arrays and the statement is illegal. For assignment operation on c-strings (char arrays) c-string functions are needed.
l.
Two-dimensional arrays can be passed as parameters to a function, and they arepassed by reference only. Hence, the given statement is “False”.
Two-dimensional arrays can be passed as parameters to a function, and they arepassed by reference.
Two-dimensional arrays can be passed as parameters to a function, and they arepassed by reference only. Hence, the given statement is “False”.
Explanation of Solution
Two-dimensional arrays can be passed as parameters to a function, and they arepassed by reference.
Want to see more full solutions like this?
Chapter 8 Solutions
EBK C++ PROGRAMMING: FROM PROBLEM ANALY
- 1) Write a program in C that stores a list of employee records in an array of structs. Each employee record should contain the following fields: Name (string), Age (int), Salary (float), Department (string). The program should prompt the user to enter the name of an employee, and then search the array of employee records for an employee with a matching name. If a matching employee is found, the program should print out the employee's age, salary, and department. If no matching employee is found, the program should print an error message. The program should use a linear search algorithm to find a matching employee in the array. If the employee's age is greater than 50, their salary should be multiplied by 1.1. If the employee's age is less than or equal to 50, their salary should be divided by 1.2. 2) Write a C program that defines a function called 'multiply_by_two' that takes an integer as an argument and returns the result of multiplying it by 2. The main function of the program…arrow_forwardC CodeApproved Libraries:<string.h> *not allowed in some questions<math.h><stdlib.h><time.h> (for srand(time(0)) only)arrow_forwardWrite in Java. initializer list example: int [] array = {1,2,3};arrow_forward
- JAVA LANGUAGEarrow_forward1)Please do it in C++ languagearrow_forwardC++ Coding: Arrays Implement ONE array of the English alphabet (26 characters). Cast and generate the array with a loop. Output the array with a loop. Swap character variables with a swap function. Reverse all array elements with a loop and the swap function. Output the updated array with a loop. Example Output:Original: A B C D E F G H I J K L M N O P Q R S T U V W X Y ZReversed: Z Y X W V U T S R Q P O N M L K J I H G F E D C B Aarrow_forward
- python assignment Matrix class Implement a matrix class (in matrix.py). a) The initializer should take a list of lists as an argument, where each outer list is a row, and each value in an inner list is a value in the corresponding row. b) Implement the __str__ method to nicely format the string representation of the matrix: one line per row, two characters per number (%2d) and a space between numbers. For example: m = Matrix([[1,0,0],[0,1,0],[0,0,1]]) print(m)> 1 0 0> 0 1 0> 0 0 1 c) Implement a method scale(factor) that returns a new matrix where each value is multiplied by scale. For example: m = Matrix([[1,2,3],[4,5,6],[7,8,9]])n = m.scale(2)print(n)> 2 4 6> 8 10 12>14 16 18print(m)> 1 2 3> 4 5 6> 7 8 9 d) Implement a method transpose() that returns a new matrix that has been transposed. Transposing flips a matrix over its diagonal: it switches rows and columns. m = Matrix([[1,2,3],[4,5,6],[7,8,9]])print(m)> 1 2 3> 4 5 6> 7 8…arrow_forwardc++ make a simple prrogram that takes random 2d array entered by user and organizes it use pointers for example if the user enter ((8,4),(3,4),(7,2),(8,6),(3,1)) no limit to number of sets use pointers there should be a function called transformer that will transform them into the right order and a funtion called display that will display what was inputed then it would organize it into ((4,8),(3,4),(2,7),(6,8),(1,3)) IT should only modify it and not make a copy of it.arrow_forwardWrite JAVA code General Problem Description: It is desired to develop a directory application based on the use of a double-linked list data structure, in which students are kept in order according to their student number. In this context, write the Java codes that will meet the requirements given in detail below. Requirements: Create a class named Student to represent students. In the Student class; student number, name and surname and phone numbers for communication are kept. Student's multiple phones number (multiple mobile phones, home phones, etc.) so phone numbers information will be stored in an “ArrayList”. In the Student class; parameterless, taking all parameters and It is sufficient to have 3 constructor methods, including a copy constructor, get/set methods and toString.arrow_forward
- Exercise #1: Write a C program that contains the following steps. Read carefully each step as they are not only programming steps but also learning topics that explain how numeric arrays in C work. Write a while loop to input a series of numbers (either from a file or from the keyboard, but using a file will make for easier debugging) into a one dimensional array of type double named x_arr, declared to be 25 elements in length. Count the elements as you input them. Then in a second loop, a for loop this time, print out all the elements which were input. Make up your own data file for this problem. Extend your code by writing a for loop to find the largest value in the array. The largest value should go into a variable named xhigh. Your code should then print out xhigh. Extend your code by writing a for loop to find the smallest value in the array. The smallest value should go into a variable named xlow. Your code should then print out xlow. Extend your code to produce a second array…arrow_forwardData Structure & Algorithum java program Do the following: 1) Add a constructor to the class "LList" that creates a list from a given array of objects.2) Add a method "addAll" to the "LList" class that adds an array of items to the end of the list. The header of the method is as follows, where "T" is the generic type of the objects in the list. 3) Write a Test/Driver program that thoroughly tests all the methods in the class "LList".arrow_forwardC++ Programming: Design a class to perform various matrix operations. A matrix is a set of numbers arranged in rows and columns. Therefore, every element of a matrix has a row position and a column position. If A is a matrix of five rows and six columns, we say that the matrix A is of the size 5 X 6. Clearly, a convenient place to store a matrix is in a two-dimensional array. Two matrices can be added and subtracted if they have the same size. Suppose A = [aij] and B = [bij] and are two matrices of the same size m *n in which aij denotes the element of A in the i th row and the j th column, and so on. The sum and difference of A and B are given by: A + B = [aij + bij] A - B = [aij - bij] The multiplication of A and B (A * B) is defined only if the number of columns of A is the same as the number of rows of B. If A is of the size m n and B is of the size n t, then A B = [c ik ] is of the size m t and the element cik is given by the formula: cik = ai1b1k + ai2b2k + ... + ainbnk Design…arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrNew Perspectives on HTML5, CSS3, and JavaScriptComputer ScienceISBN:9781305503922Author:Patrick M. CareyPublisher:Cengage Learning