Programming and Graphics

(Kiana) #1

46 Introduction to C++ Programming and Graphics


The output of the code is:


6
peace on earth

The firstcoutstatement prints the variablecon the screen using thecout
function of the internal iostream library, and then moves the cursor to a new
line instructed by theendldirective, as will be discussed in Chapter 3. The
secondcoutstatement performs a similar task.


Problems


2.8.1.Write a program that prints on the screen the name of a person that
you most admire.


2.8.2.Investigate whether the following statement is permissible:


cout << int a=3;

2.8.3.Run the following program. Report and discuss the output.


#include<iostream>
using namespace std;

int main()
{
bool honest = true;
cout << honest << "\n";
cout << !honest << "\n";
return 0;
}

2.8.4.What is the output of the following program?


#include <iostream>
using namespace std;

int main()
{
string firstname;
string lastname;
firstname = "Mother";
lastname = "Theresa";
string name = firstname+""+lastname;
cout << name << endl;
}
Free download pdf