1 Special Programming Workshop CSIT-120 Fall 2000 Workshop Targets Solving problems on computer Programming in C++ Writing and Running Programs Programming.

Slides:



Advertisements
Similar presentations
Variables in C Amir Haider Lecturer.
Advertisements

Introduction to Programming in C++ John Galletly.
Computer and Programming
Principles of Programming Fundamental of C Programming Language and Basic Input/Output Function 1.
True or false A variable of type char can hold the value 301. ( F )
1 Lab Session-VI CSIT-120 Fall 2000 Let us look at C++ syntax rules in brief Next, we complete the lab session-V Lab session-VI deals with functions (OPTIONAL)
Chapter 3 Assignment and Interactive Input. 2 Objectives You should be able to describe: Assignment Operators Mathematical Library Functions Interactive.
1 Lecture-4 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
1 Lab-1 CSIT-121 Spring 2005 Lab Targets Solving problems on computer Programming in C++ Writing and Running Programs Programming Exercise.
1 Lab 2 CSIT-120 Spring 2001 Session II-A (Feb 13th) Operations on Data Lab Exercise 2-A Data Types Variables Lab Exercise 2-B Session II-B (Feb 20th)
1 Session-I & II CSIT-121 Spring 2006 Session Targets Introducing the VC++.NET Solving problems on computer Programming in C++ Writing and Running Programs.
1 Lab Session-VI CSIT-120 Spring 2001 Let us look at C++ syntax rules in brief Exercise VI-A (Demo Required) Lab Assignment#4 Due May 1st, 2001 (No Lab.
1 Lab Session-I CSIT120 Spring2001 Using Windows Using An Editor Using Visual C++ Using Compiler Writing and Running Programs Lab-1 continues (Session.
1 Lab-1 CSIT-121 Fall 2004 Lab Targets Solving problems on computer Programming in C++ Writing and Running Programs Programming Exercise.
Computer Science 1620 C++ - Basics. #include using namespace std; int main() { return 0; } A very basic C++ Program. When writing your first programs,
1 Lab 2 CSIT-120 Fall 2000 Session II-A (September 14th) Operations on Data Lab Exercise 2-A Data Types Variables Lab Exercise 2-B Session II-B (September.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Data representation and Data Types Variables.
Chapter 2 : Overview of C By Suraya Alias. /*The classic HelloWorld */ #include int main(void) { printf(“Hello World!!"); return 0; }
Chapter 3 COMPLETING THE BASICS Programming Fundamentals with C++1.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Chapter 8 Friends and Overloaded Operators. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. Slide 2 Overview Friend Function (8.1) Overloading.
Input, Output, and Processing
Chapter 2: Using Data.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
M.T.Stanhope Oct Title : C++ Basics Bolton Institute - Faculty of Technology (Engineering) 1 C++ Basics u Data types. u Variables and Constants.
C++ Programming: Basic Elements of C++.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Fundamental Programming: Fundamental Programming Introduction to C++
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Lecture #6 OPERATORS AND ITS TYPES By Shahid Naseem (Lecturer)
02 Variables1November Variables CE : Fundamental Programming Techniques.
Control Structures (B) Topics to cover here: Sequencing in C++ language.
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
COIT29222 Structured Programming 1 COIT29222-Structured Programming Lecture Week 02  Reading: Textbook(4 th Ed.), Chapter 2 Textbook (6 th Ed.), Chapters.
PROGRAM ESSENTIALS. TOKENS  SMALLEST UNITS OF A PROGRAM LANGUAGE  Special Symbols  Mathematical Operators  Punctuation  Word Symbols  Key Words.
Programming Fundamentals with C++1 Chapter 3 COMPLETING THE BASICS.
CHAPTER 2 PART #3 C++ INPUT / OUTPUT 1 st Semester King Saud University College of Applied studies and Community Service CSC1101 By: Fatimah.
1 09/03/04CS150 Introduction to Computer Science 1 What Data Do We Have.
12/14/2016CS150 Introduction to Computer Science 1 Announcements  Website is up!   All lecture slides, assignments,
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 3: Input/Output Samples.
Bill Tucker Austin Community College COSC 1315
BASIC ELEMENTS OF A COMPUTER PROGRAM
CS1001 Programming Fundamentals 3(3-0) Lecture 2
ICS103 Programming in C Lecture 3: Introduction to C (2)
Design & Technology Grade 7 Python
Lecture2.
Introduction to C++ Programming
Programming Funamental slides
Lecture3.
CS150 Introduction to Computer Science 1
Chapter 2: Introduction to C++.
Introduction to C Programming
Primitive Types and Expressions
An Overview of C.
Variables in C Topics Naming Variables Declaring Variables
DATA TYPES There are four basic data types associated with variables:
Chapter 1 c++ structure C++ Input / Output
Variables and Constants
Presentation transcript:

1 Special Programming Workshop CSIT-120 Fall 2000 Workshop Targets Solving problems on computer Programming in C++ Writing and Running Programs Programming Exercise

2 Targets We wish to learn how to program We know how to edit a program, compile it and run it We know how to launch Visual C++ integrated environment Let us work on most fundamental aspects of programming in C++

3 Programming Fundamentals We have a real life problem that is to be solved on the computer In order to solve it, we need to write a program The program must be written using the syntax rules of Visual C++

4 Example Problem A problem is given as follows: “Given several distances in kilometers, we wish to see the same in miles.” Given this problem, let us first design a program that will convert only one given distance into miles. We can change it later to let it convert several given distances into miles

5 Strategy to solve the problem How would you solve this problem with paper and pencil? (Conversion Factor 1 mile = 1.6km)

6 Solving through programming We will use C++ syntax to solve this problem on the computer We first need to know the total number of data items in this problem and their type TOTAL DATA ITEMS

7 Solution on paper Next we should solve it on paper. The solution on paper is called an algorithm Initial Algorithm Read the distance in kilometers Convert it to miles Display the distance in miles Now refine this algorithm

8 Refined Algorithm

9 How to implement in C++? The big question is how to implement this solution in C++? First part is to express the distance value in C++ C++ provides data types to capture our real life data into programs For numbers, we can have whole numbers such as 19 or FP numbers such as 19.63

10 How to express numbers in C++? For whole numbers, we have data type int in C++ For example, we can declare int distancekm; (We have declared a data item called distancekm that is a whole number) Now, we need another data item to represent distance in miles

11 How to express numbers in C++ The distance in miles could contain fractional part because conversion factor has a fractional part We need a data format that can accept a FP number into it C++ provides float and double float distancemiles;

12 Variables and Constants If you can change the value of a data item in your program, it is known as a variable. If you cannot change the value of a data item in your program, it is a constant. Can you change the value of the conversion factor between miles and kilometers? How to show constant data items?

13 Constant Data Items For constant data items, just add the keyword const before their declaration For example, const float ConversionFactor=1.6; (Please notice the “initialization” of the data item with a specific value)

14 Basic Template to Start a Program #include void main() { ::: }

15 Template Description –#include This line tells the system to include pre- defined I/O capability so that we can use the keyboard and screen

16 Template Description –void main(void) This line gives the name of the function that you are developing. main() is the default name used for the main function of any program Function is a block of code that performs a given task. A function carries a name and opening and closing braces

17 Program Development Phase-I In phase-I, we should put our declarations of data items into the template Let us do it now:

18 Basic Template to Start a Program #include void main() { int distancekm; float distancemiles; const float ConversionFactor=1.6; } Please note the semicolons after each declaration

19 Phase-II: Action part Once we capture our data into data items, we need to perform the actual conversion from kilometers to miles First we should read the kilometers from the keyboard cout<<“Give the distance in kilometers”; cin>>distancekm;

20 PhaseII: Action part cout<< is the way to display your data on the screen cin>>variable_name is the way to read data from the keyboard and assign it to one variable in the program

21 Q&A Why is included in the program source code? Why do we name the only function in our program as main()? What is the use of opening braces and closing braces in the program? What is the difference between variables and constants? What does cout<< do? Why do we put semicolons at the end of each statement?

22 Our Program so far…. #include void main() { int distancekm; float distancemiles; const float ConversionFactor=1.6; cout<<“Give the distance in kilometers”; cin>>distancekm }

23 Phase II continues Now we have read the distance in kilometers. Next, our program should convert it into miles using the conversion factor It is here that we should design an “assignment statement”

24 Phase II continues Here, we are dividing the distance in kilometers by the conversion factor and getting the result as distance in miles distance_in_miles = distance_in_km/1.6 This arithmetic expression can be written in C++ using an assignment statement distancemiles=distancekm/ConversionFactor;

25 Rules of Assignment Statement In C++, you will use the destination variable on left of the equal sign You cannot use a constant data item on left of the equal sign You should not assign a FP value to an integer variable Doing so will cause the loss of fractional part

26 Complete Program #include void main() { int distancekm; float distancemiles; const float ConversionFactor=1.6; cout<<“Give the distance in kilometers”; cin>>distancekm; distancemiles=distancekm/ConversionFactor; cout<<“Here is distance in miles”; cout<<distancemiles; }

27 Programming Exercise Write a program that accepts the age and weight of your cat. Then it shows the age and weight to the user and the meows of the cat are printed as “meow meow” on the screen