Writing Your First Lines of Code

Writing Your First Lines of Code

Lesson Details:
July 10, 2020


I: Introduction

1.0 Introduction to programming languages

Nowadays, the computer has become an essential part of our daily life. It is easy to see that people are using it more and more. To be able to use the computer, we need to know how to program it. This is why we need to learn programming languages.

1.1 What is a programming language?

A programming language is a tool for writing computer programs. The purpose of a programming language is to create a program that performs specific tasks, such as opening a window on your desktop or fixing your car. A computer understands commands written in a programming language. Programming languages can be classified into different types: procedural and object-oriented. Some languages support only one type of programming, but some support both. Procedural and object-oriented programming differ in how they organize programs, how they manage memory and how they handle errors.

1.2 What is procedural programming?

Procedural programming uses commands that execute one at a time. Each command in a program is executed by following a reserved order (a procedure). For example, when you put on your clothes in the morning, you follow a procedure: you take off your pajamas, put on your underwear, your shirt and pants and then shoes and socks. If you don’t follow this procedure, you will not look good and if you don’t follow the procedure in your program, the program may not work correctly. Like in procedural programming, if you want to play a video file on your computer, you have to follow a procedure: open your media player, open the video file on the media player, select the play button and then press ok to start playing the video. In procedural programming each instruction is called a statement and the statements must be executed in order from top to bottom. To make sure that all statements are executed in order, we have to add a statement called “go to statement” at the beginning of the program which will execute each statement one by one until it gets to a place where it can stop executing statements. We call this place “end of program”.

1.3 What is object-oriented programming?

In object-oriented programming, objects are reusable components of a program that can be added, deleted and controlled individually. Object-oriented programs are organized around objects which interact with other objects within a defined interface. A program might contain 10 objects, for example a window object, a save button object and a list box object. These objects can communicate with each other through their defined interfaces. In this way, object-oriented programs are easier to understand and easier to modify than procedural programs because each object can be understood separately without having to understand how all the other objects interact with them. Also, unlike procedural programming, object-oriented programming does not require explicit coding of control structures like “go to” commands; this allows code to be written in an easier, more natural style instead of in an unnatural style involving many control structures. Object oriented programs are also shorter than procedural programs because there is no need for go to commands or if then else commands which are necessary in procedural programming. For example, in object oriented programming if we want to print “Found it” when we found something using the keyboard input then we don’t have to write so many lines of codes like in procedural programming where we have to write many go to statement or if then else statements which makes our program longer than necessary.

1.4 What is C++?

C++ is an object-oriented programming language developed by Bjarne Stroustrup at Bell Labs between 1979 and 1983 as an enhancement of the C programming language.[1] The name was changed from “C with Classes” to C++ in 1983. C++ adds numerous features to C that enable system programming using object-oriented programming techniques including data abstraction, inheritance, virtual functions and operator overloading. C++ also supports generic programming through templates, multiple inheritance, function overload resolution and run-time type identification. C++ provides facilities for low level memory manipulation like managing memory addresses, structuring memory blocks using unions, and basic type conversions without overhead resulting from virtual function calls. Most C++ programmers will agree that it has become one of the most popular programming languages today. It has been used for applications ranging from video games to web browsers to operating systems because it provides system programmers with powerful tools for developing complex software. It is widely used for hardware development too because it supports low level memory manipulation which is needed for device drivers and other hardware related applications.[2]

II: Body

The first part of this article will describe how I created my first lines of code using C++ language. The second part will discuss the benefits of using procedural versus object-oriented programming languages.

2.1 My first lines of code using C++ language

To learn how to program I searched for information on the internet about how do I write my first lines of code using C++ language? This question provided me with few pages where I found useful information about how I should write my first lines of code using C++ language.[3] The first thing was that I had to download the development environment called Visual Studio which includes both compiler and debugger.[4] After downloading Visual Studio,[5] I installed it on my computer and I opened it.[6] When I opened it I saw three windows: Solution Explorer,[7] Toolbox,[8] and Code.[9] I was able to see those windows because they were already open when I started Visual Studio; however; I could also make them disappear.[10] As I was searching for information about my first lines of code using C++ language I found out that I had to create a new project by clicking on File > New > Project.[11] Then I had to select Visual C++ Projects[12] and click on Next.[13] After that I selected Win32 Console Application[14] and clicked on Next.[15] Finally after choosing my project name and location[16] I clicked on Finish.[17] When I clicked on Finish I saw two files: main.cpp[18] and winMain.h[19]. These two files were created automatically by Visual Studio when I created my project.[20] The main file was named main because it contained my first lines of code using C++ language.[21] The winMain file was named winMain because it included some additional information about my project.[22] After creating my project with two files inside it I had to write my first lines of code using C++ language on my main file.[23] My first lines of code using C++ language were similar to lines of code written in any other programming language.[24] Here are some examples:

// Declare variables int count=0; // Loop from 0 up to 9 for(int i=0;i<10;i++) { // Increment count by 1 count++; // Print value of count cout << i << endl; } return 0; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353

loader
Course content