Lab Task 3.2 (use of cout function)

Ahmed Yasin
3 min readJun 21, 2020

--

Well here i am. Yesterday i started series in which i started program making. Today i am gonna tell you that how i solved task 3.2 and tell you solution in detail. In a previous task we draw some shape in output by using cout. In this task(3.2) we are also going to print something on the screen by using cout function. It is really easy just make sure to show your interest in understanding me. First we need to understand the statement of task 3.2.

If you want me to make video on this task than link in given below and go and watch how i solved this problem.

https://youtu.be/ORm83Q_IAXY

Write a program that will show the following output using cout statement :

figure 1.1

We need to print bold written statements on the screen.Let see how can we do that but first i shortly tell you the what is cout function. if you are familiar with C language than you probably know about printf (print function). What printf actual used for?. Printing anything on the screen right ?. Yes right. In C++ cout performs exactly the same job as printf. Now you all know what is cout function. Lets solve task know. As i told you in task 3.1 that first i solved each task and than share it here. So ,I have already solved it and i am gonna share my code here.

#include <iostream>
using namespace std;
int main ()
{
cout <<”************************************\n”;
cout <<”** INTRODUCTION TO COMPUTER **\n”;
cout <<”** Language C++ **\n”;
cout <<”** VISUAL C++ **\n”;
cout <<”************************************\n”;
return 0;
}

Lets understand this code. In figure 1.1 we can clearly see that what output the demand so according to that. I coded this code.

#include <iostream>
using namespace std;

It is the predefined library function used for input and output also called as header files. iostream is the header file which contains all the functions of program like cout, cin etc.

int main ()

It is the main function. You call other functions in main function just to show you output on the screen otherwise you can’t show any output on the screen and maybe you face an error.

{

}

These are the opening and closing brackets of main function. All code written between them i called body of main function.

cout <<”************************************\n”;
cout <<”** INTRODUCTION TO COMPUTER **\n”;
cout <<”** Language C++ **\n”;
cout <<”** VISUAL C++ **\n”;
cout <<”************************************\n”;

The cout function can not work without this ‘<<’ sign and than this “ ”. Whatever you want to print on the screen you need to write that between these semicolon “ ”. I told ready told you what \n do. This is keyword to jump on other line. So when you run this program this will automatically jump on second line where you added \n keyword.

--

--