// I fixed all the error with message
QUESTION (a):-
#include <iostream>
int sumOfPositive(int a,int b);
int main() {
std::cout<<sumOfPositive(35,3); // extra , was in function
call
return 0;
}
int sumOfPositive(int a,int b)
{
int sum=0;
if(a>0)
sum+=a;
if(b>0)
sum+=b;
return sum; // return statement was missing
}
QUESTION (b):-
#include <iostream>
int square(int number); /// function prototype was missing
int main() {
std::cout<<square(35);return 0;
}
int square(int number){return number*number;}
Use C++ 1. Explain how you would correct errors in the following program to it do...
C++ What will be the output of the following program? (Use _ to represent spaces.) #include <iostream> using namespace std; int main () { int i = 0; int firstNum = 1; int secondNum = 1; const int max = 10; int sum = 0; cout << firstNum << “ “; do { cout << secondNum << “ “; secondNum += firstNum; firstNum = secondNum; i++; } while (i <= max); cout << secondNum << “ “; return 0; }
Find two syntax errors in the following program: #include <iostream> using namespace std; int area(int length, int width = 0); int main() { int length, width; // for rectangle use both arguments cout << "Enter length and width of a rectangle" << endl; cin >> length >> width; cout << "The area is " << area(length, width) << endl; // for square, only need first argument cout << "Enter side of a square" << endl; cin >> length; cout <<...
Can someone explain how this C++ program runs? A line by line explanation/commentation would be great, as well as the purpose of the program and functions/classes involved. #include <iostream> #include <vector> using namespace std; // template function vector<int> removeEvenIndexedVals(vector<int> vec); // main int main() { static const int arr[] = { 2,5,7,9,1,3,6 }; vector<int> vec(arr, arr + sizeof(arr) / sizeof(arr[0])); // call function vec = removeEvenIndexedVals(vec); // print cout << "Displaying the Vector Elements:"...
Fix all syntax and logical errors for the following program. Please generate the correct output. // Program Typos prints three integer numbers, sums the numbers, calculates // the average, and prints the sum and the average of the three numbers. #Include #Include using namespace std; const ONE = 5; const TWO = 6; const THREE = 7; int Main () int sum; float average; cout << fixed << showpoint; c0ut << SetW(5) << ONE << TWO << THREE << end1;...
C++ Fix the errors in the following code. (Not all errors are syntax related) #include <iostream> using namespace std; int main() { //Part A int numA numA = 10; cout << numA << end; /* Part B */*/ int numB = numA; cin >> usrInput; int usrInput = 0; numB = numB + usrInput; cout << numB <"/n"; /* Part C */ int numC = 10000000000; cout << numC << endl; return 0; }
Give the output of the following C++ program and explain your reasoning: #include <iostream> using namespace std; int gcd( int , int ); //Function prototype int main() { int a = 105; int b = 30; cout << “The GCD of “ << a << “ and “ << b << “ is “ << gcd(a,b) << endl; return 0; } int gcd(int a, int b) { if ( b == 0 ) return a; else return gcd(b,a%b); }
C++ problem. Please just find and fix the errors and highlight it afterwards. Do not add any new comments or remove comments from teachers. Thank you very much *R 2B PROGRAM 1B: INSERTION SORT Find and rix errors. Ron the program once and save the outpat as a conment at the end of the source file Changed by: IDE #include <iostream> using namespace std: void insertionSort (int aryll, int size) int main double list(1001-(50.1, 30.2, 80.3, 10.5, 30.2, 40.9, 90.8,...
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...
61. The following program is accepted by the compiler: int sum( int x, int y ) { int result; result = x + y; } T__ F__ 62. The following implementation is accepted by the compiler: void product() { int a; int b; int c; int result; cout << "Enter three integers: "; cin >> a >> b >> c; result = a * b * c; ...
1. What is wrong with the following C++ program? #include <iostream> int main() { a = 4; b = 6; cout << a << "+" << b << "=" << a+b; return 0; 2. What is wrong with the following C++ program? What was its intended output? #include <iostream> using namespace std; int main() { cout << "What is larger? e pi or pi e?" << endl; double ans1 = exp(pi); double ans2 = pi exp(1.); cout << "epi is...