Structured Programming (4 Credits) HNDIT11034. Week 2 – Learning Outcomes Design an algorithmic solution for simple problem such as computation of a factorial,

Slides:



Advertisements
Similar presentations
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Advertisements

CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Lecture 2 Introduction to C Programming
Introduction to C Programming
 2005 Pearson Education, Inc. All rights reserved Introduction.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
Introduction to C++ September 12, Today’s Agenda Quick Review Check your programs from yesterday Another Simple Program: Adding Two Numbers Rules.
Software Development Method. Assignments Due – Homework 0, Warmup Reading – Chapter 2 –
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
Chapter 2: Introduction to C++.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Basic Input/Output and Variables Ethan Cerami New York
C programming Language and Data Structure For DIT Students.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Basic Elements of C++ Chapter 2.
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
Elements of a C++ program 1. Review Algorithms describe how to solve a problem Structured English (pseudo-code) Programs form that can be translated into.
CS107 Introduction to Computer Science Java Basics.
Computer Science 101 Introduction to Programming.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
End Show Writing a computer program involves performing the following tasks. 1. Understanding the problem 2. Developing an Algorithm for the problem 3.
Input, Output, and Processing
CHAPTER 2 PART #3 INPUT - OUTPUT 1 st semester King Saud University College of Applied studies and Community Service Csc
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Introduction to C Programming Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010 Fall.
Chapter 2: Java Fundamentals
Week 1 Algorithmization and Programming Languages.
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
THE BASICS OF A C++ PROGRAM EDP 4 / MATH 23 TTH 5:45 – 7:15.
Control Structures (B) Topics to cover here: Sequencing in C++ language.
1 Program Planning and Design Important stages before actual program is written.
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
COIT29222 Structured Programming 1 COIT29222-Structured Programming Lecture Week 02  Reading: Textbook(4 th Ed.), Chapter 2 Textbook (6 th Ed.), Chapters.
Programming Fundamentals
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
CHAPTER 2 PART #3 C++ INPUT / OUTPUT 1 st Semester King Saud University College of Applied studies and Community Service CSC1101 By: Fatimah.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
Course Title Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
Objective Write simple computer program in C++ Use simple Output statements Become familiar with fundamental data types.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
Intro. to Computer Programming Eng. Nehal A. Mohamed Spring Semester-2016.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
Basic concepts of C++ Presented by Prof. Satyajit De
C++ First Steps.
Programming what is C++
Chapter Topics The Basics of a C++ Program Data Types
Chapter 2 - Introduction to C Programming
Basic Elements of C++.
Objectives Identify the built-in data types in C++
Chapter 2 - Introduction to C Programming
Basic Elements of C++ Chapter 2.
Introduction to the C Language
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Chapter 2 - Introduction to C Programming
2.1 Parts of a C++ Program.
Introduction to C++ Programming
Chapter 2 - Introduction to C Programming
Programming Funamental slides
Chapter 2: Introduction to C++.
C programming Language
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
Chapter 1 c++ structure C++ Input / Output
Presentation transcript:

Structured Programming (4 Credits) HNDIT11034

Week 2 – Learning Outcomes Design an algorithmic solution for simple problem such as computation of a factorial, total of a series etc. using pseudo codes Identify Basic Structure of a C++ program Use comments in a program Familiar with the escape sequence characters

More flow chart examples “A” “B” “C” “S” “F” Draw a flow chart to input Average Marks and find the grade according to the grade System given below.

Input Avg If Avg>=75 If Avg>=65 If Avg>=55 If Avg>=45 Stop Start Display A Display B Display C Display S Yes No Display F

Pseudo Code One of the textual representation of algorithm is Pseudo code.

Begin Pseudo Code for adding two numbers End. Input first number and second number Total = first Number + Second Number output Total

Begin Input Maths Marks,Science Marks Total = Maths + Science Average = Total / 2 If Average >= 60 then Grade= “PASS” Else Grade= “FAIL” End if Display Total, Average, Grade End Write a pseudo code to take maths and science marks, calculate total, average and display grade. (If average >=60, “Pass” otherwise “Fail”.

“A” “B” “C” “S” “F” Write a pseudo code to input Average Marks and find the grade according to the grade System given below.

Begin Input Avg Mks If Avg >=75 then Grade = “A” Else If Avg >=65 then Grade =“ B” Else If Avg >=55 then Grade = “C” Else If Avg >= 45 then Grade =“ S” Else Grade = “W” End if Display Grade End

Begin Number=1 Do While Number <=10 Print Number Number=Number + 1 End while End Write a Pseudo code to display numbers from 1 to 10

A C++ program //include headers; these are modules that include functions that you may use in your program; we will almost always need to include the header that defines cin and cout; the header is called iostream.h #include void main() { //variable declaration //read values input from user //computation and print output to user } After you write a C++ program you compile it; that is, you run a program called compiler that checks whether the program follows the C++ syntax ◦ if it finds errors, it lists them ◦ If there are no errors, it translates the C++ program into a program in machine language which you can execute

When learning a new language, the first program people usually write is one that salutes the world Here is the Hello world program in C++. #include void main() { cout << “Hello world!”; }

The Standard output Statement cout << “Hello World”; The output operator, <<, is used to direct a value to the standard output device.

The statement: cout << “I am “ << var << “ years old.”; Can also be written as: cout << :”I am “; cout << var; cout << “years old.”; Or as: cout << “ I am “ << var << “years old.” var is a variable. When we want to display the content of a variable it should not written inside quotes.

Comment Entries You can place comment entries to provide clarity to the code. Comment entries are ignored by the compiler and are meant to describe the code. Comments can be written between /* and */, or can be preceded by a //.

ESCAPE SEQUENCES ESCAPE SEQUENCE NAMEDESCRIPTION \aBell (alert)Make a sound from computer \bBackspaceTakes the cursor back \tHorizontal tabTakes the cursor to the next tab position \nNew lineTakes the cursor to tne beginning of the next line \rCarriage return Cause a carriage return \”Double quotesDisplays a quotation mark \\BackslashDisplays a back slash \?Question markDisplays a question mark

Variable Types A variable type is a description of the kind of information a variable will store. Programming languages vary regarding how strict they require you to be when declaring a variable's type. Some languages, like Perl, python,do not require you to announce the type o fa variable. Other languages require you to declare some variables as numbers and others as text-strings, for example. C++, a strongly typed language, requires you to be even more specific than that. Instead of declaring a variable as a number, you must say whether it will store integers or decimals

Rules for Naming Identifiers in C++ The name of an identifier needs to be without any embedded space or symbols such as ? ! - # & () [] {}. However, underscores can be used wherever a space is required. Identifier names must be unique. An identifier name can have any number of characters. An identifier name must begin with a letter or an underscore (‘-‘), which may be followed by a sequence of letters, digits (0-9), or ‘-‘. The first character in an identifier name cannot be a digit. Starting an identifier with an underscore is not recommended. Keywords cannot be used as identifiers. Example : main, include, int, float etc.

Q & A