0% found this document useful (0 votes)
120 views242 pages

Coding User - Issue 08 December 2023

Uploaded by

mijimojo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
120 views242 pages

Coding User - Issue 08 December 2023

Uploaded by

mijimojo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 242
FS: lah | [9 Lode th) x ae Time Want to master your PC? Then don’t miss our NEW Windows PC & Laptop magazine on £5 Readly now! ‘Master Your Computer 2 = ‘Window WSs Windows 1 23H2 The Essential User Guide for the New Windows User! 11 A Beginners Guide ch aes clear aed Vierabecticics pene tS CRT MeN a dia bet ieet Pteretettrri sr acc aaa Click our handy link to read now: Peed i made! In this issue we look at the first time uses of all of the core coding languages and how to expand your experiences with them and learn their extensive uses. Our easy-to-follow tutorials show you how to create some utterly epic projects with your finger tips. Our team of experts will show you how to set up your Windows. computers or your Apple Mac to make use of the power of coding. We pass over our sister magazine, Tech Shopper to close out this double issue, with it featuring the very best head turning gadgets and software our team have come across. Welcome to the awesome new issue of Coding User. \ 8 _ Beinga Programmer 10 _ABrief History of Coding 12 _ Choosing a Programming Language 14 Creating a Coding Platform SD Mra kens 18 Why C+? 20 C++ Facts & Figures 22 _ Equipment You will Need 24 Structure of C++ Code 26 _ Howto Set Up C++ in Windows 28 Howto Set Up C++ ona Mac 30 32 How to Set Up C+ in Linux Other C++ IDEs to Install 34 ) Coding with C++ 36 38 40 42 44 46 48 Your First C+ Program Compile and Execute Using Comments Variables Data Types: Strings C++ Maths User Interaction 52 ) Introducing Pytl 54 _Why Python? 56 _ What Can You Do with Python? 58 Python in Numbers 60 Equipment You Will Need 62 Getting to Know Python 64 66 68 How to Set Up Python in windows How to Set Up Python in Linux Python on the Pi R 74 6 78 80 Starting Python for the First Time Your First Code Saving and Executing Your Code Executing Code from the Command Line Numbers and Expressions Using Comments aie) 1 Contents DOWNLOAD! WS eee Meme , elm tele great coding titles Si ae ase Cd For guides to C++, Python, Linux & eC) ota a : -Thesella : —ae Fee Ys mer c= SAO lies EY ret yo Reet ar ripe fe millions oflight-yaers: i help Solve the porn, Sel raitsty 2 Eley det esf (ciate) ele eele{ its -° NURSE m9 A, anndny . oe e be ee] a , aah o 1.009301 001101 00 o1 ay 2) ele SUC RalaRhabiey ohniab inate mah tale hab ele Seb ee] each si shRan Mees] p eb ees ee ee ap el ey 2st falar) ee ee alee ee ee ee ele my pena Aa ee Ls E ee are ee ee HR eel ee i Pe sfee ee lee ee ae Perera ia El (=f Fo = t= Pad uw y l=) -Fat (Welcome, Future Coder Eps Welcome, Future Coder UE RCM NR LCe a) PCN en acs Tt Ne Me ie eyo CO ee aa ee cane DE eee kur) pee ot nr eins learned how to code, and with this book you Ren nore ante ls| Poe ecu We cover C++, Python, and Linux Scripting Pause ue ee eres of project ideas, type-in listings, and in- Ce eect te oa ee een Tue Welcome, Future Coder Being a Programmer ‘Times have changed since programming inthe 80s, butthe core values still remain. “It's up to you how far to take your coding adventure!” Being able to follow a logical pattern and see an end result isone ofthe most valued sills oF a programmer. (Being a Programmer [ MORE THAN CODE For those of you old enough to remember the ‘80s, the golden era of home ‘computing, the world of computing was a very different scene to how its, today. 8-bit computers that you could purchase as a whole, as opposed to being in kit Form and you having to solder the parts together, were the stuff ‘of dreams; and getting your hands on one was sheer bliss contained within, 2 large plastic box. However, it wasnt so much the new technology that ‘computers then offered, moreover it was the fact that For the frst time ‘ever, you could control what was being viewed on the ‘television. Instead of simply playing one of the thousands of games available atthe time, many users decided they wanted to create their own content, thelr ‘own games; or simply something that could help them with their homework ‘or home finances. The simplicity ofthe &-bit home computer meant that ‘creating something from a few lines of BASIC code was achievable and so the irst generation of home-bred programmer was born. From that point on, programming expanded exponentially. t wasn't long before the bedroom coder was a thing ofthe past and huge teams of designers, coders, artists and musicians were involved in making a single ‘game. This oF course led to the programmer becoming more than simply ‘someone who could Fashion a sprite on the screen and make it move at the press of akey. Naturally, time has moved on and with itthe technology that we use. However, the fundamentals of programming remain the same; but what ‘exactly doesit taketo be a programmer? ‘The single most common trait of any programmer, regardless of what they/re doing, is the ability to see a logical pattern. By this we mean ‘someone who can logically Follow something from start to Finish and ‘envisage the intended outcome. While youmay not Feel you're such a person, itis possible to train your brain into this way of thinking. Yes, It takes time but once you start to thinkin this particular way you willbe able to.construct and follow code. ‘Second to logicis an understanding of mathematics. You don't have to be ‘at a genius level but you do need to understand the rudiments of maths. Maths is all about being able to solve a problem and code mostly alls under the umbrella of mathematics. Being able to see the big pictures certainly beneficial for the modem programmer. Undoubtedly, asa programmer, you will be part of a team ‘of other programmers, and more than likely part of an even bigger team (of designers, al of whom are creating a final product. While you may only be expected to create a small element of that final product, being able to Understand what everyone else is doing will help you create something that's ultimately better than simply being locked in your own coding cubicle. Finally, there's also a level of creativity needed to be a good programmer. ‘Again though, you don't need to be a creative genius, just have the imagination to be able to see the end product and how the user willinteract with it. ‘There is of course a lot more involved in being a programmer, including learning the actual code itself: However, with time, patience and the determination to lear, anyone can become a programmer. Whether you want to be part ofa triple-A video game team or simply create an ‘automated routine to make your computing life easier, t's up to you how Farto take your coding adventure! A Brief History of Coding It's easy to think that programming a machine to automate a process or calculate a value is amodern concept that's only really happened in the last Fifty years or so. However, that assumption is quite wrong, coding has actually been around for quite some time. CLM CMe MMMM Ok ee Tela ten een Ee eae EL ee ee ecm ere es areata cs Perens’ startof when humans began to ores ees Cee eet co Peer ea pester era Seon Cants Sree ests pec rae Dee scholars who worked in the House of Te ene ese Ceo eee ee Eo ec Rete ntti rere ets) eee cece ee co 1842-1843 i Joseph Marie Jacquard invents 3 programmable loom, which used cards with eee ene Pena design on a previous automated weaving Cee Lo i Cee eee eee een) Sverstrey ere ested Sa CUP oa ieee ere) Bieta See ee ee Peers cs A Brief Histo Er ee et Peon eee Tema) Die ca ee Crem nua Rem reer} Ree uss ae ee ae ty See Coo er oc. CR ened For ordinary Folk to buy. This led toa boom in home/bedroom Ce aun ey ‘ \ Cree ee Retard \ Re nea) Seen Pre ey ee eee Reeser rans Cot eu Pees aes eee eT 7 Perec rene script pa ee eee se PUP Pie et kts here rs Cueto’ Pearaeter nia) ones aes eee) Ce ene] allowed people access tothe tools and eee eee Leer gE) ror ane ore better way. Not only could auser learn Perret ren eed their code and source other code to reas Se ke ee cons Regional Assembly Language. Feo eae Ries eee ae the team that developed the UNIVAC architecture of the machine I computerand she eventually eT Pee ea egg Aer cs Peano oa ean tee ay (eo oko eae) Poteet es mea) Pee ute eri Bontcote ete Pricey corey " Choosing a Programming Language It would be impossible to properly explain every programming language in a single book of this size. New languages and ways in which to ‘talk’ to a computer or device and set it instructions are being FMV eekl ure merl re Renney onset of quantum computing, even more complex methods are being born. Here rN etela ee Meron Cure lel Ele nen im cacao ‘SQL stands for Structured Query Language. SQL is a standard language er eee em) (American National Standards institute) standard, there are different versions of Cl ae an eres Cie eet eee One aa Sea cs ee eee et Cee ees ek) ‘program how the web pages behave on the occurrence of an event. JavaScripts, eee Erte eet ite eter ey ‘web page behaviour. LAVA Tae kc application andis the global standard For developing enterprise software, web-based content, games and mobile apps. The two main components Ce ee ee er is PN ea ii eter te es fee ae ere er ie eee etd bud a variety of secure and robust applications that run on the NET Framework, You can use Ct to create Windows client applications, XML Web services, Client server applications, database applications and much more. The curly-brace syntax of C# willbe instantly recognisable to anyone familiar with C, C++ or Java. aay Python i a widely used high level programming language used for general purpose programming, created by Guido van et er a etc philosophy that emphasises code readability and a syntax that allows programmers, to express concepts n Fewer lines of code. This can make it easier For new pect ad QS C++ (pronounced cee plus plus) is a general purpose programming Poet ees ee cere ay te ee econ Ce ce resource-constrained and large systems, with performance, efficiency and flexibility Cree aes a ee ee ne eee ee Matsumoto, blended parts of his Favourite languages (Per, Smalltalk, Sere ee eee er eee Ree ead CE ee ee ee ee een parts of Ruby can be removed or redefined, at will. Existing parts can be added to. “PERL Perlis a general purpose programming language, used For a wide range of tasks including system administration, web development, See ae eet td Cee ae a ee ore eau Pen wet nee EL a eee ‘Swifts a powerful and intuitive programming language for macOS, 10S, watchOS and tvOS. Writing Swift code is interactive and fun; the syntax is concise yet expressive and Swift includes modern Features that developers love. Swift codes safe by desian, yet also produces software that runs Lightning Fast. A coding tutorial app, Swift Playgrounds, is available forthe iPad. Welcome, Future Coder Creating a Coding Platform rere Pier eereeianenre cee en es pearenpenertee ween ise eininerrent wetness Se eat ean ier nine Ben CCE O aS paar ee peer eer nCn oS Pe ee peer ocr snport re re Thankfully, coding atthe Foundation level doesn’t require specialist eq cor atop ofthe range, lig hydrogen-cooled PC. IF you own a computer, no matter how basic, you can begin to learn how to code. Naturally, iFthe computer in question is 2 Commodore 64 then you may have some difficulty following a ‘modern language tutorial but some of the best programmers around today started on an &bit machine, so there's hope yet. install and update the coding development environment, alongside a computer with Windows 10, macOS, or Linux, instal can use other operating systems, but these are the ‘big three! and you will find that most code resources are written with ‘one, oral, of these in mind wom ppublestionscom eee eect eee buts often confusing to tackle. After al, there's a plethora pret ee eee Peters ere ace tere eure huge amount of third-party softwar ay accessing the Interne countless Peete ent peer Peete ar ecto Te eens Rae Ce eo ed eee erro etn es citar Creer tet Atacand peor ease ee eee aes Pes eae eee Set as while you begin to take your frst tentative steps into ld of coding, In terms of software, most of the developmen environments have the toals that allow you to fe, compile the code and execute it, freely available to download and instal, There are some specialist tools available that will cost, but at this level they're not necessary, so dont be Fooled into thinking you need to purchase any extrasoftwarein order to start learning how to code. Over time, y may Find yourself pragressing from the mainstream development environment and using a allection of your awn, tools to write your code. sal personal preference in the end and as you become more experienced, you will start to use different tools to get the job done, L (Creating a Coding Platform [ SUT eua N=} ‘Avirtal machine sa piece of sofware that allows you to installa Fully working operating system within the confines ofthe software itsef. The installed OS wil locate user-defined resources fromthe host computer, provicing memory, hard crve space etc, as wellas |} sharing the host computer'sintemet connection Ne UES) Windows 10s the most widely used operating system in the world, so i's natural that the vast majority of coding tools are ‘ritten For Microsoft's leading operating system. However, dont discount macOS and especially Linux. 1macO users enjoy an equal number of coding tools to their windows counterparts. In Fact, you will probably find that a lot of professional coders use 2 Mac over aPC, simply because of the fact that the Mac operating system is built on top of Unix (the command-line OS that powers much of the world’s filesystems and servers). This Unix layer lets you test programs In almost any language without using a specialised IDE. COLE) However, Linuxis, by far and away, one of the most popular and important coding operating systems available. Not only doesit have a Unixlike backbone, it's also Free to download, Install and use and comes with most of the tools necessary to| start learning how to code. Linux powers most ofthe servers that make up the internet. t's used on nearly all ofthe top supercomputers, as well as specifically in organisations such {as NASA, CERN and the military it also forms the base of ‘Android powered devices, smart TVs and in-ar systems, Linux, 2a coding platform, isan excellentidea and itcan be installed inside a virtual machine without ever affecting the installation ‘of Windows or macOS, ‘The advantage ofa virtual machine is that you can work with Linus, for example, without itaffecting your currently installed host OS. This means that you can have Windows 10 running and launch your virtual machine dient, Bot into Linux and use all the Functionality of Linux, wile still being able to use Windows, ‘This, of course, makes ita fantastic coding platform, as you can, have different installations of operating systems running from the host computer while using different coding languages. You can test your code without Fear of breaking your host OS, ‘andit's easy to return to a previous configuration without the need to reinstall everything again. Virtualisation is the key to most big companies now. You will probably Find, rather than having a single server with an installation of Windows Server, for example, the IT tear have instead opted fora virtualised environment whereby each Windows Server instance sa virtual machine running from several powerful machines. This cuts down on the number ‘of physical machines, allows the tear to better manage resources and enables them to deploy an entire server Ha THE RASPBERRY PI F ryouhavert already heard ofthe RaspberryP then we suggest you head over to www.raspberrypi.organd check itout.nshor, the Raspberry Pisa small Fully Functional computer. Itcomes withits own customised Linux based operating system that's preinstalled with everything you need to start earning how to, } codein Python, C+, Scratch and more YOUR OWN CODING PLATFORM Whichever method you choose, remember that your coding platform wil probably change, as you gain experience {and favour one language over another. Don't be afraid to experiment along the way, as. you will eventually create your ‘own unique platform that ‘canhandle all the code you enter into it Costing around €35, its incredibly cheap and allows you to utilise different hardware, in the form of robaticsand electronics projects, as well asoffering a complete desktop experience. Although not the most powerful computing device in the world, the Raspberry Pihas a lot going Fort, especially in terms (of being one ofthe best coding platforms avalabe. Introducing y 10 i On v1) O10 5} 7] 1 rt} i ui) a =—— 0 110 110 en) P , , TARE RE CLE cine | utc a od i (RAS aus cus i ao Pent mci Coane cin tac SLC er ekg eater) 00 Pe eee Ei er Tea ry] whole new world for you, in terms of desirable 00 PU UR EL a one Eee eur tute 00 MW iat eran eueenene rerun teres an} Para oR C0 eee Ee applications, games and much more. It’s used in science, engineering, banking, education, the space industry, and much more. — ee ee Sree OSS OSS aso aos ese eae7 fb Introducing C++ Why C++? C EVERYTHING Due to both the complexity of the language and its power and performance, C++ is often used to develop games, programs, device drivers, and even entire operating systems. Dating back to 1979, the start of the golden era of home ‘computing, C+, or rather Cwith Classes, was the brainchild of Danish computer scientist Bjame Stroustrup, while working on his Ph.D. thesis. Stroustrup’ plan was to further the original C language, which had been widely used since the early seventies. C+ proved to be popular among the developers of the 80s, since itwas a much easier environment with which to get to grips, ‘and, more importantly, it was 99% compatible withthe original C language. This meant that, beyond the mainstream computing labs, regular people who didn’t have access to the mainframes and large ‘computing data centres could useit. C++'simpactin the digital worldis immense, Many ofthe programs, applications, games, and even operating systems re coded My C++ code is much Faster than other ‘programming languages. Using C++. For example, all of Adobe's major applications, such as Photoshop, InDesign and so on, are developed in C++, You wil find that the browser you use to surf the Internet is written in C++, as well as Windows 10, Microsoft Office, and the backbone to Google's search engine. Apple's macOS is written largely in C++ (with some ‘other languages mixed in depending on the function) and the likes ‘of NASA, SpaceX, and even CERN use C++ for various applications, programs, controls, and umpteen other computing tasks. Aswell as being an easier addition to the core Clanguage, CH+ is also extremely efficient and performs well across the board. This higher level of performance over other languages, such as Python, BASICand such, makes it an ideal development environment For ‘modern computing; hence the aforementioned companies using it sowidely, | = aSc se ate douse ato ig summary ~ eskzop development wth ‘Microsoft's Visual Studio isa great, free cenvironmentin which to learn C++. Ct puts the developer in. a much wider world of coding. By mastering C++, you will Find yourself being able to develop code for the tikes of Microsoft, Apple and so on. Generally, C++ developers. ‘enjoy a higher salary than programmers of some other languages, and, due to its versatility, the C++ programmer can move between jobs and companies without the need tore-learn anything specific ‘You will discover, as you become a more advanced coder, that many ‘of the developers in various coding jobs around the world tend to use pre-designed development engines. For example, when creating ‘games, the likes of Bethesda, the team behind Oblivion and Skyrim, utlise a 30 game engine called The Creation Engine. This enables the team to quickly create animations, characters items, terrains, Fooms, and just about everything else you'd see in the game. The ‘engine itself has been modified to make the most ofthe current ‘araphies card hardware, and computer or console processing ower, These engines are mostly written in C++, and when making Indeed, the operating system ‘you're using is written in C+. Improvements to the engine, or when creating a new game, the developers want to add something that the engine can't do, they will use C++ to create the new content or link between two rent engines. The end result, of course, isa game that con the latest graphical technology, white being seamlessly bound together with some pretty clever C++ coding. Getting to use C++ is quite easy all you need isthe right setof tools in which to communicate with the computer in C++, and you can start your journey. A C++ IDE is Free of charge, even the immensely powerful Visual Studio from Microsofts Freely available to ‘download and use. You can getinto C++ from any operating system, bbe it macOS, Linux, Windows, or even mobile platforms. So, to answer the question of Why C+, the answer is because it’ Fast, efficient, and developed by most ofthe applications you regularly se,lts cutting edge, and a Fantastic language to have mastered. Introducing C++) C++ is one of the top programming languages in the industry. It’s quick, powerful, and used by nearly every major tech and gaming company in the world. Here's some interesting Facts about the rather wonderful C++. C+tis oneofthe >» predominant programming languages for the development of all kinds of technical Rca and commercial MICROSOFT, software, ORACLE, PAYPAL, LINKEDIN, AMAZON AND THE MILITARY USE C++. C++ has influenced other ™ programming 3D AN IMATION, languages, such as MODELLING, Cit and Java. AND SIMULATIONS Alot of the Linux operating system is coded using C++, therefore you could say that most of the world’s Internet. hosting servers are available thanks to C++. SUPERCOMPUTING USES C++ CODE More than 70% of all TO CALCULATE VAST AMOUNTS OF e See bitte DATA, INCLUDING THE NASA-BASED (HFT), and the software SUPERCOMPUTING FARM THAT RUNS responsible is written in SIMULATIONS OF THE UNIVERSE. abe tiiebeetal Sources bsweteh Coogi Quora, Stack ( C++ Facts & Figures Eopeg chong, iC, StockOverfow stocShore Aopbynanics ‘ses Ces asits backbone. Gaming is one of the biggest users of C++. ithandles the ‘Many database applications: complexities of 3D games, are bull sing C++, such supports multiplayer Google Chrome, Mazila's as MySQL, it's also used options, and enables Firefox, and even Microsoft's by Wikipedia, Yahoo and intensive CPU and Epeteepelieaes YouTube. GPU hardware y easier functions. J THE CHis » i used in computer " networking as the nm main code behind the . Programmable Logic PERCENTILE SALARY Peretlesies Controller, connecting FOR AUK-BASED C++ are developed servers, processors, other DEVELOPERS pee hardware, and Senge ‘even robotics. MRI scanning machines and Computer Aided Design all use C++ to help with the enhanced imagery produced by these systems. Windows 95,98, 2000, XP,7,8.1 and 10, as well as ‘Microsoft Office, as the backbone pi language of choice. The Unreal 4 Engine, which is coded in C++, is used for hundreds ‘of games, including Fortnite. CTV alts _TECHNOLOGIES afer ey nec} ADVANCED CESS platen) Be FLIGHT CONTROL SYSTEMS IN MODERN AIRCRAFT, INCLUDING MILITARY AIRCRAFT, USE C++. ) Introduci ac ) Equipment You Will Need Noreen ae eure muna ml kere hat Cone Rete n le ea ritie eel ore eh sc eg Meet Ree casi eics cn C++ SETUPS ‘As most, if not all, operating systems have C++ at their code, it stands to reason that you can learn to program in C++ no matter what 0S you're currently using. (| computer Unless you fancy witng out your C++ code by hand ona sheet of paper whichis something many older coders used to do), then a computer is an absolute must have Component. PC Users can have ny recent Linux dro or Windows 05 Mac uses the latest macOs. AN IDE AnIDE is used to enter and execute your C+ cade. Many IDEs come with extensions and plugins that helo make t work better, o add an extra level of Functionality. Often, an IDE will provide enhancements depending on the core OS being used, such as enhancements for Windows 10. [| COMPILER ‘Accompiler is a program that converts the C++ language nto binary that the computer can understand. While some IDEs come with a compile builtin, others don't, CodeBlocks is our Favourite IDE that comes with a C++ compiler as part ofthe package, More on this later. |_| TEXT EDITOR Some programmers much prefer to use a text editor to assemble their C++ code before running it through a compiler. Essentially, you can use any text editor to write code, just save twith a.cpp extension. However, Notepad++ is one of the best code text editors availabe. INTERNET ACCESS While it’s entirely possible to learn how to cade on a computer that’s not attached tothe Internet, t's extraordinarily difficult. You will need toinstal the relevant software, keep itup to date, install any extras or extensions, and [ook for help when coding, All of which require access to the Internet. |_| TIME AND PATIENCE You're going to need to set aside significant time to spend on learning how to code in C++, Sadly, unless you're a genius, it’s not going to happen overnight, or even ina "week. A good C++ coder has spent many years honing their craft, so be patient, start small and keep learning ( Equipment You will Need OS SPECIFIC NEEDS C++ will work in any operating system; however, getting all the necessary pieces together can be confusing to a newcomer. Here's some OS specifics for C++. Linuxcusers are lucky in that they already have a compiler and text editor built into their operating system. Any text editor will allow you to type out your C++ code, when it’s saved with 2 cpp extension, use gr+ to complet ‘As we've mentioned previously, one good IDE is Microsoft's Visual Studio. However, a better IDE and compiler is Code::Blocks, which is kept regularly up to date with a new release twice yearly, orso. Otherwise, Windows users can enter their code in Notepad-+ then compile it with MinGW ~ Which CodeBlocks uses. Naa ‘The Raspberry P's operating system is Raspbian, whichis Linux based, Therefore, you're ‘able to write your code out Using text editor and then compile it with or, as you ‘would in any other Linux distro. ‘Mac owners will need to download and install Xcode, in order to compile their C++ code natively. Other ‘options for the macOS include Netbeans, Eclipse or Code:Blocks. Note: the latest Code:Blocks isn't available for Mac, due toa lack of Mac developers. BD weotcinc ) Structure of C++ Code C++ is an amazing programming language to learn. If your dream is to become a games designer, or work at the cutting edge of science or engineering technology, then being able to code in C++ is a must. Remember, you're never too old to learn how to code. #INCLUDE ‘As you learn the basics of programming, you will begin to understand the structure of a program. The commands may be different, but you will start to see how the code works. an #INCLUDE Danish student Bjarne Tlockeonelec tonceye, ala oes eS aS Stroustrup invented C++ in 1979, 38 apart of his PRD. thesis. Initially C++ was called CCwith Classes, which added se familar tn tyou'Tbeginto See how tflows. very Ces code besins wns drectve, clude evihediecveinstucsthe¢ *newcodecpp declaration of a Function, which isa group of code statements, ‘under the name ‘main’. All featuestothe akeady popular $ preprocessorto indudea programming language =} section ofthe standard C++ #include while making it amore } code. For example: #include: Userfriendy environment. £ includes the ‘ostream header to support Bjarne Stroustrup, inventor input/output operations. of Hs, } INT MAIN() . *newcode.cpp (~/D { Intain initiates the File Edit View Search Tools Documents Help. ecode beghs atthe main function regardessof where @)#nemcodecpp x ites thin the man body oF Can avof Finclude int main() BRACES ~ ae ena he open brace 1 ; 7 See eee umay [Fe Edt View Search Tools Documents Help not have come across before, especially if you're used to other coding languages. The ‘open brace indicates the beginning ofthe main #include Function, and contains allthe code belongingto int _main() that function. { COMMENTS Lines that begin with a double slash are comments. This means they ‘won't be executed in the cade and are ignored by the compiler. Why {are they there? Comments are designed to help you, or another programmer looking at your code, explain what's going on, There {are two types of comment: /* covers multiple ine comments, //a single line, > *newcode.cpp (-/Documents) Fle Edt View Search Toole Documents Help [ech temcadecoe i#include dint main() « (1m first ces progrant STD In C++, STO means Standard. l’sa part ofthe Standard Namespace. in C++, which covers a number of different statements and ‘commands. You can leave the std part out ofa code, but it must be declared atthe start with: using namespace etd, . “snewcode.cpp (-/Documents) Fle Edt View Search Tools Documents Help (€) trewcodecpp #include using namespace int main) « 11 My first Coe program! Sta? cout | Structure of C++ Code ell << “The two chevrons used here ae insertion operators. This means that, whatever Follows, the chevrons are to be inserted into the std:cout statement. In this ase, they are the words Hello World, |which are to be displayed on the screen when you compile and execute the code, . “snewcode.cpp (Documents) Fle St View Search Tools Documents Help [c) trewcode cpp \#include int main() I) My first Ces prograst out << ("Helle World!\n") OUTPUTS Leading on, (Hello World!) isthe part that we want to appear on the screen when the code is executed. You can enter whatever you like, as ong as t's inside the quotation marks. The brackets aren't ‘needed, but some compilers insist on them. The \n part indicates 3 ew line isto be inserted. 1/ My first C++ program! cout << ("Hello World!\n")| AND} Finaly you wil notice that lines within a function code block (except comments) end witha semicolon. This marks the end of the statement, and all statements in C++ must have one at the end cr the compiler wil fll to build the code. The very last line has the closing brace to indicate the end ofthe main Function. ) Introduci ac ) How to Set Up C++ in Windows Wi Nate eM clam rea ean ecto ee Cnn kee ay Peer oa =the ceca mieten StS noum crea However, in our opinion, the best C++ IDE to begin with is Code::Blocks. CODE::BLOCKS Code::Blocks isa free C++, C and Fortran IDE that is Feature rich and easily extendible with plugins. It's easy to use, comes with ‘a compiler and has a vibrant community behind it too. FRED tart by visting the Code-locks download site, at wwnwcodeblocks.org/downloads. From there, click ‘on the ‘Download the binary reteases'linkto be taken to the latest downloadable version For Windows. ERTeeED There you can see, there are several Windows versions available. The one you want to download has mingw-setup.exe atthe end of the current version number. At the time of writing thisis: codeblocks-17.12mingw-setup.exe. The liffecence is thatthe mingw-setup version includes a C++ compiler ‘and debugger from TOMGCC (a compiler suite) ‘When you've located the file, click on the Sourceforge.net link atthe end of the line anda download notification window appears; click on Save File to start the download and save the executable to your PC. Locate the downloaded CodeBlocks installer and double-click to start, Follow the on-screen instructions to begin the installation, Sid @: Welcome to CodeBlocks Setup ‘Seno gae yu trou reat Cotes, reopened tye ater eto Sesenaregteun aroma toque inte ‘Sovoteya ot ng teat aa Som ‘Once you agree to the licencing terms, a choice of installation options becomes available. You can opt For a smaller install, missing out on some ofthe components but we recommend that you opt forthe Full option, as default. Coons Components ee aor yaw andes be coves a naa le econ [Recon at ra ¥ Next choose an install location Far the CodeBlocks files. t's your choice but the default is generally sufficient (unless you have any special requirements of course). ‘When you click Next, te install begins; when it's Finished a notification pops up asking you if you want start Code: Blocks now, so.click Yes. ete sara ses aera Ruane sence Sa rr! ere st ‘There'sa lot you can do in CodeBlocks, so you need todigin and find a good C++ tutorialto help you {get the most from it. However, to begin with, click on File > New > Empty File. This creates a new, blank window for you to type in PPD the frst time Code:Blocks loads it runs an autodetect for any C++ compilers you may already have installed on your system. if you don't have any, click on the First detected option: GNU GCC Compiler and click the Default button to set it as the system's C++ compiler. Click OK when you're ready to continve. SRI SES aecranraaie nei oc The program starts and another message ppeas Suey informing you that Code::Blocks is currently not the default aplation fr Cres You have tuo option to eve eventhing as tis allow Code:Socs to associate al rele byes Aga, we would recommend you opt forte astro, to dscocte Codecs with every supported Fle ype. PEPED the new window, enterthe following: Hinclude Int main() fl Jimy fizet CH program Std: :cout << "Hello World!\n"? 1 Notice haw Codes.Blacks auto-inserts the braces and speech quotes, ClckFe> Save asand save the code vith sma ily -Cpp extension (helloworld.cpp, For example). CodeBlocks changes the view to colour coe accordngt Ce+ Standards. To exectethe code clckon the Bland un Kon along the top ofthe sree.’ green pay ion together witha yellocog How to Set Up C++ in Windows C= ) Introducing C++ How to Set Up C++ ona Mac se Meemece ee era leant Cero emcees ce MS Pence aurea ke ure ccs ear ced also able to be used to create C++ code relatively easily. 1ed For users to develop apps for macOS, iOS, tvOS and watchOS applications in Swift or Objective-c, but we can use it for C++ too. FETE EEDD t2ttby opening the App Store on yourMac, Apple REESE When you're ready click onthe Get or cloud icon Menu > App Store. n the Search box enter Xcode, button which willinstall the Xcode app. Enter your {and press Return. There willbe many suggestions filing the App Apple ID, and Xcode will begin to download and instal. ir may take ‘Store window, but t's First option, Xcode, that you need to click on. some time depending on the speed of your Internet connection, as Xcode isin excess of 1168, FETED) 12ke 2 momentto browse through the app’s Eee When the installation is complete, click on the Open Information, including the compatibility to ensure button to launch Xcode. Click Agree to the licence you have the correct version of macOS. Xcode requires macOS terms, and enter your password to allow Xcode to make changes 10.12.60 later to install and work. to the system. When you've done that, Xcode will begin to install additional components. \With everything now installed, including the additional components, Xcode wil launch displaying the version number along with three choices and any recent projects that you've worked on~although for fresh instal this wl be blank, Start by clicking on Create New Xcode Project, this Sues ‘opens a template window to choose which platform you're developing code For, Click the macOS tab, then click the Command une Too option. Click Nev to continue Fillin all the Fields, but ensure that the Language ‘option at the bottom is set to C++. Simply choose it From the drop-down list. When you've filed in the Fields, and made sure that C+ isthe chosen language, click on the Next buttonto continue. How to Set Up C++ ona Mac Epa ‘The next step asks where to create a Git Repository For al your Future code. Choose a location on your Mac, or a network location, and cick the Create button, When ‘you've done all that, you can start to code. The left-hand pane details the files used in the C++ program you're coding, lick on the main.cpp filein the list. Secor cua reaucassaseeeegueuenorrne When you want to run the code, click on Product > un, You may be asked to enable Developer Mode onthe Mac, thisisto authorise Xcode to perform functions without needing your password every session. When the program executes, the output will be displayed atthe bottom ofthe Xcode window. f Jp Introducing C++ How to Set Up C++ in Linux LINUX++ ‘There are many different versions of Linux available, For this example we're using one of the more popular distributions: Linux Mint. However, these steps will work in any Debian-based Linux. ‘The fist step with ensuring Linux's ready for your C++ code's check the system and software are Up to date. Open a Terminal and enter: 46 sudo apt-get parade. Press Return and enter your password. These commands updates the entire system and any installed software, File Edit View Search Terminal Help Sree ran roa david: Bl FEED Most Linux distros come preinstalled with all the necessary components tostartcodingin C++. However, its always worth checking to see if everything present, sostillwithin the Terminal, enter: sudo apt-get: install build-essential and press Return. F you have the right ‘components, nothings installed but IFyou're missing some then they are installed by the command, Fit Vow Such Tei eb PEPER Aazinaly, that'sit. Everything ill ready for you to start coding, Here's how to get your First C++ program up and running n Linux Mint the main text editor isXed canbe launched by clicking on the Menu and typing xed into the search bar. Click on the Text Editar button in the right-hand pane to ‘open xed. In Xed, or any other text editor you maybe using, enter the lines of code that make up your C++ Hello World program. To remind you, its: Hinclude int main() ( May first c+ program std::cout << “Hella World!\n"; include int main) eo Saat tnt ortay b FETED When you've entered your code, lick File> Save As and choose a folder where you want to save your program, Name the file as helloworld.cpp, or any other name just as long asithas.cpp as the extension. Click Save to continue. =r The fist thing you can see isthat Xed has automatically recognised this asa C++ fle, since the file extension fs now set to.cpp. The colour coding is present in the ‘ode and if you open up the file manager you can also see that the Fle’ icon has C+ stamped on it FEED with your code now saved, drop into the Terminal again. You need to navigate tothe location of the C+ fileyou've just saved. Our examples in the Documents folder, sowe can navigate toit by entering: ed Dacument's Remember, the Linux Terminals case sensitive, so ary capitals must be entered correctly. (_ How to Set Up C++ in Linux Before you can execute the C++ file you need to compile it. In Linux t's common to use g++, an open source C++ compller and as you're now in the same Folder asthe C++fle, go tothe Terminal, enter: g++ hel loworld..epp and press return davidemi: Fle Edit View Search Terminal Help earn TEED There willbe a brief pause asthe code is compiled by g++ and providing there are no mistakes or errorsin the code you are retumed to the command prompt. The compiling of the code has created a new file. Fyou enter 1 into the Terminal you can see that alongside your C++ files a.out. davide Fle Edit View Search Terminal Help STE) este Paeeacees ered PEPER the 2cutfileisthe compiled c++ code. Torunthe code enter: /a.out and press Return. The words Hello World! appears onthe screen, However, aout isnt very friendly To name it something else post-campiling, you can recompile with: t+ helloworld.cpp =o helloworld. Thiscreatesan output file called helloweorld which can be run with: /he1Lowor a, File Edit View Search Terminal Help rs Other C++ IDEs to Install IF you want to try a different approach to working with your C++ code, then there are plenty of options available to you. Windows is the most prolific platform for C++ IDEs but there are plenty for Mac and Linux users too. DEVELOPING C++ Here are ten great C++ IDEs that are worth looking into. You can install one or all of them if you like, but find the one that works best for you. Eclipse is @ hugely popular C++ IDE that offers ED Codetite isa free and open source IDE that's LL the prosramers weath of eatres those Seta cei updated and ovlable for Windows ‘great, clean interface, is easy to use and available For Windows, Linux and macOS. It’ lightweight, uncomplicated and extremely Linux and Mac. Head over to www.eclipse.org/downloads/ to powerful. You can find out more information as well as how to ‘download the latest version If you're stuck, clickthe Need Help link download and instal it at www.codelite.org/ For more information, ‘The GNAT Programming Studio (GPS) isa powerful ‘Another popular choice is NetBeans. This and intuitive IDE that supports testing, debugging isanother excellent IDE that's packed with {and code analysis. The Community Editions Free, whereas the Features anda pleasure to use. NetBeans IDE includes project based Pro version costs; however, the Community Edition isavalable for templates For C++ that give you the ability to buld applications with Windows, Mac, Linuxand even the Raspbery Fi.Youcanfinditat dynamic and static libraries. Find out more at www.netbeans.org/ wwrwadacore.com/download. Features/cpp/indexhtml. Other C++ IDEs to Install ei Microsoft’ Visual Studioisa mammoth C++ IDE that allows you to create applications For Windows, Android, iOS and the web, The Community version is Free to download and install but the other versionsallowa Free trial period. Go to wwv.visualstudio.com/ to ‘see what it can do for you. This crossplatform IDEs designed to create C++ applications for desktop and mobile environments. it comes with a code editor and integrated tools for testing and debugging, as well as deploying to you chosen platform. snot free but there is a tral period on offer before Fequiring purchasing: www.at io/qt-features-tibraries-apis-tools- and-ide/ Bloodshed Dev C++, despite its colourful name, isan older IDE that is For Windows systems only However, many users praise its clean interface and uncomplicated ‘way of coding and compiling. Although there's not been much updating for some time, it's certainly one to consider if you want something different: www.bloodshed.net/devepp. html fone PRT) The Anjuta Devstudio is Linux-only IDE that Features some of the more advanced Features you ‘would normally Find in a paid software development studio. There's 8 GUI designer, source editor, app wizard, interactive debugger and much more, Go to wwww.anjuta.ora/ for more information, ThisexcellentDE allows developers towrite C++ code for desktop and ‘web applications across all the major platforms. There's an advanced text editor, integrated debuoger and a configurable workbench to help you create your code. t's available For Windows, Mac and Linux ands Fee to download and use: www.monodevelop.comy/ Ultimate++ isa cross-platform C++ IDE that boats a rapid development of code through the smart and aggressive Use of C++. For the novice it's a beast of an IDE but behindits complexity s a beauty that would make a developer's knees go ‘wobbly. Find out more at www.ultimatepp.org/index.html By

You might also like