Correction of Programming Errors in C++, Lecture notes of Computer Programming

The correction of programming errors in c++ for various functions such as square and maximum. Each question includes the incorrect code, the corrected code, and the explanation of the error.

Typology: Lecture notes

2012/2013

Uploaded on 04/27/2013

kid
kid ๐Ÿ‡ฎ๐Ÿ‡ณ

4.3

(18)

110 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Please find the program errors and correct them.
Question 1
# include <iostream>
using std::cout;
int square ( int);
int main ( )
{ for ( int x =1; x <=10; x++)
cout << square(x) << โ€œ โ€œ;
return(0);
}
void square( int y)
{
return y*y;
}
Question 2
int maximum ( int, int, int); //function prototype
โ€ฆ..
cout << maximum (a, b, c); // calling function
โ€ฆโ€ฆ
int maximum (int x, y, z) // function definition
{
int max =x;
if (y> max) max =y;
if (z > max) max = z;
return max
}
Question 3
# include <iostream>
pf3
pf4

Partial preview of the text

Download Correction of Programming Errors in C++ and more Lecture notes Computer Programming in PDF only on Docsity!

Please find the program errors and correct them. Question 1

include

using std::cout; int square ( int); int main ( ) { for ( int x =1; x <=10; x++) cout << square(x) << โ€œ โ€œ; return(0); } void square( int y) { return y*y; } Question 2 int maximum ( int, int, int); //function prototype โ€ฆ.. cout << maximum (a, b, c); // calling function โ€ฆโ€ฆ int maximum (int x, y, z) // function definition { int max =x; if (y> max) max =y; if (z > max) max = z; return max } Question 3

int square ( int); int main ( ) { for ( int x =1; x <=10; x++) cout << square(x) << โ€œ โ€œ; return(0); } int square( int y); { return y*y; } Question 4

include

using std::cout; int square ( int); int main ( ) { for ( int x =1; x <=10; x++) cout << square(x) << โ€œ โ€œ; return(0); } int square( int y) { int y; return y*y; } Question 5

int square ( float); int main ( ) { for ( int x =1; x <=10; x++) cout << square(x) << โ€œ โ€œ; return(0); } int square( int y) { return y*y; } Question 8

include

using std::cout; int square ( int) int main ( ) { for ( int x =1; x <=10; x++) cout << square(x) << โ€œ โ€œ; return(0); } int square( int y) { return y*y; }