Hello everyone I need help with the following questions 1Con
Hello everyone I need help with the following questions
1.Consider the following program:
#include <iostream>
 using namespace std;
 void func1();
 void func2();
 int main()
 {
 int num;
cout << \"Enter 1 or 2: \";
 cin >> num;
 cout << endl;
cout << \"Take \";
if (num == 1)
 func1();
 else if (num == 2)
 func2();
 else
 cout << \"Invalid input. You must enter a 1 or 2\" << endl;
 return 0;
 }
void func1()
 {
 cout << \"Programming I.\" <<endl;
 }
void func2()
 {
 cout << \"Programming II.\" <<endl;
 }
What is the output if the input is 1?
What is the output if the input is 2?
What is the output if the input is 3?
What is the output if the input is -1?
2.Consider the following program:
#include <iostream>
 #include <cmath>
 #include<iomanip>
using namespace std;
void traceMe(double x, double y);
int main()
 {
 double one, two;
cout << \"Enter two numbers: \";
 cin >> one >> two;
 cout << endl;
traceMe(one, two);
 traceMe(two, one);
 return 0;
 }
void traceMe(double x, double y)
 {
 double z;
 if (x != 0)
 z = sqrt(y) / x;
 else
 {
 cout << \"Enter a nonzero number: \";
 cin >> x;
 cout << endl;
 z = floor(pow(y, x));
 }
 cout << fixed << showpoint << setprecision(2);
 cout << x << \", \" << y << \", \" << z << endl;
 }
What is the output if the input is 3 625?
What is the output if the input is 24 1024?
What is the output if the input is 0 196?
Solution
What is the output if the input is 1?
output
Take Programming I.
What is the output if the input is 2?
output
Take Programming II.
What is the output if the input is 3?
output
Take Invalid input. You must enter a 1 or 2
What is the output if the input is -1?
output
Take Invalid input. You must enter a 1 or 2
Solution1.cpp
#include <iostream>//header file for inputoutput function
 using namespace std; //it tells the compiler to link std namespace
 void func1(); //functiondeclaration
 void func2();
 int main()
 { //main function
 int num;
cout << \"Enter 1 or 2: \";
 cin >> num; //key board inputting
 cout << endl;
cout << \"Take \";
if (num == 1)
 func1(); //calling function
 else if (num == 2)
 func2(); //calling function
 else
 cout << \"Invalid input. You must enter a 1 or 2\" << endl;
 return 0;
 }
void func1()
 { //function definition
 cout << \"Programming I.\" <<endl;
 }
void func2()
 { //function definition
 cout << \"Programming II.\" <<endl;
 }
output
Enter 1 or 2: 1
Take Programming I.
Enter 1 or 2: 2
Take Programming II.
Enter 1 or 2: 3
Take Invalid input. You must enter a 1 or 2
Enter 1 or 2: -1
Take Invalid input. You must enter a 1 or 2
What is the output if the input is 3 625?
output
Enter two numbers: 3 625
3.00, 625.00, 8.33
625.00, 3.00, 0.00
What is the output if the input is 24 1024?
output
Enter two numbers: 24 1024
24.00, 1024.00, 1.33
1024.00, 24.00, 0.00
What is the output if the input is 0 196?
output
Enter a nonzero number:
Solution2.cpp
#include <iostream>//header file for input output function
 #include <cmath>//header file for math operations
 #include<iomanip>//header for seeting precision
using namespace std;//it tells the compiler to link std namespace
void traceMe(double x, double y);//function declaration
int main()
 { //main function
 double one, two;//variable declaration
cout << \"Enter two numbers: \";
 cin >> one >> two; //key board inputting
 cout << endl;
traceMe(one, two); //calling function
 traceMe(two, one);
 return 0;
 }
void traceMe(double x, double y)
 { //function defintion
 double z;
 if (x != 0)
 z = sqrt(y) / x;
 else
 {
 cout << \"Enter a nonzero number: \";
 cin >> x;
 cout << endl;
 z = floor(pow(y, x));
 }
 cout << fixed << showpoint << setprecision(2);
 cout << x << \", \" << y << \", \" << z << endl;
 }
output
Enter two numbers: 3 625
3.00, 625.00, 8.33
625.00, 3.00, 0.00
Enter two numbers: 24 1024
24.00, 1024.00, 1.33
1024.00, 24.00, 0.00
Enter two numbers: 0 196
Enter a nonzero number: 2
2.00, 196.00, 38416.00
196.00, 0.00, 0.00




