C++ exercise

C++ Basic Syntax

Ahmed Yasin
3 min readJun 24, 2020

Well I am going to solve problem no. 3.3 and 3.4. I am going to explain you the best as much as I can. So, these two task are really simple but first i remind you about cout function. cout is a function in C++ language which prints anything on the screen as output. I have already told you about it in my previous tutorial.

If you guys want to watch tutorials than you can watch them on the Youtube. The link is given below.

Part 1 : https://youtu.be/MNIipLdKZVE

Part 2:https://www.youtube.com/watch?v=o_rYRE1MVWE

Now lets begin with reading and understanding the statement of task 3.3.

figure 3.3

As we can clearly see that we have to print the pattern which is given in figure 3.3.

Note : You just need to remember the pattern and than try to print that with cout statement.

Step One :

You always start with including header file as i have shown below .

#include <iostream>

using namespace std;

Step Two :

You need to make a function (main function). Main function is a function in which other function we call. This is a reason we use mostly main function at the end but for now we do not need to make other function because we can print that pattern with in main function body.

int main()

{

}

where int is the type of function. Int means integer type.

Step Three :

Last but not least we have to write code between {} brackets. Code is given below in the picture.

I this code you can see I just simple use cout functions and made pattern by using space and asterisk signs. I have already told you about what \n do. \n is keyword which is use to jump on next line.

Task 3.4

Honestly this one is so easier than you imagine but first I have to tell you some keywords before I show you the statement of this task.

If you have read my previous stories than you all must be familiar with \n and \t keyword. I just tell you \n is use to jump on next time and \t is use to make tab space between any string. There are many keywords but right now we only need to use these two. So, lets read and understand the statement of task 3.4.

Note : I am using word understanding before starting any task. This is because understanding problems is a skill and this is every important in any field so improve this skill as much as you can.

Figure 3.4

First two steps are exactly same like task 3.3. First you have to mention header file and than make main function after these two steps you i can start writing code. We just need to print line.

Code :

you can see i used cout function and than write This and than put \t. I used \t to put tab-space between ‘This’ and ‘a’ and so on..

Sign up to discover human stories that deepen your understanding of the world.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Ahmed Yasin
Ahmed Yasin

Written by Ahmed Yasin

Youtuber / Content Writer / C++ /Learning Java/ https://www.youtube.com/channel/UC-gDcN99rYbeyH1oKsoPM3A Instagram : belongs_to_mars

No responses yet

Write a response