Question
Need help with these C++ problems: Part I: What is output by the following? Assume the necessary header files are included. 1 . int funct_1(int,
Need help with these C++ problems:
Part I:
What is output by the following? Assume the necessary header files are included.
1. int funct_1(int, int);
int main() {
int num1=2, val;
val = funct_1(8, num1) + funct_1(num1, 4);
cout << val;
return 0;
}
int funct_1(int x, int y) {
return x + y;
}
2. void dostuff(int cnt, int extra);
void main(void) {
int a=3, b=2;
dostuff(a, b);
dostuff(2, 4);
}
void dostuff(int cnt, int extra) {
int i;
for(i=0; i<=cnt; i++) {
cout << i + extra << " ";
}
cout << endl;
}
3. int funct_1(int, int);
void main(void) {
int num1=2, val;
val = funct_1(8, funct_1(num1, 5) );
cout << val << endl;
cout << funct_1(val, num1);
}
int funct_1(int x, int y) {
int temp;
temp = x + y + 3;
return temp;
}
4. int dostuff(int cnt);
void main(void) {
int a=3, c;
c = dostuff(a);
cout << c << endl;
cout << dostuff(4);
}
int dostuff(int cnt) {
int i, sum=0;
for(i=0; i<=cnt; i++)
sum += i;
return sum;
}
5. void userInOut(int);
void main(void) {
int cnt=3;
userInOut(cnt);
}
void userInOut(int cnt) {
int num, sum=0;
for(int i=1; i<=cnt; i++) {
cout << "Enter a number: "; // assume user enters 2, 14, -5
cin >> num;
sum += num;
}
cout << "Sum is " << sum;
}
6. float userIn(int);
void main(void) {
int cnt=2;
float avg;
avg = userIn(cnt);
cout << avg;
}
float userIn(int count) {
int num, sum=0;
for(int i=1; i<=count; i++) {
cout << "Enter a number: "; // assume user enters 6, 7
cin >> num;
sum += num;
}
return static_cast
}
7. int reference(int, int, int &);
void main(void) {
int x=5, y=6, z=3;
x = reference(4, y, z);
cout << x << ", " << y << ", " << z;
}
int reference(int x, int y, int &c) {
c = x + y;
return y;
}
8. void funct_stat(int);
int main(void) {
funct_stat(2);
funct_stat(3);
}
void funct_stat(int x) {
static int num = 2;
num = num + x;
cout << num << ", ";
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started