Professional Documents
Culture Documents
Source Code
/* This program is used to input two numbers and display them in descending order.
It has been written by Jobin Solomon, Student no 2622588 (LSBU) on 7/03/09.
It was written using Microsoft Visual Studio 2008 Express Edition.
*/
{
int num1,num2; //initialization of required variables.
cout <<"\n Please enter first number"<<endl; //user prompt to enter first variable
cout<<"\n Please enter second number"<<endl; //user prompt to enter second variable
}//End of program.
Output Screen Shots
Question 1 b) In this question I have been asked to comment on the given code's out put.
# include <iostream>
int main ()
{
int a=1, b=1, c ;
if (c = (a-b))
return 0 ;
Answer : Th e if s tat ement w orks o n logic, it w il l execute the code in the con t in u in g
lin e o r s eg men ted code (bracket ed code) provided the boolean express ion in th e
arg u men t o f the if s tat ement re turns a logic valu e of true w hos e numer ica l
eq u iv alen t is 1. If the argumen t is zero than it w il l not exe cute the code con t in u in g
b elo w an d w ill s kip i t. In the above ques tion the argum ent is c = (a- b), in th is
ex p r es s io n w e have us ed the as s ignmen t opera tor ' =' and not th e comp ar is o n
o p er a to r ' =' w hich me ans c w ill be ass ign ed the value of a- b which is zer o . Th is
me an s th e if condi tion is not val id and henc e it s kips the cout s tat ement. H en ce
th is p r o g r am w ill have no outpu t and w ill be a bl ank s creen.
Question 2 a)
Source Code
/* This program is designed to input a name and print out the name in a sentence.
It is been written by Jobin Solomon, Student no 2622588(LSBU) on 7/03/09.
It has been written using Microsoft Visual Studio 2008 Express edition.
*/
Source Code
/* This program is designed to input an integer type number and a float type number and
calculate the total of the two.
It is been written by Jobin Solomon, Student no 2622588(LSBU) on 7/03/09.
It has been written using Microsoft Visual Studio 2008 Express edition.
*/
{
int number1; // Declaring int type variable.
cin>>number1;//inputing integer
cin>>number2;//inputing decimal.
}//End of program
Output screen shots
Question 2 c)
Source Code
/* This program is designed to input any given inches and convert to centimetres
and print result.
It is been written by Jobin Solomon, Student no 2622588(LSBU) on 7/03/09.
It has been written using Microsoft Visual Studio 2008 Express edition.
*/
{
int centimetres, inches;//initializing required variables.
cin>>inches;//inputing inches.
}
Output screen shots
Question 3
Source Code
{
float c=1e-6,xc;//initializing the float variables.
}//End of program.
Output screen shots
Question 4
Source code
{
float mark;//initialization of variable to store mark.
cout << "\n\nPlease enter your test mark to obtain your grade :";//user prompt for marks
cin>>mark;//inputing marks.
}
else
cout << "\nInvalid marks entered \n";//error message for invalid marks
}//End of program
Output screen shots