Objectives Identify the built-in data types in C++

Slides:



Advertisements
Similar presentations
C Language.
Advertisements

ARDUINO CLUB Session 1: C & An Introduction to Linux.
Introduction to C Programming
 2005 Pearson Education, Inc. All rights reserved Introduction.
Guide To UNIX Using Linux Third Edition
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
C++ fundamentals.
Introduction to C Topics Compilation Using the gcc Compiler
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.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Input, Output, and Processing
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
Chapter 2. C++ Program Structure C++ program is a collection of subprograms Subprograms in C++ are called FUNCTIONS Each function performs a specific.
C++ Programming: Basic Elements of C++.
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
Structured Programming (4 Credits) HNDIT Week 2 – Learning Outcomes Design an algorithmic solution for simple problem such as computation of a factorial,
C++ for Engineers and Scientists Second Edition
Chapter 2: Basic Elements of C++. Introduction Computer program – Sequence of statements whose objective is to accomplish a task Programming – Process.
Introduction to C Programming
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
C LANGUAGE UNIT 3. UNIT 3 Arrays Arrays – The concept of array – Defining arrays – Initializing arrays.
A FIRST BOOK OF C++ CHAPTER 7 ARRAYS. OBJECTIVES In this chapter, you will learn about: One-Dimensional Arrays Array Initialization Arrays as Arguments.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 3: Input/Output Samples.
Bill Tucker Austin Community College COSC 1315
Basic concepts of C++ Presented by Prof. Satyajit De
C++ First Steps.
Chapter 1.2 Introduction to C++ Programming
TK1913 C++ Programming Basic Elements of C++.
Chapter 2: Basic Elements of C++
Review 1.
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1.2 Introduction to C++ Programming
Topics Designing a Program Input, Processing, and Output
Chapter 7 Pointers and C-Strings
Chapter 1.2 Introduction to C++ Programming
Chapter 2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
BASIC ELEMENTS OF A COMPUTER PROGRAM
Completing the Problem-Solving Process
Yanal Alahmad Java Workshop Yanal Alahmad
Computing Fundamentals
Basic Elements of C++.
Objectives State the reasons for the complexity involved in the development of software Define the following terms Objects Classes Messages Methods Explain.
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Revision Lecture
Introduction to C++.
C language IT-1 (Batch-A) Name: EnNo: Arshad Muthalif
Chapter 2: Basic Elements of C++
C++ for Engineers and Scientists Second Edition
Basic Elements of C++ Chapter 2.
Visit for more Learning Resources
Introduction to the C Language
Chapter 2 Elementary Programming
2.1 Parts of a C++ Program.
CS150 Introduction to Computer Science 1
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
Chapter # 2 Part 2 Programs And data
elementary programming
Chapter 2: Introduction to C++.
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Course Outcomes of Programming In C (PIC) (17212, C203):
Getting Started With Coding
Presentation transcript:

Objectives Identify the built-in data types in C++ Use variables in C++ programs Write and execute C++ programs Use arrays in C++ programs

Variables Are Named locations in memory that contain specific values Rules for naming variables in C++ Should not have any embedded spaces or symbols Should be unique Can have any number of characters Must begin with a letter or an underscore, which may be followed by a sequence of letters, digits, or underscores Keywords cannot be used as variable names

Data Types Define the type of data that can be stored in a variable Built-in data types are: char - For characters and strings int - For integers float - For numbers with decimals

Data Types (Contd.)

Member Variables Are used to implement attributes in C++ Are declared inside the class body Example: class Car { float price; };

Accepting and Storing Values in Member Variables The cin object is used to accept input from the user Example: class Car { float price; public: void acceptprice() cout << “Enter Price :”;cin >> price; } };

Writing and Executing a C++ Program The iostream header file Is called a pre-processor directive The main() function Is mandatory in C++ programming for program execution Creating objects Is required for reserving memory at the time of declaration

Compiling, Linking, and Executing a Program Is done by following the listed steps: 1. The C++ program should contain the #include statement, the class declaration and member function definition, and the main() function. 2. Save the file with a .cc extension. 3. Compile the file using the g++ <file name> command from the Linux prompt. 4. Execute the file using the a.out command from the Linux prompt.

Executing C++ Programs a.out executes the initial startup code The startup code executes the main() function When the main() function finishes execution, it sends a status of execution to the operating system

Array Is a collection of elements of a single data type stored in adjacent memory locations Syntax: <data_type> <variable_name>[<dimension_size>]; Example: int arr[5];

Declaring and Initializing an Array Example: arr[0] = 14; arr[1] = 15; arr[2] = 17; arr[3] = 45; arr[2] = 81; int arr[5] = {14, 15, 17, 45, 81}; int arr[] = {14, 15, 17, 45, 81};

Declaring and Initializing an Array (Contd.) Size of an array should be specified at the time of its declaration Example: char err[]; //ERROR!! will not compile An array cannot be initialized with another array xyz = abc; // ERROR!!

String Constant Is an array of characters terminated by a NULL(‘\0’) Example: char str[] = "SANDY"; Can be schematically represented as:

Problem Statement As a member of a team that is developing the billing system software for Diaz Telecommunications Inc., you have been assigned the task of creating a software module that accepts the following customer details and displays it. 1.Mobile number, containing a maximum of 12 characters 2. Name, containing a maximum of 25 characters 3. Date of birth, containing a maximum of 10 characters 4. Billing address, containing a maximum of 50 characters

Problem Statement (Contd.) 5. City, containing a maximum of 25 characters 6. Residence phone number, containing a maximum of 13 characters. 7. Amount outstanding, containing decimal values

Summary In this lesson, you learned that: A variable is a named location in memory that contains a specific value A data type defines the type of data that can be stored in a variable Member variables are declared inside the class body The cin object is used to accept input from the keyboard The contents of header files are inserted into a program with the #include directive The C++ program execution starts from the first statement of the main()function

Summary (Contd.) Comment entries are notes that a programmer writes anywhere in the code so that any programmer reading the code will understand it better An object is an instance of a class The compiler is a software that translates a program written in a language like C++ into machine language and the file containing the translated program is called the object code of your program Linking combines your object code with the object code of the functions you use and adds some standard startup code to produce a run-time version of your program

Summary (Contd.) The Linux-based GNU compiler for C++ generates the executable code and stores it in a file named a.out An array is a collection of elements of a single data type stored in adjacent memory locations The array can be initialized when it is defined or later An array must be given a constant dimension size, which should be at least 1 Each element of an array can be accessed by its subscript number