Q2: What is the output for the following codes: 1- a) 2 6 7 8 c) 2 6 7 int arr[4]= {2, 6, 7, 8}; for (int i= 3; i>=0; i--) cout<
Q: #include using namespace std; class test{ public: test(){ cout<<"alpha\n"; } ~test(){…
A: This is about classes and the constructors.
Q: # includeusing namespace std; int main (){int m[7]= {10, 1, 1, 111, 1, 13};int i ;coutusing…
A: We can initialise array and fix the elements or elements can be inserted by user at execution In…
Q: What will the following code output? int *MyPtr, MyNums[ ]= {-1, 0, 3, 4): MyPtr = MyNums; cout<<…
A: Given:
Q: 1 #include 2 #include 3 using namespace std; 4 int main() { const int MAX = 10; char cstr[MAX];…
A: Code :- If you give more memory allocation to the character array cstr[35] it gives no error.…
Q: 1- a) 8 251 c) 8 2 5 int arr[4]- {1, 5, 2, 8}3; for (int i- 3; i>-0; i--) cout<<arr[i] <<" "; b) 15…
A: Question 1:int arr[4]={1,5,2,8};for(int i=3;i>=0;i--)cout<<arr[i]<<" ";Answer:8 2 5 1…
Q: double tab1[5] = {2,3,4,5,6}; double tab2[5] = {6,5,4,3,2}; for(int i = 0;i<5;i++)…
A: The program declares two array named tab1 of size 5 and tab2 of size 5. For loop is used to iterate…
Q: #include #include using namespace std; int main() { const int ROW_HOURS=6; //declare…
A: The solution for the above given question is given below:
Q: Complete the code: string cars[5] = {"Volvo", "BMW", "Ford", "Mazda", "Honda"}; for(int i = 0; i< _;…
A: string cars[5]={"Volvo","BMW","Ford","Mazda","Honda"}; for(int i=0;i<5;i++){…
Q: Why does little-endian vs. big-endian matter here in this code
A: *In case of multiple questions, only the first will be answered. For other questions, put separate…
Q: how to tweak the code so that when i enter for computer's ship it only shows whether i missed or hit…
A: So to do this you just have to remove the display_board() method from line no. 94 and line no.100…
Q: #include struct dna { int number; char text; char stringvalue[30]; }; int main() {…
A: NOTE: - As asked the comments are being added on each line of the program. Any modification other…
Q: 17. Given the following C code, what is the value of scores[5]? int scores[] =…
A: The objective of the question is to determine the value of the 6th element in the array 'scores'. In…
Q: // you must finish this program. it should ask how //many fish were caugh by fishermen 1-20,…
A: Complete Code in C++ #include <bits/stdc++.h> // import all libraryusing namespace std;…
Q: 1. Draw a dfa of L/L2 for L1 {a"b" : n 2 1, m 0}U{ba} L2 {b"aa : m 2 0}
A: DFA is also known as deterministic finite automata.
Q: In this lab, you use what you have learned about searching an array to find an exact match to…
A: #include <iostream>#include <string>using namespace std; int main() { string…
Q: int a[ 10] = {1,5,3,8,4,2,6,9,7}; int *p; p = &a[2]; p[0] = 10; p[1] = 15; What are the values of a?
A: Required:
Q: thedW.d What will the following code display? void showDub (int); 5. int main () int x = 2; cout « x…
A: Step 1:- Given:- void showDub(int);int main(){ int x=2; cout<<x<<endl;…
Q: What is the value of the variable ss after the following code is executed? int x[ 7 ] =…
A: In the given program, an array of size 7 is defined which contains 6 elements. Then, a variable ss…
Q: In your program for HW4- Telephone Service Simulation, when is_valid_areacode() is being executed,…
A: Below are the answers for given questions:
Q: #include #include int MAX_SIZE = 10; int n = 0; //A counter variable which will keep track of…
A: The objective is to solve the given code using struct type.
Q: What are the output from the C++ codes segments below? 1- {int x=10; while(x>5); { cout<<x<<"\n";…
A: The loop statements such as while and for loops run the block of code multiples times until the…
Q: CFG: Example 1 • Draw the CFG for the following code: int f(int n){ } int m = n* n; if (n < 0) else…
A: CFG for the code has been written in step2
Q: 6. {w \ w doesn't contain exactly two a's}.
A: DFA stands for Design a Finite Automata. A language L is accepted by a DFA < Q , , q0 , , A >…
Q: // Program 1 #include using namespace std; int main () { cout using namespace std; int main () {…
A: Here, two programs and first program have single for loop and second program ahe nested for loop.
Q: 2.20 LAB: Hypotenuse Given two numbers that represent the lengths of a right triangle's legs (sides…
A: Introduction: The name "Hypotenuse" in mathematics derives from the Greek word hypoteinousa, which…
Q: Q2: What is the output for the following codes: 1- b) 15 2 d) 15 2 8 int arr[4]= {1,5, 2, 8}; for…
A:
Q: using namespace std; int main(int argc, char *argv[]) { int num; cout >num; if (num%2==0) cout<<"num…
A: #include <iostream> using namespace std; int main(int argc, char* argv[]){ int num;…
Q: #include using namespace std; class test{ public: test(){ cout<<"alpha\n"; } ~test(){…
A: Given: #include <iostream>using namespace std;class…
Q: #include using namespace std; class test{ public: test(){ cout<<"
A: Code: #include <iostream>using namespace std;class…
Q: // MichiganCities.cpp - This program prints a message for invalid cities in Michigan. // Input:…
A: You need to check with each and every element in the array of strings and if it equals the input…
Q: 1. Why does little-endian vs. big-endian matter here in this code 2. Describe how pointer casting…
A: Answer: I have given answer in the brief explanation.
Q: #include #include typedef struct Number_struct { int num; } Number; void Swap(Number*…
A: Code: Swap Function void Swap(Number* numPtr1, Number* numPtr2) { int temp = numPtr1->num;…
Q: /*Line 1:*/ doublevalues[6] = {10, 20, 30, 40, 50, 60}; /*Line 2:*/ double* yalptr= values; /*Line…
A: NOTE: - There is error on line 1 the way of declaring and initializing an array is wrong.…
Q: include
A: 1) Computers store data in memory in binary. One thing that is often overlooked is the formatting at…
Q: #include #include int MAX_SIZE = 10; int n = 0; //A counter variable which will keep track of…
A: Task : In the given C code, the output of the code is not correct. The task is to debug the code…
Q: 11.Defining char myString[10]=”IPC144” what is the value of strlen( 1+ myString) 1+…
A: Hey, since multiple questions posted, we will answer first question according to our policy. If you…
Q: KLold T T=T+(K-2)*L T=T-10 T=0 T=T-10 K= 4, 8, 2 L=4, 3, -1 T=T+(K-2)*L
A: Given graph contains lines of codes and the variables present in this are T, K and L. The initial…
Q: #include #include int MAX_SIZE = 10; int n = 0; //A counter variable which will keep track of…
A: the program is given below:-
Q: I cannot get all the inputs to produce the correct ou
A: The question is asking for a brief summary of the provided C code, including its purpose,…
Q: Q1:Find the output of the following code: const int x=3; const int y=2; double a[x]…
A: #include <iostream>using namespace std; int main(){ const int x=3; const int y=2;…
Q: int* p; int a[3] = {1, 2, 3); p = a; What is the value of *(p+2)?
A: We are we are given an array a and a integer pointer variable p. we are asked the value of *(p+2).…
Q: #include using namespace std; int main() { double matrix[4][3]={{2.5,3.2,6.0},{5.5, 7.5,…
A: The problem is based on the basics of 2D arrays in c++ programming language.
Q: Why does little-endian vs. big-endian matter here in this code
A: Answer: Little-endian: The little-endian show is a kind of addressing that alludes to the request…
Q: //I need help debugging the C code below the image is what I was following for directions while…
A: SUMMARY: - Hence, we discussed all the points.
Control structures
Control structures are block of statements that analyze the value of variables and determine the flow of execution based on those values. When a program is running, the CPU executes the code line by line. After sometime, the program reaches the point where it has to make a decision on whether it has to go to another part of the code or repeat execution of certain part of the code. These results affect the flow of the program's code and these are called control structures.
Switch Statement
The switch statement is a key feature that is used by the programmers a lot in the world of programming and coding, as well as in information technology in general. The switch statement is a selection control mechanism that allows the variable value to change the order of the individual statements in the software execution via search.
Step by step
Solved in 4 steps with 3 images
- #include <stdio.h>#include <stdlib.h> int MAX_SIZE = 10;int n = 0; //A counter variable which will keep track of number of elements in arr. void append(int *arr, int element){ if(n == MAX_SIZE) { MAX_SIZE = MAX_SIZE * 2; int *ptr = (int*)malloc(MAX_SIZE * sizeof(int)); //Copy elements of existing array to a new array for(int i=0;i<n;i++) { ptr[i] = arr[i]; } arr = ptr; n++; } arr[n] = element;} int get(int *arr, int index){ return arr[index];}int main(){ int *arr = (int*)malloc(MAX_SIZE * sizeof(int)); n = 10; for(int i=0;i<n;i++) arr[i] = i+1; printf("\nArray size: %d", MAX_SIZE); printf("\nNumber of elements: %d", n); printf("\nArray: "); for(int i=0;i<n;i++) printf("%d ", arr[i]); printf("\n\nAdding an element"); append(arr, 11); printf("\nArray size: %d", MAX_SIZE); printf("\nNumber of elements: %d", n);…1. What is the output of the following code segment: char* s [] = { "NBY", "SDT"}; const char** z = s; const cout << z [1] [1]; cout << cout << a. DSDT b. DTY c. DTBY d. DTS e. *(z [1]+ 2); (*z + 1); None of the above#include <stdio.h>#include <string.h> int findRepeat(char* s){int p , i , j; p = -1; for (i = 0 ; i < strlen(s) ; i++){for (j = i + 1; j < strlen(s); j++){if (s[i] == s[j]){p = i;break;}}if (p != -1)break;}return p;} int main(){char str[] = "Hello World";int pos = findRepeat(str);if (pos == -1)printf("Not found");elseprintf("%c", str[pos]);return 0;}can you please explain this code for me
- #include <iostream>//#include <vector> using namespace std; class Vec {public:Vec() {sz = 0;cap = 1;p_arr = new int[cap];} int size(){return this->sz;}int capacity(){return this->cap;}void reserve( int n ){// TODO:// (0) check the n should be > size, otherwise// ignore this action.if ( n > sz ){// (1) create a new int array which size is n// and get its address//cout << "Adress:"<< &n << endl;int *newarr = new int [n];//cout << "Address: " << newarr << endl; // location // (2) use for loop to copy the old array to the// new arrayfor(int i = 0; i < sz; i++){newarr[i] = p_arr[i];}// (3) update the variable to the new addressthis->cap=n; // (4) delete old arraydelete[] newarr;}}void push_back( int v ){// TODO:if ( sz == cap ){ cap *= 2; reserve(cap);}p_arr[sz++] = v;// complete others}int at(int idx){return this->p_arr[idx];}private://vector<int> arr;int *p_arr;int sz = 0;int cap = 0; }; int main(){Vec v;…#include using namespace std; int find(int arr[], int value, int left, int right) { int midpt = (left+right)/2; if (left > right) return -1; if ( arr[midpt] return midpt; else if (arr[midpt] < value) == value) return else return find(arr,value, left,midpt-1); } void main(void) { int arr[] ={4,5,6,9,11}; cout<Explain the code and how it works: #include <iostream>#include <cmath> using namespace std;double to_kilograms(double n){ return n * 0.453592;}double to_pounds(double n){ return n * 2.20462;}double to_kilograms_ref(double& n){ return n * 0.453592;}double to_pounds_ref(double& n){ return n * 2.20462;}double to_kilograms_ptr(double* n){ return *n * 0.453592;}double to_pounds_ptr(double* n){ return *n * 2.20462;} void display_menu(){ cout << "1.Kilograms to Pounds (pass by value)\n2. Pounds to Kilograms (pass by value)\n3. Kilograms to Pounds (pass by reference)\n4. Pounds to Kilograms (pass by reference)\n5. Kilograms to Pounds (using pointers)\n6. Pounds to Kilograms (using pointers)\nEnter choice\n\n";} void convert(){ int ch; double w; cout << "Enter a menu option: "; cin >> ch; cout << "Enter weight: "; cin >> w; if (ch == 1) cout << "weight in kg is " << to_kilograms(w);…5- int arr[4]= {2, 4, 5, 3); for (int i= 0; i<4; i++) cout<#include <stdio.h>#include <stdlib.h> int MAX_SIZE = 10;int n = 0; //A counter variable which will keep track of number of elements in arr. void append(int *arr, int element){ if(n == MAX_SIZE) { MAX_SIZE = MAX_SIZE * 2; int *ptr = (int*)malloc(MAX_SIZE * sizeof(int)); //Copy elements of existing array to a new array for(int i=0;i<n;i++) { ptr[i] = arr[i]; } arr = ptr; n++; } arr[n] = element;} int get(int *arr, int index){ return arr[index];}int main(){ int *arr = (int*)malloc(MAX_SIZE * sizeof(int)); n = 10; for(int i=0;i<n;i++) arr[i] = i+1; printf("\nArray size: %d", MAX_SIZE); printf("\nNumber of elements: %d", n); printf("\nArray: "); for(int i=0;i<n;i++) printf("%d ", arr[i]); printf("\n\nAdding an element"); append(arr, 11); printf("\nArray size: %d", MAX_SIZE); printf("\nNumber of elements: %d", n);…Given the following declaration : char msg[100] = "Department of Computer Science"; What is printed by: strcpy_s(msg, "University"); int len = strlen(msg); for (int i = len-3; i >0; i--) { msg[i] = 'x'; } cout << msg;#include<iostream>using namespace std;const int rows=10;const int columns=10;int computer_board1[rows][columns];int computer_board2[rows][columns];int player_board[rows][columns];int x,y;void setboard(){for(int i=0;i<rows;i++){for(int j=0;j<columns;j++){computer_board1[i][j]=0;player_board[i][j]=0;}}}void display_computer_board1(){cout<<"Computer's Board"<<endl;cout<<" 0 1 2 3 4 5 6 7 8 9 "<<endl;for(int i=0;i<rows;i++){for(int j=0;j<columns;j++){if(j==0){cout<<i<<" ";}cout<<computer_board1[i][j]<<" "; }cout<<endl;}cout<<endl;}void display_player_board(){cout<<"Your Board"<<endl;cout<<" 0 1 2 3 4 5 6 7 8 9 "<<endl;for(int i=0;i<rows;i++){for(int j=0;j<columns;j++){if(j==0){cout<<i<<" ";}cout<<player_board[i][j]<<" "; } cout<<endl;} }void place_player_ships(){for(int i=1;i<=15;i++){cout<<"Horizontal…#include <stdio.h>#include <string.h>#define SIZE 6struct Cake {char name[50];float price;};int searchChoice(char *choice, struct Cake data[]);void displayChoice(int index, struct Cake data[]);int main() {char choice[50];int index;//Answer for Part (i) – Declare and initialise array stockprintf("What is your choice of cake? ");gets(choice);index = searchChoice(choice, stock);displayChoice(index, stock);return 0;}//Answer for Part (ii) – Function definition for searchChoice//Answer for Part (iii) – Function definition for displayChoice1. Examine the following code segment. What will be printed?If there are any errors indicate the nature of the error. int a[8] ={16, 12, 10, 7, 15, 18, 17, 29}; int *ptr ; ptr = & a[ 5 ] ; for(int i = 0; i<= 4; i = i + 2) cout<<a[i]<<*( ptr + i )<<endl; cout<<” ”<<a[1]<<” ”<<*ptr<<” ”<<*ptr + 2<<” ”<<*(ptr + 3);SEE MORE QUESTIONSRecommended textbooks for youDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSONC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag…Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill EducationDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSONC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag…Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education