cout<<”Inside function g”<<endl;
int h(void)
{
cout<<”Inside function h”<<endl;
}
}
int result;
result = x+y;
}
{
float a;
cout<<a<<endl;
}
a)
int g(void) //it is possible to passan argument as void. Which means the function does not wants to
//pass any argument.
{
cout<<"inside g" //it is also correct
//next statement is the error. It is not possible to define a function within a function like this. If you
//want to define you should call the function before function definition.
}
corrected code
int g(void)
{
int x;
cout<<"inside function g"<<endln;
x=h();
int h(void)
{
cout<<"inside function h"<<endln;
return;
}
return;
}
b) int sum(int x,int y) //integer return type
{
int result;
result=x+y;
}
Note that the function defined with integer return type. So must return an integer value. But it is not provided here.Corrected code
int sum(int x,int y)
{
int result;
result=x+y;
return result;
}
C) void f(double a)
{
float a;
cout<<a<<endln;
}
There is a semicolon at the end of function definition.It should be avoid.Here the function declares a as double in definition. But it also declare the same variable 'a'as float in function definition. So the compiler feels a confusion it is double or float. So the error.
Corrected code
void f(double a)
{
cout<<a<<endln;
}
Find the error in each of the following c++ program segments and explain how the error...
/* • The following code consists of 5 parts. • Find the errors for each part and fix them. • Explain the errors using comments on top of each part. */ #include <stdio.h> #include <string.h> int main( ) { ////////////////////////////////////////////////////////////////////////// ////////////// Part A. (5 points) ////////////////// int g(void) { printf("%s", Inside function g\ n " ); int h(void) { printf(" % s ", Inside function h\ n "); } } printf("Part A: \n "); g(); printf(" \n"); ////////////////////////////////////////////////////////////////////////// ////////////// ...
Find the five problems with this program. Do not change the functionality or rewrite the program. #include <iostream> void multiply(int x = 1, int y); int main() { int length, width, area; cout << "Enter length and width of a rectangle "; cin >> length, width; area = multiply(length, width); cout << "The area is " << area << endl; area2 = multiply(width); cout << "The second area is " << area2 << endl; return 0; } void multiply(int x=...
Examine each of the following program segments carefully. Determine what is printed from each program. There are no intentional errors. 1. int array[] = {1, 2, 3, 4, 5}; for (int i = 0; i < 5; i++) cout << array[i]*5 << “ “; Output _________________________________ 2. int *iptr; iptr = new int[5]; for (int count = 0; count < 5; count++) iptr[count] = count+1; cout << *iptr << endl; Output _________________________________ 3. int x = 50, y = 60,...
81. The following function call doesn’t agree with its prototype: cout << BoxVolume( 10, 5 ); int BoxVolume(int length = {1}, int width = {1}, int height = {1}); T__ F__ 82. The following function is implemented to swap in memory the argument-values passed to it: void swap(int a, int b) { int temp; temp = a; a = b; b = temp; ...
I know the right answers by using a compiler. However, can you please explain each step and how you get the correct answer. Thank you in advance. Output: E = 1 F = 7 G = 11 H = 14 W = 5 X = 6 Problem 7 #include <iostream> #include <cmath> using namespace std; void F1(int,int,int,int&); void F2(int,int&,int&,int&); int main ( void ) { int E=1,F=2,G=3,H=4,W=5,X=6; F1(E,F,G,H); F2(E,F,G,H); cout << "E = " << E <<...
howthe output of the following 4 program segments (a) const int SIZE=8; int values[SIZE] = {10, 10, 14, 16, 6, 25, 5, 8}; int index; index=0; res = values[index]; for (int j=1; j<SIZE; j++) { if (values[j] > res) { res = values[j]; index = j; cout << index << res << endl; } } cout <<...
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; ...
C++ Language I have a class named movie which allows a movie object to take the name, movie and rating of a movie that the user inputs. Everything works fine but when the user enters a space in the movie's name, the next function that is called loops infinetly. I can't find the source of the problem. Down below are my .cpp and .h file for the program. #include <iostream> #include "movie.h" using namespace std; movie::movie() { movieName = "Not...
Three of these function overloads are considered identical by the compiler and would conflict with each other. The other would be considered different- choose the one that is considered different from others. Int foo ( int x, double y ) ; Int foo ( double x, int y ) ; Void foo ( int x, double y ) ; Int foo ( int day, double temp ) ; Consider the following incomplete code: Int f ( int number ) }...
Explain specifically what error. You may assume all includes are done properly, the code is inside a valid function, assume "srand(time(0)):" has been set int x[5]; int sum; for(int 1-0 ; i <= 5; i++); x[i] sum = rand ( ) %100 ; x[i]; cout < "Sum is: "<<sum << endl;