You are on page 1of 4

Question 1

This is a program that prints the message “This is a c ++ program for BITS1A and BBITS1!!”

It also prompts the user to type his/her age. (“Type your Age:”)

It also prompts the user to enter his/her name (“Enter your name”)

After all this it prints out the user`s name and age. Then it prints BYE!

DESCRIPTION OF EVERY LINE

#include<iostream> /*his is a preprocessor directive .it tells the compiler to include the contents of input /output
stream header file in current file. It must be included in by every program that outputs to screen ,or takes input from
the keyboard. */

using namespace std;

int main () /*This the function header. The parenthesis () indicate that main is a program building block called a
function ,the key word ‘ int ‘ indicates that function main returns an integer value.*/

{ //indicates the beginning of the body of the function

string myName; // is a declaration line. This statement declares “variable “of integer “data type “

int a; //is a declaration line. This statement declares “variable “of integer “data type “

cout<<"This is a c++ program for BITS1A and BITS1!!"<<endl; /* it instructs the screen to output the string of
characters between the quotation (“ “).when this statement is executed, it sends ,” This is a c++ program for
BITS1A and BITS1!!” to the std::out, standard output stream object. */

cout<<endl; //this moves the cursor to the new line

cout<<"Type your Age:"; /* it instructs the screen to output the string of characters between the quotation (“
“).when this statement is executed, it sends,”Type your age:”

cout<<endl; //this moves the cursor to the new line

cin>>a;/*this takes the value form the key standard input ,the keyboard, the memory location a is now given a
value of age*/

cout<<"Enter your name:"; it instructs the screen to output the string of characters between the quotation (“
“).when this statement is executed, it sends,” Enter your name:”

cout<<endl; //this moves the cursor to the new line

cin>>myName; ;/*this takes the value form the key standard input ,the keyboard, the memory location myName is
now given a value of user`s name*/

cout<<endl; //this moves the cursor to the new line


cout<<"Hello"<<" "<< myName <<" "<<"you`re"<<" "<<a<<" "<<"years old!!"<<endl; /* it instructs the
screen to output the string of characters between the quotation (“ “),and also the name of the user and the age .when
this statement is executed.

cout<<endl<<endl<<endl<<"BYE"<<endl; /* it instructs the screen to output the string of characters between the
quotation (“ “). This is displayed after the cursor is moved three times down when this statement is executed, it
sends, “BYE”*/

system ("pause");/* This prevents the program from disappearing after the user has entered his/her details. It
program will prompt the user to press any key to continue */

return 0;//this indicates that the program has ended successfully

} // this indicates the end of the body of the function

QUESTION 2

//MAFANTRI SELLO 901002287

//QUESTION 2,C++ TUTORIAL 1

#include<iostream>//This is a processor directive

using namespace std;// This allows us to easily access c++ built-in resources such as input and output

int main ()//This the main function .it is the function header.

{// This is the begging of the main function

string name, surname, passportNumber ;//is a declaration line. This statement declares "variables "of string "data
type

int dateOfbirth,age;//is a declaration line. This statement declares "variables "of integer "data type

const int currentYear= 2010;/*is a declaration line. This statement declares "variable "of cosntant integer "data
type

and initializes it the value 2010*/

cout<<"Please Enter your name:"<<endl;//it prompts the user for an input

cin>>name;/*This takes the input form the key standard input ,the keyboard,

and the memory location name is now given a value of user`s name*/

cout<<"Please Enter your surname:"<<endl;//it prompts the user for an input

cin>>surname;/*This takes the input form the key standard input ,the keyboard,

and the memory location surname is now given a value of user`s surname*/
cout<<"Please Enter your passport number:"<<endl;//it prompts the user for an input

cin>>passportNumber;/*This takes the input form the key standard input ,the keyboard,

and the memory location passportNumber is now given a value of user`s passportNumber*/

cout<<"Please Enter your date of birth:" <<endl;//it prompts the user for an input

cin>>dateOfbirth;/*This takes the input form the key standard input ,the keyboard,

and the memory location dateOfbirth is now given a value of user`s dateOfbirth*/

age = currentYear - dateOfbirth;/*This statement subtracts the value of currentYear form dateOfbirth

and assigns the result to age.*/

cout<<"Your surname is "<<surname<<" ,then your name is "<<name<<" and you are "<<age<<" years
old!!"<<endl;/*This statement displays

whatever is inside the quotation marks and prints them on screen. it also print out whatever is inside the memry
location surname, name

and age respectively in order*/

system ("pause");/* This prevents the program from disappearing after the user has entered his/her details.

The program will prompt the user to press any key to continue */

return 0;//this indicates that the program has ended successfully

}//This indicates the end of the body of the function

QUESTION 3

//MAFANTRI SELLO 901002287

//QUESTION 3,C++ TUTORIAL 1

#include<iostream>//This is a processor directive

using namespace std;// This allows us to easily access c++ biult-in resources such as input and output

int main ()//This the main function .it is the function header.

{// This is the begginig of the main function

int number1,number2;//is a declaration line. This statement declares "variables "of integer "data type

cout<<"Please Enter the first number :"<<endl;//it prompts the user for an input

cin>>number1;/*This takes the input form the key standard input ,the keyboard,

and the memory location number is now given a value of number the user entered*/

cout<<"Please Enter the second number:"<<endl;//it prompts the user for an input
cin>>number2;/*This takes the input form the key standard input ,the keyboard,

and the memory location number2 is now given a value of the second number entered by the user*/

if (number1<number2){//compares two numbers, where there number1 is less than number2

cout<<"The second number is greater than the first number!"<<endl;}

//prints the the statement inside the quotation marks on screen

else if (number1>number2){//compares two numbers where there number1 is greater than number2

cout<<"The first number is greater than the second number!"<<endl;}

// prints the the statement inside the quotation marks on screen

else if (number1==number2){//compares two numbers, where there number1 is equal to number2

cout<<"The two numbers are equal"<<endl;}// prints the statement inside the quotation marks
on screen

system ("pause");/* This prevents the program from disappearing after the user has entered his/her details.

The program will prompt the user to press any key to continue */

return 0;//this indicates that the program has ended successfully

}//This indicates the end of the body of the function

You might also like