0% found this document useful (0 votes)
38 views4 pages

Week 1

Ok

Uploaded by

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

Week 1

Ok

Uploaded by

joshualumbo1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Week 1

What is programming?

 Programming refers to a technological process for telling a computer which tasks to perform in order to solve problems. You
can think of programming as a collaboration between humans and computers, in which humans create instructions for a
computer to follow (code) in a language computer can understand.

Programming enables so many things in our lives. Here are some examples:

1. When you browse a website to find information, contact a service provider, or make a purchase, programming allows you to
interact with the site’s on-page elements, such as sign-up or purchase buttons, contact forms, and drop-down menus.
2. The programming behind a mobile app can make it possible for you to order food, book a rideshare service, track your fitness,
access media, and more with ease.
3. Programming helps businesses operate more efficiently through different software for file storage and automation and video
conferencing tools to connect people globally, among other things.
4. Space exploration is made possible through programming.

How does computer programming work?


 At its most basic, programming tells a computer what to do. First, a programmer writes code—a set of letters, numbers, and
other characters. Next, a compiler converts each line of code into a language a computer can understand. Then, the computer
scans the code and executes it, thereby performing a task or series of tasks. Tasks might include displaying an image on a
webpage or changing the font of a section of text.

Introduction to C++ as a programming language.

 C++ is a general-purpose programming language that was developed as an enhancement of the C language to
include object-oriented paradigm. It is an imperative and a compiled language.

1. C++ is a high-level, general-purpose programming language designed for system and application programming. It
was developed by Bjarne Stroustrup at Bell Labs in 1983 as an extension of the C programming language. C++ is
an object-oriented, multi-paradigm language that supports procedural, functional, and generic programming
styles.
2. One of the key features of C++ is its ability to support low-level, system-level programming, making it suitable
for developing operating systems, device drivers, and other system software. At the same time, C++ also
provides a rich set of libraries and features for high-level application programming, making it a popular choice
for developing desktop applications, video games, and other complex applications.
3. C++ has a large, active community of developers and users, and a wealth of resources and tools available for
learning and using the language. Some of the key features of C++ include:
4. Object-Oriented Programming: C++ supports object-oriented programming, allowing developers to create
classes and objects and to define methods and properties for these objects.
5. Templates: C++ templates allow developers to write generic code that can work with any data type, making it
easier to write reusable and flexible code.
6. Standard Template Library (STL): The STL provides a wide range of containers and algorithms for working with
data, making it easier to write efficient and effective code.
7. Exception Handling: C++ provides robust exception handling capabilities, making it easier to write code that can
handle errors and unexpected situations.
8. Overall, C++ is a powerful and versatile programming language that is widely used for a range of applications and
is well-suited for both low-level system programming and high-level application development.

Overall, C++ is a powerful and versatile programming language that is widely used for a range of applications and is well-
suited for both low-level system programming and high-level application development.

What is an IDE?
 An integrated development environment (IDE) is a software application that helps programmers develop
software code efficiently. It increases developer productivity by combining capabilities such as software editing,
building, testing, and packaging in an easy-to-use application. Just as writers use text editors and accountants
use spreadsheets, software developers use IDEs to make their job easier.

Why are IDEs important?


You can use any text editor to write code. However, most integrated development environments (IDEs) include
functionality that goes beyond text editing. They provide a central interface for common developer tools, making the
software development process much more efficient. Developers can start programming new applications quickly instead
of manually integrating and configuring different software. They also don't have to learn about all the tools and can
instead focus on just one application. The following are some reasons why developers use IDEs:
1. Code editing automation
 Programming languages have rules for how statements must be structured. Because an IDE knows these
rules, it contains many intelligent features for automatically writing or editing the source code.

2. Syntax highlighting
 An IDE can format the written text by automatically making some words bold or italic, or by using different
font colors. These visual cues make the source code more readable and give instant feedback about
accidental syntax errors.

3. Intelligent code completion


 Various search terms show up when you start typing words in a search engine. Similarly, an IDE can make
suggestions to complete a code statement when the developer begins typing.

4. Refactoring support
 Code refactoring is the process of restructuring the source code to make it more efficient and readable
