HW2 - program I have mentioned it in the main so that it is...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
1. This program would not compile , this program will compile if the code is changed to the following and the changes are explained below: #include <iostream> #include <ostream> #include <sstream> #include <iomanip> #include <string> #include <math.h> using namespace std; int main() { double x = 3.45; double y = x / 2; double z=0; char ch = 'a' + 'b'; if (x = y){ z = y++; } else{ z = y++; } cout<<z << "***" << sqrt(z) <<endl; } a. The variable ‘x’ in the original program is defined as an integer but actually is a double , b. ‘y’ is defined as ‘w’ instead of mentioning as ‘y’. c. ‘z’ was defined separately in the ‘if’ and the ‘else’ , instead in the changed
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: program I have mentioned it in the main so that it is used in the whole program. d. The math.h library was not declared at the start of the program to use the method ‘sqrt’ e. The code now compiles and outputs the following result : 1.725***1.31339 2. None of the statements will result in a run-time error. a. Const int X_SIZE = 10; compiles and does not return any error b. int x[X_SIZE]; returns an error ‘ X_SIZE’ was not declared in this scope c. x[X_SIZE] = 5; returns an error that ‘x’ and X_SIZE were not declared d. x[X_SIZE-1] = -95; returns an error that ‘x’ and X_SIZE were not declared...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online