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 0;
}
#include <iostream>
using namespace std;
int myfunc(double);
int myfunc(float);
int main()
{
cout << myfunc(3.6) << "\n";
return 0;
}
int myfunc(double n)
{
return n * 2.0;
}
#include <iostream>
using namespace std;
int main()
{
int i = 1;
double x = 1.111;
cout << i << " " << x << "\n";
{
int x = 2;
double i = 2.222;
cout << i << " " << x << "\n";
}
return 0;
}
#include <iostream>
using namespace std;
int sum(int pt[], int n)
{
int temp = 0;
for (int i = 0; i < n; ++i)
{
temp += pt[i];
}
return temp;
}
int main()
{int i;
int total;
int pt[5];
for ( i = 0; i < 5; i++)
pt[i] = i;
total = sum(pt, 3);
cout << total << " " << i << endl;
return 0;
}
#include <iostream>
using namespace std;
int func ( string plant5, char plant4[])
{
for (char &x: plant5)
cin >> x;
}
int main()
{
char plant1[] = "Tree";
char plant2[] = {'T','R','E','E'};
cout << "i " << plant2[50] << endl;
char plant3[80] = "Tree";
char plant4[] = {'T','R','E','E','\0'};
string plant5 = "Tree";
cout << "i " << plant5[2];
func(plant5,plant4);
for (char x: plant5)
cout << x;
return 0;
}
*/
#include <iostream>
using namespace std;
double triangle(double base , double height = 10.0 ); //right
//double triangle(double base = 10.0, double height ); //wrong
int main()
{
cout << triangle(10.0) << "\n";
return 0;
}
double triangle(double base, double height)
{
return 0.5*base*height;
}
/*
#include <iostream>
using namespace std;
void what( int &a) // add const before int to fix the syntax error
{
cout << a;
}
int main()
{
const int whatVar = 1;
int b = 100;
what(whatVar);
cout << whatVar << " " << b;
}
I will a syntax error because if I pass a const
variable to a function I must add the const on the
function header.
*/
Dear Student ,
As per the requirement submitted above , kindly find the below solution.
Question 1:
Output :
Explanation :
*********************************
Question 2:
Output :
Explanation :
*********************************
Question 3:
Output :
Explanation :
*********************************
Question 4:
Output :
*********************************
Question 5:
Output :
*********************************
Question :
Output :
**************************
Question :
Output :
******************************
Question :
Output :
NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.
what is the output for the following code? explain the steps. /*#include <iostream> using namespace std;...
Thanks in advance: // File: main.cpp #include <iostream> #include <fstream> #include <iomanip> using namespace std; int recursiveCount = 0; void triangle(const char drawChar, const int maxHeight, const int currentHeight); int main() { char drawChar = '*'; recursiveCount = 0; cout.fill(drawChar); triangle(drawChar, 5, 1); cout.fill(' '); return 0; }// end main() void triangle(const char drawChar, const int maxHeight, const int currentHeight) { /* DO NOT edit code */ cout.fill(drawChar); recursiveCount += 1; /* END of do not edit */ /*...
Question 1: Fix the 2D dynamic array initialization in following code #include <iostream> using namespace std; int main(){ int rows = 5; int cols = 5; int x; int** arr = new int[rows][cols] cin >> x; arr[x][x] = x; cout << "arr[x][x] = " << arr[x][x]; return 0; } Question 2: Fix the code to initialize the 2D array elements to x #include <iostream> using namespace std; int main(){ int rows; int cols; int x;...
One dimensional array What this code print #include <iostream> using namespace std; int main () { const int SIZE = 7; int numbers [SIZE] = {1, 2, 4, 8): // Initialize first 4 elements cout << Here are the contents of the array:\n"; for (int index = 0; index < SIZE: index++} cout << numbers[index] << ; cout << endl; return 0; }
#include <iostream> #include <vector> #include <iomanip> using namespace std; int main() { const int NUM_ITEMS = 8; vector <double> inverse(NUM_ITEMS); int j; double temp; for (int i = 0; i < NUM_ITEMS; i++) { inverse.at(i) = 1 / (i + 1.0); } cout << fixed << setprecision(2); cout << "Original vector..." << endl; for (int i = 0; i < NUM_ITEMS; i++) { cout << inverse.at(i) << " "; } cout << endl; cout << "Reversed vector..." << endl; for...
//countingAnimals.cpp C++ #include <iostream> #include "Animal.h" using namespace std; int Animal::count = 0; int main(int argc, const char * argv[]) { Animal myAnimal; Animal anotherAnimal; cout << Animal::count << endl; return 0; }
* The output of the following code is #include <iostream> using namespace std: int prod (int x, int y=3){ int d; int a=x*y; return (a); int main ({ cout << prod (7) <<" "<<prod (6, 4); return 0; 21 12 O 49 24 O 21 24 O 21 18
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...
im not sure why my code isnt working? include <iostream> #include <iomanip> using namespace std; int main() { int amountOfCoffee; double Price; char salesTaxChargeability; double TotalAmount; const double SALESTAX = 0.035; // 3.5 % cout << "\nEnter the number of pounds of coffee ordered in Pounds :"; cin >> amountOfCoffee; cout << "\nEnter the price of coffee per Pound :"; cin >> Price; cout << "\nIs sales tax Chargeable (y or n): "; cin >> salesTaxChargeability; if ( (salesTaxChargeability ==...
4) What is the output if the input istom - Sawyer? #include <iostream> using namespace std; int main() { string playerName; cout << "Enter name"; cin >> playerName; cout << endl « playerName; return 0; } a. Tom - Sawyer b. Tom Sawyer c. Tom d. Sawyer 5) Which XXX generates "Adam is 30 years old." as the output? #include <iostream> using namespace std; int main() { string name = "Adam"; int age = 30; XXX return 0; } a....
Find Output. Just output. No explanation needed.. #include <iostream> #include <string> using namespace std; class baseClass { public: void print() const; baseClass(string s = " ", int a = 0); //Postcondition: str = s; x = a; protected: int x; private: string str; }; class derivedClass: public baseClass { public: void print() const; derivedClass(string s = "", int a = 0, int b = 0); //Postcondition: str = s; x = a; y = b; private: int y; }; int...