Professional Documents
Culture Documents
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!
#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. */
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.*/
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<<"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:”
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:”
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<<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 */
QUESTION 2
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.
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
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*/
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
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
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 */
QUESTION 3
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.
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*/
else if (number1>number2){//compares two numbers where there number1 is greater than 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 */