Question

In: Computer Science

True or False: It's easy to loop through an array using a for loop in C++...

True or False: It's easy to loop through an array using a for loop in C++ because you can use the .size() function to get the total number of spaces in the array

True or False: It's easy to loop through a vector using a for loop in C++ because you can use the .size() function to get the total number of spaces in the vector

Solutions

Expert Solution

1.False it is not very easy to loop through an array using a for loop in c++ beacuse we cannot use the .size() function as it is not available in the c++.

code to demonstrate the above statement

#include<bits/stdc++.h>
using namespace std;
int main(){
    int a[]={1,2,3,4,5,6};
    for(int i=0;i<a.size();i++){
        cout<<a[i]<<" ";
    }
}

the above code will show an error which is shown below

2.True in vector It easy to loop through a vector using a for loop in C++ because you can use the .size() function to get the total number of spaces in the vector

program to demonstrate the above statement

#include<bits/stdc++.h>
using namespace std;
int main(){
    vector<int>v{1,2,3,4,5,6};
    for(int i=0;i<v.size();i++){
        cout<<v[i]<<" ";
    }
}

tje output of the following program will be

If you have any query comment it down and if you like the answer upvote it


Related Solutions

In C++ using a single dimensional array Create a program that uses a for loop to...
In C++ using a single dimensional array Create a program that uses a for loop to input the day, the high temperature, and low temperature for each day of the week. The day, high, and low will be placed into three elements of the array. For each loop the day, high, and low will be placed into the next set of elements of the array. After the days and temps for all seven days have been entered into the array,...
Using C++ language, create a program that uses a struct with array variables that will loop...
Using C++ language, create a program that uses a struct with array variables that will loop at least 3 times and get the below information: First Name Last Name Job Title Employee Number Hours Worked Hourly Wage Number of Deductions Claimed Then, determine if the person is entitled to overtime and gross pay. Afterwards, determine the tax and net pay. Output everything to the screen. Use functions wherever possible. Bonus Points: Use an input file to read in an unknown...
(True or False) The following is an infinite loop. int main() { bool flag = false;...
(True or False) The following is an infinite loop. int main() { bool flag = false; int num = 0; while(!flag); { cin >> num; if(num == -1) { flag = true; } } return 0; }
Write a program to reverse each integer number on array (size 3) using while loop. C++...
Write a program to reverse each integer number on array (size 3) using while loop. C++ Input: 3678 2390 1783 Output: 8763 0932 3871
6 C++ Questions 13. True/False: every while loop is guaranteed to execute at least one time....
6 C++ Questions 13. True/False: every while loop is guaranteed to execute at least one time. 14. Assume there is a file named "cards.txt" in the current directory which contains 3 ints. Write a code snippet which reads in the three ints and outputs their average (mean) to the screen. 15. True/False: the following function prototype takes an array and its size as its parameters. If you change the value of the array's elements within the function, the changes persist...
Write a function in JAVASCRIPT that accepts an array as argument. The function should loop through...
Write a function in JAVASCRIPT that accepts an array as argument. The function should loop through the array elements and accumulate the sum of ASCII value of each character in element and return the total. For example: function([‘A’, ‘bc’, 12]); // returns 361 which is the sum of 65 + 98 + 99 + 49 + 50 Use of any built in string functions or built in array functions is not allowed, Any help would be much appreciated
Using for loop . Input an integer and identify whether it's EVEN OR ODD ( without...
Using for loop . Input an integer and identify whether it's EVEN OR ODD ( without using modulo operator ) using only <iostream> . C++ programming
In C++, Create an array of 10 characters. Use a loop to prompt for 10 letters...
In C++, Create an array of 10 characters. Use a loop to prompt for 10 letters (a-z|A-Z) and store each in the array. If an invalid character is entered, re-prompt until a valid char is entered. After 10 characters are stored in the array, use a loop to print out all characters in the array from the first to the last element. Then, use another loop starting at the last element to print all characters in the array in reverse...
Answer true or false: a. The properties that make water a good solvent are it's polarity...
Answer true or false: a. The properties that make water a good solvent are it's polarity and its capacity for hydrogen bonding. b. when ionic compounds dissolve in water, their ions become solvated by water molecules. c. The term " water of hydration " refers to the number of water molecules that surround an ion in aqueous solution. d. The term " anhydrous " means " without water ". e. An electrolytes is a substance that dissolves in water to...
After three passes through the outer loop of a sorting algorithm, an array changes from 43...
After three passes through the outer loop of a sorting algorithm, an array changes from 43 16 48 37 81 54 71 29 to 16 29 37 48 81 54 71 43 What sorting algorithm is being used to sort the array? A. Selection sort B. Bubble sort C. Insertion sort
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT