0% found this document useful (0 votes)
2 views18 pages

Introduction to Programming

The document introduces programming concepts, emphasizing the importance of problem-solving and understanding the computer's language. It covers the basics of creating a program, including input and output, data types, variables, and basic input/output functions in C programming. Additionally, it provides instructions for setting up a project in C Lion and writing a simple 'Hello, World!' program.

Uploaded by

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

Introduction to Programming

The document introduces programming concepts, emphasizing the importance of problem-solving and understanding the computer's language. It covers the basics of creating a program, including input and output, data types, variables, and basic input/output functions in C programming. Additionally, it provides instructions for setting up a project in C Lion and writing a simple 'Hello, World!' program.

Uploaded by

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

MOD003212

Introduction to
Programming Week
1
Dr. Razvan-Ioan “Raz” Dinita
[email protected]
Programming In General
• Programming means:
• Finding a solution to a problem
• Expressing that solution in such a way that a
computer can do it
• Therefore:
• You must understand the problem and its solution
yourself
• Only then can you instruct the computer how to do it
• You must speak the language of the computer; it
doesn’t understand English
Programming In General

• Is programming hard?
• No, but...
• Requires practice – A “perishable” skill
• Requires attention to detail
• Lots of concepts to learn in the
beginning
Programming In General
• “Nothing is
particularly hard if
you divide it into
small jobs” –
Henry Ford
What is a Program?

• A set of instructions for processing


inputs to generate outputs

Input Process Output


Example Inputs

• Keyboard
• Joystick/Gamepad
• Sensor (e.g. accelerometer)
• Other program
• File
• Camera
Example Outputs

• Screen (Text, Graphics etc.)


• File
• Printer
• Force Feedback
• Special hardware (Valves, relays etc.)
• Other programs
C Lion Projects
• When creating a new project, click on New Project and, on the left-hand side, select C
Executable (NOT C++)
• The name of the project will come from the folder name – please DO NOT include any
spaces in the name (see below)!
• If working on your own personal PC/Laptop, then choose a Location (by clicking the folder
icon next to the Location field) that you can find
• If working on an ARU university machine, then choose the following location:
• C:\Users\YOUR_LOGIN_USER_ID\AppData\Local\Development\Year1\ITP \
ProjectName
• (replace YOUR_LOGIN_USER_ID with the first part of your ARU login email e.g.
abc123)
• Development folder needs to be created first time, only once
• So do Year1 and ITP
• (replace ProjectName with the purpose of the project i.e. CarSales or HelloWorld or
Week3 etc.)
• Select the C11 Language standard (should be automatically selected for you)
• Click Create.
• Note: The first ever time you create a C Lion project, it will ask you to confirm the compiler
options – everything should be left as it appears on screen – just click OK.
• A new window will appear – locate main.c on the left-hand side and double-click on it
• You’re now ready to start writing some code!
Hello, World!
• Line 1: #include <libraryName.h>
• imports sets of tools (libraries) from outside
our program to enable us to write less and do
more
• stdio.h is such a library that enables us to
work with standard input/output a.k.a. the
keyboard for input and command prompt
(console) for output in our case
• Line 3: int main() { … }
• the starting point of our program, it must exist
in our main.c file, written exactly as shown
here
• The purpose of a Hello, World!
• any line of code we write for our program, at
program is to show us what a basic
least for now, will happen within the two program looks like in the chosen
curly brackets { } language (C language in our case),
• Line 4: printf(“Hello, World!\n”); what the basic syntax is (the simplest
• printf is a tool, part of the stdio.h library, that program that is valid, compiles, and
allows us to write text to the console window
runs), and how we can output some
(command prompt)
text to whatever output we’re able to
• Line 5: return 0;
use (in this case, the Console a.k.a.
• This tells the computer that the program has
finished without any errors – anything other Command Prompt)
than 0 here would mean that the program
finished with some kind of issue/error. Most
times, you’ll want to leave it as it is.
Statements

• A command to be carried out by the


computer
• Declaration of a variable
• Assignment of a value
• Calling of a procedure/function
• A single line of code ending in ;
• A block of single line statements within
a pair of curly brackets { }
Flow of Execution

• Sequentially – do this, do that, do this


other thing, etc. .....
• Selectively – do this if it’s before
lunchtime, do this other thing if it’s after
lunchtime
• Iteratively – if it’s not lunch time, do this
until it is lunchtime
Sequence in C programming
• By default, each line of code is executed one at a
time.
Data Types I: Integer Types
• int
• it can hold whole numbers between -231 and 231
• short
• it can hold whole numbers between -215 and 215
• long
• it can hold whole numbers between -263 and 263
• char
• it can hold whole numbers between 0 and 255
• each number also represents a character, like the
ones on your keyboard, e.g. 65 represents A
Variables aka Data Containers
• dataType variableName = initialValue;
• The above is the structure of a statement for creating a
variable (data container) within a C program
• Variables are data containers that exist purely for the purpose
or remembering bits of data, such as numbers, text, etc.
• The dataType is one of int, short, long, char, etc. (others will
follow in future weeks)
• The variableName is a descriptor in English, only containing
letters, numbers, and underscores (but it must NOT start with
a number)
• initialValue is a value that the variable will hold at the
moment that line e.g.: 5 (int), ‘A’ (char), etc.
Basic Input
• scanf(“format”, &variable)
• a statement/tool used to capture input from the standard/default
input (in our case, the keyboard)
• when the program runs this statement, it pauses and waits for the
user to type in some data
• “format” can have many forms, but it essentially represents the
kind of input the program should be expecting from the keyboard,
like “%d” to capture int type data:

• please note that the ampersand & is required, otherwise scanf will
not be allowed to change the contents of the variable
• other relevant formats
• %hd – captures short type data
• %ld – captures long type data
• %c – captures char type data
• (more formats will follow in future weeks)
Basic Output
• printf(“format”, variable)
• a statement/tool used to output text to the standard/default output
(in our case, the console window)
• The console window is a window that pops up when we run our
programs from Visual Studio. We can see the result of our
programming efforts within them. Only text outputted with printf will be
visible here.
• when the program runs this statement, it writes/outputs to the
console window whatever the “format” tells it to
• “format” can have many forms, but it essentially is a mix of English
and placeholders, the same ones used in scanf (see previous slide)
• optionally, within the text, the newline character \n may be used to
push the text that will follow it to the next line in the console window
• the % placeholders (like %d) are replaced with the data contained
within the variable at the time the printf statement runs:
Basic Input and Output Example
• // represents a single line comment, it is ignored by the program
Basic Input and Output Example
• Output of the example program

You might also like