without changing its core functionality. IDEs can auto-refactor to some extent, allowing developers to
improve their code quickly and easily. Other team members understand readable code faster, which
supports collaboration within the team.

5. Local build automation


 IDEs increase programmer productivity by performing repeatable development tasks that are typically part
of every code change. The following are some examples of regular coding tasks that an IDE carries out.

6. Compilation
 An IDE compiles or converts the code into a simplified language that the operating system can understand.
Some programming languages implement just-in-time compiling, in which the IDE converts human-readable
code into machine code from within the application.

7. Testing
 The IDE allows developers to automate unit tests locally before the software is integrated with other
developers' code and more complex integration tests are run.

8. Debugging
 Debugging is the process of fixing any errors or bugs that testing reveals. One of the biggest values of an IDE
for debugging purposes is that you can step through the code, line by line, as it runs and inspect code
behavior. IDEs also integrate several debugging tools that highlight bugs caused by human error in real time,
even as the developer is typing.

Examples of IDE for C++


1. Code::Blocks
2. Dev-C++
3. Visual Studio Code (with C++ Extensions)
4. Geany
5. CLion (Educational License)

Writing First C++ Program – Hello World Example

C++ is a widely used Object Oriented Programming language and is relatively easy to understand. The “Hello World”
program is the first step towards learning any programming language and is also one of the most straightforward
programs you will learn.

The Hello World Program in C++ is the basic program that is used to demonstrate how the coding process works. All you
have to do is display the message “Hello World” on the console screen.

To write and run C++ programs, you need to set up the local environment on your computer. Refer to the complete
article Setting up C++ Development Environment. If you do not want to set up the local environment on your computer,
you can also use online IDE to write and run your C++ programs.

C++ Hello World Program


Below is the C++ program to print Hello World.
// C++ program to display "Hello World"

// Header file for input output functions


#include <iostream>
using namespace std;

// Main() function: where the execution of


// program begins
int main()
{
// Prints hello world
cout << "Hello World";

return 0;
}

Output:
Hello World

Working of Hello World Program in C++


Let us now understand every line and the terminologies of the above program.

1. // C++ program to display “Hello World”


This line is a comment line. A comment is used to display additional information about the program. A comment does
not contain any programming logic.

When a comment is encountered by a compiler, the compiler simply skips that line of code. Any line beginning with ‘//’
without quotes OR in between /*…*/ in C++ is a comment. Click to know More about Comments.

2. #include
This is a preprocessor directive. The #include directive tells the compiler to include the content of a file in the source
code.

For example, #include<iostream> tells the compiler to include the standard iostream file which contains declarations of
all the standard input/output library functions. Click to Know More on Preprocessors.

3. using namespace std


This is used to import the entity of the std namespace into the current namespace of the program. The statement using
namespace std is generally considered a bad practice. When we import a namespace we are essentially pulling all type
definitions into the current scope.

The std namespace is huge. The alternative to this statement is to specify the namespace to which the identifier belongs
using the scope operator(::) each time we declare a type. For example, std::cout.

4. int main() { }
A function is a group of statements that are designed to perform a specific task. The main() function is the entry point of
every C++ program, no matter where the function is located in the program.

The opening braces ‘{‘ indicates the beginning of the main function and the closing braces ‘}’ indicates the ending of the
main function. Click to know More about the main() function.

5. cout<<“Hello World”;
std::cout is an instance of the std::ostream class, that is used to display output on the screen. Everything followed by the
character << in double quotes ” ” is displayed on the output device. The semi-colon character at the end of the
statement is used to indicate that the statement is ending there.

6. return 0
This statement is used to return a value from a function and indicates the finishing of a function. This statement is
basically used in functions to return the results of the operations performed by a function.

7. Indentation
As you can see the cout and the return statement have been indented or moved to the right side. This is done to make
the code more readable. We must always use indentations and comments to make the code more readable.

Important Points
1. Always include the necessary header files for the smooth execution of functions. For example, <iostream> must
be included to use std::cin and std::cout.
2. The execution of code begins from the main() function.
3. It is a good practice to use Indentation and comments in programs for easy understanding.
4. cout is used to print statements and cin is used to take inputs.

You might also like