Q1. A) Option : C
After executing the instruction num[4], nothing will happen. If you print the value by cout << num[4];. then 4 will be printed
Q2. A) No option is correct. Actually vector vec, contains 8 elements totally. Check the attached code
Hope this will clarify your doubts.Let me know, still if you have any queries..
C++ int num [ ] = { 1,2,3,3,4,5,6,7,8 } vector <int> vec (num, num + 8)...
Example program
#include <string>
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
vector<int> factor(int n)
{
vector <int> v1;
// Print the number of 2s that divide n
while (n%2 == 0)
{
printf("%d ", 2);
n = n/2;
v1.push_back(2);
}
// n must be odd at this point. So we can
skip
// one element (Note i = i +2)
for (int i = 3; i <=...
when will the (return) word take us?
it will end the if or the while or both?
7 | 8 6 void insert(int num, int loc){ int par; while(loc>0){ 91 par=(loc-1)/2; if (num<=arr[par]) { arr[loc]=num; return; Oo own v L arr[loc]=arr par]; locupar; 16 F }/*End of while*/ arr[@]=num; /*assign num to t 18 - }/*End of insert() */ * *
What is the value of result after the following code executes? int a = 60; int b = 15; int result = 20; if (a = b) result *= 3; 30 20 60 10 code will not execute The numeric data types in C++ can be broken into two general categories which are integers and floating-point numbers singles and doubles real and unreal numbers numbers and characters numbers and literals Which line in the following program will cause a compiler error?...
question about c++ find function int num_to_id(int num) { static const int table[] = { 10, 15, 30, 50 }: assert(std::find(&table[0], &table[4], num) != &table[4]); return std::find(&table[0], &table[4], num) - &table[0]: } why do you need &table[0] and [4] and have to extract &table[0] from them ??
QUESTION 18 Rewrite this if/else if code segment into a switch statement int num = 0; int a = 10, b = 20, c = 20, d = 30, x = 40; if (num > 101 && num <= 105) { a += 1; } else if (num == 208) { b += 1; X = 8; } else if (num > 208 && num <210) { c=c* 3; } else { d+= 1004;
3) [16 points total] Consider the following algorithm int SillyCalc (int n) int i; int Num, answer; if (n <= 4) return n 10; else { Num-SillyCalcl n/4) answer = Num + Num + 10; for (i-2; i<-n-1; ++) answer- answer+ answer; return answer; Do a worst case analysis of this algorithm, counting additions only (but not loop counter additions) as the basic operation counted, and assuming that n is a power of 2, i.e. that n- 2* for some...
int num; int total = 0; cout << "Enter a number from 1 to 10."; cin >> num; switch (num) { case 1: case 2: total = 5; case 3: total = 10; case 4: total = total + 3; case 8: total = total + 6; default: total = total + 4; } cout << total; A. 10 B. 0 C. 23 D. 3 E. None of these
C++ Question
12. Based on our Vector class which only held integers, we want to implement a class Iterator, sufficient to handle a ranged for. (You are not writing any part of the class Vector!!!) Our goal is for the following function to work properly, i.e. to double every int in the Vector v. void double(Vector& v) { for (int& val : v) { val *= 2; } } As you know, the Vector class must support the methods begin()...
3) [16 points totall Consider the following algorithm: int SillyCalc (int n) { int i; int Num, answer; if (n < 4) 10; return n+ else f SillyCalc(Ln/4) answer Num Num 10 for (i-2; i<=n-1; i++) Num + = answer + answer; answer return answer } Do a worst case analysis of this algorithm, counting additions only (but not loop counter additions) as the basic operation counted, and assuming that n is a power of 2, i.e. that n- 2*...
4.9 [10/20/20/15/15]<4.2> Consider the following code, which multiplies two vec- tors that contain single-precision complex values: for (i-0:i <300:i++) Assume that the processor runs at 700 MHz and has a maximum vector length of 64. The load/store unit has a start-up overhead of 15 cycles; the multiply unit, 8 cycles; and the add/subtract unit, 5 cycles. a. [101 <4.3> What is the arithmetic intensity of this kemel? Justify your answer. b. [20] <4.2> Convert this loop into RV64V assembly code...