C++
1.
A?B?C?D? which one is correct
2.
3A, 3B
Question 1: swap3 is correct. Option D Question 2: Question 3: Question 4:
C++ 1. A?B?C?D? which one is correct 2. 3A, 3B #include<iostream> using namespace std; void swap0(int*...
#include <iostream> using namespace std; struct node { int base=0; int power=0; }; void insert(node ptr[],int basee,int powerr) { ptr[powerr].power=powerr; ptr[powerr].base=basee; } void subtract(node ptr1[],int size1,node ptr2[],int size2,node ptr3[]) { for(int j=0;j<=size1;j++) { if(ptr1[j].base!=0) { ptr3[j].base=(ptr3[j].base)+(ptr1[j].base); ptr3[j].power=ptr2[j].power; } } for(int j=0;j<=size2;j++) { if(ptr2[j].base!=0) { ptr3[j].base=(ptr3[j].base)-(ptr2[j].base); ptr3[j].power=ptr2[j].power; } } } void addition(node ptr1[],int size1,node ptr2[],int size2,node ptr3[]) { for(int j=0;j<=size1;j++) { if(ptr1[j].base!=0) { ptr3[j].base=(ptr3[j].base)+(ptr1[j].base); ptr3[j].power=ptr2[j].power; } } for(int j=0;j<=size2;j++) { if(ptr2[j].base!=0) { ptr3[j].base=(ptr3[j].base)+(ptr2[j].base); ptr3[j].power=ptr2[j].power; } } } void display(node ptr[],int size)...
Please help me debug the following code #include int main(void){ int a = 11, b = 5; int *ptr1 = &a, *ptr2 = &b; printf("%d %d\n", *ptr1, *ptr2); swap(&ptr1, &ptr2); printf("%d %d\n", *ptr1, *ptr2); minimum(ptr1, ptr2); printf("%d %d\n", a, b); return 0; } // Part A void swap(int **ptr1, int **ptr2){ int *temp = *ptr1; *ptr1 = *ptr2; *ptr2 = temp; return; } // Part B void minimum(int *ptr1, int *ptr2){ if(*ptr1 > *ptr2){ *ptr1 = *ptr2; }else{ *ptr2 =...
Explain the results 푤include <iostream> using nanespace std: int nain (O rloat arr[s- (12.5,.11.0, 13.8, 1000.5, 1.5): float ptri-arEIo1: float *ptr2"ptri +3: cout<< +ptr2xcend *ptr2-* (ptr2)+1: //Line 16 cout<< ptr2<<endl: return 0; Bxplaing the results. 5 What Happens if the Line 16 is replaced by *ptr2- (ptr2+1): 6. tincludekiostream> using namespace std: void fun (int arr(I) int for air size = arestizer) isizeor (arr10]); for (i=0;遠くarr size: i++) int main(0 int int array 114](10, 20 30, 401 fun (array 1):...
#include <iostream> using namespace std; int main(void) { int SIZE; cout<<"Enter the size of the array"<<endl; cin>>SIZE; int *numlist = new int[SIZE]; // Read SIZE integers from the keyboard for (int i = 0; i<SIZE; i++ ) { cout << "Enter value #" << i+1 << ": "; cin >> numlist[i]; } // Display the numbers in a reverse order for (int i = SIZE; i > 0; i--...
#include <iostream> using namespace std; struct node { int base; int power; }; void insert(node ptr[],int basee,int powerr) { ptr[powerr].power=powerr; ptr[powerr].base=basee; } void addition(node ptr1[],int size1,node ptr2[],int size2,node ptr3[],int size3) { for(int j=0;j<=size1;j++) { ptr3[j].base=ptr3[j].base+ptr1[j].base; } for(int j=0;j<=size2;j++) { ptr3[j].base=ptr3[j].base+ptr2[j].base; } } void display(node ptr[],int size) { if(ptr[0].base!=0) cout<<ptr[0].base<<"+"; for(int i=1; i<=size; i++) { if(ptr[i].base!=0) cout<<ptr[i].base<<"x^"<<ptr[i].power<<"+"; } } int main() { bool choice1=true; bool choice2=true; int size1,size2,base1,base2,power1,power2; cout<<"enter the max power in polynominal 1"; cin>>size1; node *a= new node[size1+1]; for(int...
what is the output for the following code? explain the steps. /*#include <iostream> using namespace std; int f(int &i) { i = 10; return(5 * i); } int main() { int n = 5; f(n); cout << n << "\n"; return 0; } #include <iostream> using namespace std; int sub1(int n) { n--; return n; } int main() { int m = 10; for(int j = 0; j < 10; j++) m -= sub1(j); cout << m << "\n"; return...
What is the difference between these two programs? #include <iostream> using namespace std; int DontPanic(int & x); int z = 10; void main() { char x = 'y'; int y = 5; int z = 100; y = DontPanic(z); cout << x << " " << y << " " << z << endl; } int DontPanic(int & x) { int * p; p = & z; x = (*p)++ + 1; cout << x << " " << *p...
Consider the following C++ program: #include <iostream> using namespace std; void f1(int); void f2(int); void f3(int); int main() { f1(10); return 0; } void f1(int n) { f2(n + 5); } void f2(int n) { f3(n - 2); } void f3(int n) { cout << n << endl; // LINE 1 } Just before the program statement marked with the comment "LINE 1" is executed, how many stack frames will be on the program call stack?
#include <iostream> using namespace std; const int SIZE = 10; void displayGreaterThan(int[], int); void displaySmallerThan(int[],int); void displayArrayContent(int[]); void displayLargestValue(int[]); void displaySmallestValue(int[]); int main(){ int number; int numbers[SIZE] = {9,1,90,98,53,22,76,29,37,65}; cout <<"Enter a number: "; cin >> number; cout << endl; displayGreaterThan(numbers,number); cout << endl; displaySmallerThan(numbers,number); cout << endl; displayArrayContent(numbers); cout << endl; displayLargestValue(numbers); cout << endl; displaySmallestValue(numbers); cout << endl; return 0; } void displayGreaterThan(int value[],int num){ cout << " All larger value(s)than" <<...
C++ question #include <iostream> using namespace std; void printReverse(int); int main() { int number = 12345; cout << "Original : " << number << endl; cout << "Reversed : "; printReverse(number); } void printReverse(int x) { if (x == 0) return; cout << x % 10; printReverse(x /= 10); } Modify the above recursive program to output the number in the same order. Note that the program still should break up the number and then output it in the...