GETTING STARTED WITH C++ C++ BASICS - 1 -

Save this PDF as:
 WORD  PNG  TXT  JPG

Size: px
Start display at page:

Download "GETTING STARTED WITH C++ C++ BASICS - 1 -"

Transcription

1 - 1 - GETTING STARTED WITH C++ Programming is a core activity in the process of performing tasks or solving problems with the aid of a computer. An idealised picture is: PROBLEM COMPUTER SOLUTION Unfortunately things are not that simple. In particular, the PROBLEM" cannot be given to the computer using natural language. A computer cannot understand our language thatt we use in our day to day conversations, and likewise, we cannot understand the binary language that the computer uses to do its tasks Moreover, it has to contain information about how the problem is to be solved or the task is to be executed. Hence we need programming languages. C++ is a programming language which includes facilities for object-oriented programming, as well as for more conventional procedural programming. C++ was developed by Bjarne Stroustrup of AT&T Bell Laboratories in the early 1980's, and is based on the C language. COMPILATION AND LINKING OF C++ PROGRAM C++ BASICS C++ CHARACTER SET Character set is a set of valid language can recognize. Letters Digits Spac Special Characters { = %! Formatting characters TOKENS A token is the smallest element of a C++ program that is meaningful to the compiler. As in the English language, in a paragraph all the words, punctuation mark and the blank spaces are called Tokens. Similarly in a C++ program all the C++ statements having Keywords, Identifiers, Constants, Strings, Operators and the Special Symbols are called C++ Tokens. The programmer can write a program by using tokens. C++ uses the following types of tokens: Keywords, Identifiers, Literals, Punctuators, Operators 1. Keywords Keywords are reserved words. They have some specific meaning and are used for some specific task. The interpreter uses keywords to recognize the structure of the program, and they cannot be used as variable names. Some commonly used Keywords are given below: asm auto break case characters that a A-Z, a-z 0-9 ce + - * / ^ \ () [] =!= <> $, ; :! &?_ # <= backspace, horizontal tab, vertical tab, form feed, and carriage return catch char class const continue delete do double else extern inline int float friend goto if long operator private protected public return short signed sizeof struct switch template this typedef union unsigned virtual default enum for new register static Try void volatile while 2. Identifiers Symbolic names can be used in C++ for various data items used by a programmer in his program. A symbolic name is generally known as an

2 - 2 - something. The identifier is a sequence of characters taken from C++ character set. The rules for the formation of an identifier are: An identifier can consist of alphabets, digits and/or underscores. It must not start with a digit C++ is case sensitive that is upper case and lower case letters are considered different from each other. It should not be a reserved word. Examples of valid identifier names are i, my_name, name_23. Examples of invalid identifier names are 2things, S I, my-name, S.I., switch, sum. Programmer can choose the name of identifier whatever they want. However, if the programmer choose meaningful name for an identifier, it will be easy to understand and work on, particularly in case of large program. 3. Literals Literals (often referred to as constants) are data items that never change their value during the execution of the program. The following types of literals are available in C++. Integer-Constants Character-constants Floating-constants Strings-constants Integer Constants Integer constants are whole number without any fractional part. C++ allows three types of integer constants. Decimal integer constants : It consists of sequence of digits and should not begin with 0 (zero). For example 124, - 179, Octal integer constants: It consists of sequence of digits starting with 0 (zero). E.g. 014, 012. Hexadecimal integer constant: It consists of sequence of digits preceded by ox or OX. Character constants: A character constant in C++ must contain one or more characters and must be enclosed in single quotation marks. For example 'A', '9', etc. C++ allows non graphic characters which cannot be typed directly from keyboard, e.g., backspace, tab, carriage return etc. These characters can be represented by using an escape sequence. An escape sequence represents a single character. The following table gives a listing of common escape sequences. Escape Sequence Non-graphic Character \a Bell (beep) \n Newline \r Carriage Return \t Horizontal tab \0 Null Character Floating constants They are also called real constants. They are numbers having fractional parts. They may be written in fractional form or exponent form. A real constant in fractional form consists of signed or unsigned digits including a decimal point between digits. For example 3.0, -17.0, etc. String Literals A sequence of character enclosed within double quotes is called a string literal. String literal is by default (automatically) added with a special character \0' which denotes the end of the string. Therefore the size of the string is increased by one character. For example "COMPUTER" will re represented as "COMPUTER\0" in the memory and its size is 9 characters. 4. Punctuators The following characters are used as punctuators in C++: Brackets [ ] Opening and closing brackets indicate single and multidimensional array subscript. Parentheses ( ) Braces { Comma, Semicolon ; Colon : Asterisk * Equal sign = Opening and closing brackets indicate functions calls,; function parameters for grouping expressions etc. Opening and closing braces indicate the start and end of a compound statement. It is used as a separator in a function argument list. It is used as a statement terminator. It indicates a labeled statement or conditional operator symbol. It is used in pointer declaration or as multiplication operator. It is used as an assignment operator. Pound sign # It is used as pre-processor directive. 5. Operators Operators are special symbols used for specific purposes. Some important types of operators are: Arithmetical operators, Relational operators, Logical operators, Unary operators, Assignment operators, Conditional operators, Comma operator.

3 - 3 - DATA HANDLING BASIC DATA TYPES C++ supports a large number of data types. The built in or basic data types supported by C++ are integer, floating point and character. These are summarized in table along with description and memory requirement Type Byte Range Description int to Small whole number long int to Large whole number float 4 3.4x10-38 to 3.4x10+38 Small real number double 8 1.7x to 1.7x Large real number long double x to 3.4x Very Large real number char 1 0 to 255 A Single Character VARIABLES Variables are memory location in computer's memory to store data. To indicate the memory location, each variable should be given a unique name called identifier. Variable names are just the symbolic representation of a memory location. Examples of variable name: sum, car_no, count etc. To understand more clearly we should study the following statements: Total = 20.00; In statement a value has been stored in a memory location Total. Before a variable is used in a program, it has to be defined. This activity enables the compiler to make available the appropriate type of location in the memory. The definition of a variable consists of the type name followed by the name of the variable. For example, a variable Total of type float can be declared as shown below: float Total; INPUT/OUTPUT (I/O) C++ supports input/output statements which can be used to feed new data into the computer or obtain output on an output device such as: VDU, printer etc. It provides both formatted and unformatted stream I/O statements. The following C + + streams can be used for the input/output purpose. Stream Description cin console input cout console output In addition to the above I/O streams, two operators <<and >>are also used. The operator << is known as put to or bit wise shift operator. The operator>> is known as extraction or get from operator. cout << My first computer"; Once the above statement is carried out by the computer, the message "My first computer" will appear on the screen. cin is the standard input stream (keyboard) and it can be used to input a value entered by the user from the keyboard. However, the get from operator>> is also required to get the typed value from cin and store it in the memory location. Let us consider the following program segment: int marks; cin >> marks; In the above segment, the user has defined variable marks of integer type in the first statement and in the second statement he is trying to read a value from the keyboard. TYPE CONVERSION Converting an expression from one data type to another is known as type-conversion. There are two types of conversion in C Implicit conversion (Type Promotion) 2. Explicit conversion (Type Casting) Implicit conversion Data type can be mixed in the expression. For example double a; int b = 5; float c = 8.5; a = b * c; When two operands of different type are encountered in the same expression, the lower type variable is converted to the higher type variable. An implicit conversion is performed automatically by the compile when an expression needs to be converted into one of its compatible types. The following table shows the order of data types. DATA TYPE long double double float long int char Order of data types ORDER (highest) To (lowest) The int value of b is converted to type float and stored in a temporary variable before being multiplied by the float variable c. The result is then converted to double so that it can be assigned to the double variable a.

4 - 4 - Explicit conversion It is also called type casting. It temporarily changes a variable data type from its declared data type to a new one. It may be noted here that type casting can only be done on the right hand side of the assignment statement. T_Pay = double (salary) + bonus; Initially variable salary is defined as float but for the above calculation it is first converted to double data type and then added to the variable bonus. Explicit type conversion is a type conversion which is explicitly defined within a program (instead of being done by a compiler for implicit type conversion). CONSTANTS A number which does not change its value during execution of a program is known as a constant. Any attempt to change the value of a constant will result in an error message. A constant in C++ can be of any of the basic data types, const qualifier can be used to declare constant as shown below: const float pi = ; The above declaration means that Pi is a constant of float types having a value Examples of valid constant declarations are: const int rate = 50; const char ch = 'A'; STRUCTURE OF C++ PROGRAM The structure of a C++ program is given below: #include<header file> void main () { A C++ program starts with function called main ( ). The body of the function is enclosed between curly braces. The program statements are written within the braces. Each statement must end by a semicolon; (statement terminator). A C++ program may contain as many functions as required. However, when the program is loaded in the memory, the control is handed over to function main ( ) and it is the first function to be executed. // This is my first program is C++ /* this program will illustrate different components of a simple program in C++ */ # include <iostream.h> void main ( ) {cout <<"This is my first program in C++"; cout << "\n"; When this program is compiled, linked and executed, the following output is displayed on the VDU screen. This is my first program in C++ Various components of this program are discussed below: COMMENTS Comments are lines of code which are ignored by the compiler. Comments are included in a program to make it more readable. If a comment is short and can be accommodated in a single line, then it is started with double slash sequence in the first line of the program. For example: //Program to find Simple Interest However, if there are multiple lines in a comment, it is enclosed between the two symbols /* and */ For example: /* this program will illustrate different components of a simple program in C++ */ Use as many useful comments as you can in your program to: explain assumptions explain important decisions explain important details explain problems you re trying to solve explain problems you re trying to overcome in your program, etc. Code tells you how, comments should tell you why This is useful for readers of your program so that they can easily understand what the program is doing. Remember, that person can be you after six months! include <iostream.h> The lines in the above program that start with symbol # are called directives and are instructions to the compiler. The word include with '#' tells the compiler to include the file iostream.h into the file of the above program. File iostream.h is a header file needed for input/ output requirements of the program. Therefore, this file has been included at the top of the program. void main ( ) The word main is a function name. The brackets ( ) with main tells that main ( ) is a function. The word void before main ( ) indicates that no value is being returned by the function main (). When program is loaded in the memory, the control is handed over to function main ( ) and it is the first function to be executed.

5 - 5 - The curly brackets and body of the function main ( ) A C++ program starts with function called main(). The body of the function is enclosed between curly braces. The program statements are written within the brackets. Each statement must end by a semicolon, without which an error message in generated. SOME IMPORTANT TERMS Syntax error - The errors which are traced by the compiler during compilation, due to wrong grammar for the language used in the program, are called syntax errors. For example, cin<<a; // instead of extraction operator insertion operator is used. Run time Error - The errors encountered during execution of the program, due to unexpected input or output are called run-time error. For example - a=n/0; // division by zero Logical Error - These errors are encountered when the program does not give the desired output, due to wrong logic of the program. For example : remainder = a+b // instead of using % operator + operator is used. The preprocessor directive #include tells the complier to insert another file into your source file. In effect, #include directive is replaced by the contents of the file indicated. Compiler - It is a program which converts the program written in a programming language to a program in machine language. Linker - It is a program which links a complied program to the necessary library routines, to make it an executable program. Why char is considered as numeric data type? The memory implementation of char data type is in terms of the number code. Therefore, it is said to be another integer data type. Type Promotion: When two operands of different data types are encountered in the same expression, the variable of lower data type is automatically converted to the data types of variable with higher data type, and then the expression is calculated. For example: int a=98; float b=5; cout<<a/3.0; //converts to float type, since 3.0 is of float type. cout<<a/b; // converts a temporarily to float type, since b is of float type, and gives the result automatic type conversions. This can be done when the compiler does not do the conversions automatically. Type casting can be done to higher or lower data type. For example : cout<<(float)12/5; //displays 2.4, since 12 is converted to float type. Remember the type Promotion is performed by the compiler but a casting is done by the user Importance of main(): Whenever a C++ program is executed, execution of the program starts and ends at main(). The main is the driver function of the program. If it is not present in a program, no execution can take place. LAB EXERCISES - 1 LE 1.1 Write a program to find area and perimeter of a rectangle taking length as 10 and breadth as 20. LE 1.2 Write a program to find area and perimeter of a rectangle taking length and breadth from the user using input () function. LE 1.3 Write a program to convert Centigrade into Fahrenheit and vice versa. LE 1.4 Write a program to find lateral surface area, total surface area and volume of a cuboid. Take Length, Breadth and Height from the user using input () function. LE 1.5 Write a program to find lateral surface area, total surface area and volume of a Cone. Take Radius and Height from the user using input () function. LE 1.6 Write a program to find simple interest and compound interest. Take principal, rate and time from the user using input () function. LE 1.7 Write a program to swap two variables using a third variable. LE 1.8 Write a program to swap two variables without using a third variable. Type casting refers to the data type conversions specified by the programmer, as opposed to the

6 - 6 - OPERATORS Operators are special symbols used for specific purposes. C++ provides six types of operators. Arithmetical operators, Relational operators, Logical operators, Unary operators, Assignment operators, Conditional operators, Comma operator Arithmetical operators An operator that performs an arithmetic (numeric) operation: +, -,*,/, or %. For theseoperations always two or more than two operands are required. Therefore these operators are called binary operator. Relational operators The relational operators are used to test the relation between two values. All relational operators are binary operators and therefore require two operands. A relational expression returns zero when the relation is false and a nonzero when it is true. The following table shows the relational operators: Relational Meaning Operators < Less than <= Less than or equal to == Equal to > Greater than >= Greater than or equal to! = Not equal Logical operators The logical operators are used to combine one or more relational expression. The logical operators are Operators Meaning OR && AND! NOT Unary operators C++ provides two unary operators for which only one variable is required. For Example a = - 50; a = + 50; Here plus sign (+) and minus sign (-) are unary because they are not used between two variables. Assignment operator The assignment operator '=' stores the value of the expression on the right hand side of the equal sign to the operand on the left hand side. Example int m = 5, n = 7; int x, y, z; x = y = z = 0; in addition to standard assignment operator shown above, C++ also support compound assignment operators. Compound Assignment Operators C++ provides two special operators viz '++' and '--' for incrementing and decrementing the value of a variable by 1. The increment/decrement operator can be used with any type of variable but it cannot be used with any constant. With the prefix version of these operators, C++ performs the increment or decrement operation before using the value of the operand For instance the following code: int sum, ctr; sum = 12; ctr = 4; sum= sum + ++ctr; will produce the value of sum as 15 because ctr will be first incremented and then added to sum producing value 15. Similarly; the following code sum = 12; ctr = 4; sum = sum ctr will produce the value of sum as 15 because ctr will be first decremented. With the postfix version of these operators, C++ first uses the value of the operand in evaluating the expression before incrementing or decrementing the operand's value. For example, the following code sum = 12; ctr = 4; sum = sum + ctr + + will produce the value of sum as 16 because ctr will be first used in the expression producing the value of sum as 16 and then increment the value of ctr by 1 (ctr becomes now 5) Similary, the following code sum = 12; ctr = 4; sum = sum + ctr - -; will produce the value of sum as 16 because ctr will be first used with its value 4 producing value of sum as 16 and then decrement the value of ctr by 1 (ctr becomes 3). C++ Shorthand Operator Example Equivalent to + = A + = 2 A = A = A - = 2 A = A - 2 % = A % = 2 A = A % 2 /= A/ = 2 A = A / 2 *= A * = 2 A = A * 2

7 - 7 - Conditional operator The conditional operator?: is called ternary operator as it requires three operands. The format of the conditional operator is: Conditional_ expression? expression1 : expression2; If the value of conditional expression is true then the expression1 is evaluated, otherwise expression2 is evaluated.example int a = 5; int b = 6; big = (a > b)? a : b; The condition evaluates to false, therefore big gets the value from b and it becomes 6. The comma operator The comma operator gives left to right evaluation of expressions. It enables to put more than one expression separated by comma on a single line. Example int i = 20, j = 25; int sq = i * i, cube = j * j * j; In the above statements, comma is used as a separator between two statements / expressions. The sizeof operator As we know that different types of Variables, constant, etc. require different amounts of memory to store them The sizeof operator can be used to find how many bytes are required for an object to store in memory. Example sizeof (char) returns 1 sizeof (int) returns 2 sizeof (float) returns 4 If k is integer variable, the sizeof (k) returns 2. the sizeof operator determines the amount of memory required for an object at compile time rather than at run time. The order of Precedence The order in which the operators are used in a. given expression is called the order of precedence. The following table shows the order of precedence: ++, --(post increment/decrement) Highest ++ (Pre increment) --(Pre decrement), sizeof (),!(not),- (unary), +(unary) *,/,% +, - To <, <=, >, >= ==,!= &&?: = Lowest Comma operator LAB EXERCISES - 2 LE 2.1 Write a program to obtain a 4 digit number from the user and display the sum of digits and the reverse number. For example if user enters the number as 1534, the sum should be 13 and reverse number would be LE 2.2 Write a program to obtain seconds form the user and convert and display it into Hours, minutes and numbers format. For example if user inputs seconds as 7295, then your program should display the result as 2 Hours 60 minutes and 35 seconds LE 2.3 Write a program which accepts days as integer and display total number of years, months and days in it. for example : If user input as 856 days the output should be 2 years 4 months 6 days. LE 2.4 Write a program which accepts length1 and length2 in meters and centimeters and display their sum alsi in meter and centimeter form. For example: If user inputs length1 = 10 m 80 cm and length2 = 5 m 60 cm then the output should be 16 m 40 cm. LE 2.5 Write a program which accepts amount as integer and display total number of Notes of Rs. 500, 100, 50, 20, 10, 5 and 1. For example, when user enters a number, 575, the results would be like this : 1 100: 0 50: 1 20: 1 10: 0 5: 1 1: 0

8 - 8 - FLOW OF CONTROL Statements Statements are the instructions given to the computer to perform any kind of action. Action may be in the form of data movement, decision making etc. Statements form the smallest executable unit within a C++ program. Statements are always terminated by semicolon. Compound Statement A compound statement is a grouping of statements in which each individual statement ends with a semi-colon. The group of statements is called block. Compound statements are enclosed between the pair of braces ({.). The opening brace ({) signifies the beginning and closing brace () signifies the end of the block. Null Statement Writing only a semicolon indicates a null statement. Thus ';' is a null or empty statement. This is quite useful when the syntax of the language needs to specify a statement but the logic of the program does not need any statement. This statement is generally used in for and while loops. Conditional Statements Sometimes the program needs to be executed depending upon a particular condition. C++ provides the following statements for implementing the selection control structure. Simple if statement if-else statement Nested if-else statement else if statement switch statement Simple if statement syntax of the if statement if (condition) { statement(s); From the flowchart it is clear that if the if condition is true, statement is executed; otherwise it is skipped. The statement may either be a single or compound statement. if else statement syntax of the if - else statement if (condition) else statement1; statement2; From the above flowchart it is clear that the given condition is evaluated first. If the condition is true, statement1 is executed. If the condition is false, statement2 is executed. It should be kept in mind that statement and statement2 can be single or compound statement. Nested if statement In nested if...else statement, an entire if...else construct is written within either the body of the if statement or the body of an else statement. The syntax is as follows: if (condition_1) { if(condition_2) { block statement_1; else { block statement_2; else { block statement_3; block statement_4;

9 - 9 - else if statement It is used in multi-way decision on several conditions. This works by cascading comparisons. As soon as one of the conditions is true, the statement or block of statements following them is executed and no further comparisons are performed. The else...if syntax is as follows: if(condition_1) block statement_1; else if(condition_2) block statement_2; else if(condition_n) else For example: if (marks > 80) grade = A ; else if (marks > 60) grade = B ; block statement_n; else if (marks > 40) else default statement; grade = C ; grade = D LAB EXERCISES - 3 LE 3.1 Write a program to check whether the given number is even or odd (using?: ternary operator ). LE 3.2 Write a program to check whether the given number is positive or negative (using?: ternary operator ). LE 3.3 Write a program to find the greatest of three unequal numbers (using? : ternary operator ). LE 3.4 Write a program to find the grade based on marks (using? : ternary operator ). LE 3.5 Write a program to find the electricity bill based on units consumed (using? : ternary operator ). LE 3.6 Write a program to find the income tax (using?: ternary operator ). LE 3.7 Write a program to find the gain or loss% (using?: ternary operator ). LE 3.8 Write a program to find the nature and roots of a quadratic equation (using?: ternary operator ). LE 3.9 Write a program to find slant height, LSA,TSA, Volume of two cones and compare them (using? : ternary operator ). LE 3.10 Write all the above programs using if else statement.

10 LE 4.01 LE 4.02 LE 4.03 LE 4.04 LE 4.05 LE 4.06 LE 4.07 LE 4.08 LE 4.09 LE 4.10 LE 4.11 LE 4.12 LAB EXERCISE 4 (USE IF.ELSE) Any integer is input by the user. Write a program to find out whether it is an odd number or even number. Find the absolute value of a number entered by the user. Write a program to calculate the total expenses. Quantity and price per item are input by the user and discount of 10% is offered if the expense is more than Write a program to determine whether the seller has made profit or incurred loss. Also determine how much profit he made or loss he incurred. Cost price and selling price of an item is input by the user. If the ages of Ram, Sulabh and Ajay are input by the user, write a program to determine the youngest of the three. Write a program to check whether a triangle is valid or not, when the three angles of the triangle are entered by the user. A triangle is valid if the sum of all the three angles is equal to 180 degrees. Any year is input by the user. Write a program to determine whether the year is a leap year or not. In a company an employee is paid as under: If his basic salary is less than Rs. 1500, then HRA = 10% of basic salary and DA = 90% of basic salary. If his salary is either equal to or above Rs. 1500, then HRA = Rs. 500 and DA = 98% of basic salary. If the employee's salary is input by the user write a program to find his gross salary. Write a program to calculate the monthly telephone bills as per the following rule: Minimum Rs. 200 for upto 100 calls. Plus Rs per call for next 50 calls. Plus Rs per call for next 50 calls. Plus Rs per call for any call beyond 200 calls. Write a program to find the roots of and quadratic equation of type ax2+bx+c where a is not equal to zero. The marks obtained by a student in 5 different subjects are input by the user. The student gets a division as per the following rules: Percentage above or equal to 60 - First division Percentage between 50 and 59 - Second division Percentage between 40 and 49 - Third division Percentage less than 40 - Fail Write a program to calculate the division obtained by the student. Any character is entered by the user; write a program to determine whether the character entered is a capital letter, a small case letter, a digit or a special symbol. The following table shows the range of ASCII values for various characters. Characters ASCII Values A Z a z special 0-47, 58-64, 91-96, symbols

7 Introduction to C++

7 Introduction to C++ 7 Introduction to C++ 7.1 Introduction C++ is an extension to C Programming language. It was developed at AT&T Bell Laboratories in the early 1980s by Bjarne Stroustrup. It is a deviation from traditional

More information

Punctuation in C. Identifiers and Expressions. Identifiers. Variables. Keywords. Identifier Examples

Punctuation in C. Identifiers and Expressions. Identifiers. Variables. Keywords. Identifier Examples Identifiers and Expressions CSE 130: Introduction to C Programming Spring 2005 Punctuation in C Statements are terminated with a ; Groups of statements are enclosed by curly braces: { and } Commas separate

More information

INTRODUCTION TO FLOWCHARTING

INTRODUCTION TO FLOWCHARTING CHAPTER 1 INTRODUCTION TO FLOWCHARTING 1.0 Objectives 1.1 Introduction 1.2 Flowcharts 1.3 Types of Flowcharts 1.3.1 Types of flowchart 1.3.2 System flowcharts 1.4 Flowchart Symbols 1.5 Advantages of Flowcharts

More information

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void 1. Explain C tokens Tokens are basic building blocks of a C program. A token is the smallest element of a C program that is meaningful to the compiler. The C compiler recognizes the following kinds of

More information

A First Book of C++ Chapter 2 Data Types, Declarations, and Displays

A First Book of C++ Chapter 2 Data Types, Declarations, and Displays A First Book of C++ Chapter 2 Data Types, Declarations, and Displays Objectives In this chapter, you will learn about: Data Types Arithmetic Operators Variables and Declarations Common Programming Errors

More information

Chapter 2: Problem Solving Using C++

Chapter 2: Problem Solving Using C++ Chapter 2: Problem Solving Using C++ 1 Objectives In this chapter, you will learn about: Modular programs Programming style Data types Arithmetic operations Variables and declaration statements Common

More information

INDEX. C programming Page 1 of 10. 5) Function. 1) Introduction to C Programming

INDEX. C programming Page 1 of 10. 5) Function. 1) Introduction to C Programming INDEX 1) Introduction to C Programming a. What is C? b. Getting started with C 2) Data Types, Variables, Constants a. Constants, Variables and Keywords b. Types of Variables c. C Keyword d. Types of C

More information

Chapter 8. Arithmetic in C++

Chapter 8. Arithmetic in C++ Christian Jacob Chapter 8 Arithmetic in C++ 8.1 The C++ Vocabulary 8.2 Variables and Types 8.2.1 Data Objects 8.2.2 Variables 8.2.3 Declaration of Variables 8.3 Elementary C++ Data Types 8.3.1 Integers

More information

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 2: Basic Elements of C++

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with the basic components of a C++ program,

More information

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program. Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to

More information

BHARATHIAR UNIVERSITY: COIMBATORE CENTRE FOR COLLABORATION OF INDUSTRY AND INSTITUTIONS(CCII) CERTIFICATE IN ADVANCED PROGRAMMING C++ LANGUAGE

BHARATHIAR UNIVERSITY: COIMBATORE CENTRE FOR COLLABORATION OF INDUSTRY AND INSTITUTIONS(CCII) CERTIFICATE IN ADVANCED PROGRAMMING C++ LANGUAGE Certificate in Advanced Programming - C++ Language Page 1 of 7 BHARATHIAR UNIVERSITY: COIMBATORE 641046 CENTRE FOR COLLABORATION OF INDUSTRY AND INSTITUTIONS(CCII) CERTIFICATE IN ADVANCED PROGRAMMING C++

More information

Which of the following is the correct operator to compare two variables? A. := B. = C. equal D. ==

Which of the following is the correct operator to compare two variables? A. := B. = C. equal D. == Group 1 Question 1. What is the correct value to return to the operating system upon the successful completion of a program? A. -1 B. 1 C. 0 D. Programs do not return a value. Question 2. What is the only

More information

Introduction to C Programming

Introduction to C Programming Introduction to C Programming C HOW TO PROGRAM, 6/E 1992-2010 by Pearson Education, Inc. All Rights Reserved. 2.1 Introduction The C language facilitates a structured and disciplined approach to computer

More information

1. Constants. 2. Variables. 3. Reserved words or key words. 4. Constants. Character set in C

1. Constants. 2. Variables. 3. Reserved words or key words. 4. Constants. Character set in C Character set in C We should use only the following characters in writing a C program. These characters can be combined to create C words. Alphabet: A, B, C, D.. Z, a, b, c, d..z Numeric digits: 0, 1,

More information

UNIT-1. C Programming & Data Structures. Introduction to Computers: Computing Environment: Types of Computing Environments:

UNIT-1. C Programming & Data Structures. Introduction to Computers: Computing Environment: Types of Computing Environments: Introduction to Computers: C Programming & Data Structures UNIT-1 A computer system consists of hardware and software. Computer hardware is the collection of physical elements that comprise a computer

More information

C Programming Dr. Hasan Demirel

C Programming Dr. Hasan Demirel C How to Program, H. M. Deitel and P. J. Deitel, Prentice Hall, 5 th edition (3 rd edition or above is also OK). Introduction to C Programming Dr. Hasan Demirel Programming Languages There are three types

More information

Adjusted/Modified by Nicole Tobias. Chapter 2: Basic Elements of C++

Adjusted/Modified by Nicole Tobias. Chapter 2: Basic Elements of C++ Adjusted/Modified by Nicole Tobias Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types

More information

Introduction to C++ Programming

Introduction to C++ Programming Introduction to C++ Programming 1 Outline Introduction to C++ Programming A Simple Program: Printing a Line of Text Another Simple Program: Adding Two Integers Memory Concepts Arithmetic Decision Making:

More information

C++ Language Tutorial

C++ Language Tutorial cplusplus.com C++ Language Tutorial Written by: Juan Soulié Last revision: June, 2007 Available online at: http://www.cplusplus.com/doc/tutorial/ The online version is constantly revised and may contain

More information

Computers process data under the control of sets of instructions called computer programs.

Computers process data under the control of sets of instructions called computer programs. Introduction Computer is a device capable of performing computations and making logical decisions at speeds millions and even billions of times faster than human beings. Computers process data under the

More information

Chapter One Introduction to Programming

Chapter One Introduction to Programming Chapter One Introduction to Programming 1-1 Algorithm and Flowchart Algorithm is a step-by-step procedure for calculation. More precisely, algorithm is an effective method expressed as a finite list of

More information

VALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANKULATHUR 603 203 DEPARTMENT OF COMPUTER APPLICATIONS QUESTION BANK IN REVISED BLOOM S TAXONOMY

VALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANKULATHUR 603 203 DEPARTMENT OF COMPUTER APPLICATIONS QUESTION BANK IN REVISED BLOOM S TAXONOMY ACADEMIC YEAR: 0 7 VALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANKULATHUR 0 0 SEMESTER: ODD BRANCH: MCA YEAR: I SEMESTER: I SUBJECT CODE AND NAME: MC70 Problem Solving and Programming NAME OF THE FACULTY

More information

Dept. of CSE, IIT KGP

Dept. of CSE, IIT KGP Programming in C: Basics CS10001: Programming & Data Structures Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Types of variable We must declare the

More information

Lecture 1 Notes: Introduction

Lecture 1 Notes: Introduction Introduction to C++ January 4, 2011 Massachusetts Institute of Technology 6.096 Lecture 1 Notes: Introduction 1 Compiled Languages and C++ 1.1 Why Use a Language Like C++? At its core, a computer is just

More information

C programming. Intro to syntax & basic operations

C programming. Intro to syntax & basic operations C programming Intro to syntax & basic operations Example 1: simple calculation with I/O Program, line by line Line 1: preprocessor directive; used to incorporate code from existing library not actually

More information

Borland C++ Compiler: Operators

Borland C++ Compiler: Operators Introduction Borland C++ Compiler: Operators An operator is a symbol that specifies which operation to perform in a statement or expression. An operand is one of the inputs of an operator. For example,

More information

I PUC - Computer Science. Practical s Syllabus. Contents

I PUC - Computer Science. Practical s Syllabus. Contents I PUC - Computer Science Practical s Syllabus Contents Topics 1 Overview Of a Computer 1.1 Introduction 1.2 Functional Components of a computer (Working of each unit) 1.3 Evolution Of Computers 1.4 Generations

More information

Variables and Constants. Variable A location in computer's memory in which a value may be stored from which that value may be retrieved

Variables and Constants. Variable A location in computer's memory in which a value may be stored from which that value may be retrieved Variables and Constants Variable A location in computer's memory in which a value may be stored from which that value may be retrieved Storage of Variables Setting Aside Memory Defining a variable in C++

More information

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

MLR Institute of Technology

MLR Institute of Technology MLR Institute of Technology DUNDIGAL 500 043, HYDERABAD COMPUTER SCIENCE AND ENGINEERING Computer Programming Lab List of Experiments S.No. Program Category List of Programs 1 Operators a) Write a C program

More information

Figure 1.12 Entering, Translating, and Running a High-Level Language Program Pearson Education, Inc. All rights reserved.

Figure 1.12 Entering, Translating, and Running a High-Level Language Program Pearson Education, Inc. All rights reserved. Figure 1.12 Entering, Translating, and Running a High-Level Language Program 1 2007 Pearson Education, Inc. All rights reserved. 2 Figure 2.7 General Form of a C Program 2007 Pearson Education, Inc. All

More information

Marathwada Institute of Technology

Marathwada Institute of Technology Marathwada Institute of Technology Master of Computer Application Title of the subject: Object Oriented Programming using C++ Course Code: MCA 101 Faculty: Shubhashree Savant Class: FY MCA Part - I (Question

More information

Programming Language: Syntax. Introduction to C Language Overview, variables, Operators, Statements

Programming Language: Syntax. Introduction to C Language Overview, variables, Operators, Statements Programming Language: Syntax Introduction to C Language Overview, variables, Operators, Statements Based on slides McGraw-Hill Additional material 2004/2005 Lewis/Martin Modified by Diana Palsetia Syntax

More information

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C Embedded Systems A Review of ANSI C and Considerations for Embedded C Programming Dr. Jeff Jackson Lecture 2-1 Review of ANSI C Topics Basic features of C C fundamentals Basic data types Expressions Selection

More information

6.096 Lab 1. Due: 7 January 12:30:00. September 20, 2011

6.096 Lab 1. Due: 7 January 12:30:00. September 20, 2011 6.096 Lab 1 Due: 7 January 1:30:00 September 0, 011 1 Additional Material 1.1 Constants A constant is an expressions with a fixed value. Kinds of constants: Literals: used to express particular values

More information

Chapter 2: Elements of Java

Chapter 2: Elements of Java Chapter 2: Elements of Java Basic components of a Java program Primitive data types Arithmetic expressions Type casting. The String type (introduction) Basic I/O statements Importing packages. 1 Introduction

More information

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements 9 Control Statements 9.1 Introduction The normal flow of execution in a high level language is sequential, i.e., each statement is executed in the order of its appearance in the program. However, depending

More information

PIC Microcontrollers The basics of C programming language

PIC Microcontrollers The basics of C programming language Page 1 / 28 Page 2 / 28 Table of contents PROGRAMMING LANGUAGES...3 ADVANTAGES OF HIGHER PROGRAMMING LANGUAGES...6 PREPROCESSOR... 6 PREPROCESSOR DIRECTIVE # include... 7 PREPROCESSOR DIRECTIVE # define...7

More information

Tutorial-3a: First steps with C++ programming

Tutorial-3a: First steps with C++ programming HTTP://WWW.HEP.LU.SE/COURSES/MNXB01 Introduction to Programming and Computing for Scientists (2015 HT) Tutorial-3a: First steps with C++ programming Programming for Scientists Tutorial 3a 1 / 17 Quick

More information

OSMIC. CSoft ware. C Language manual. Rev Copyright COSMIC Software 1999, 2003 All rights reserved.

OSMIC. CSoft ware. C Language manual. Rev Copyright COSMIC Software 1999, 2003 All rights reserved. OSMIC CSoft ware C Language manual Rev. 1.1 Copyright COSMIC Software 1999, 2003 All rights reserved. Table of Contents Preface Chapter 1 Historical Introduction Chapter 2 C Language Overview C Files...2-1

More information

MIT Aurangabad FE Computer Engineering

MIT Aurangabad FE Computer Engineering MIT Aurangabad FE Computer Engineering Unit 1: Introduction to C 1. The symbol # is called a. Header file c. include b. Preprocessor d. semicolon 2. The size of integer number is limited to a. -32768 to

More information

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T) Unit- I Introduction to c Language: C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating

More information

Going from Python to C

Going from Python to C Going from Python to C Darin Brezeale December 8, 2011 Python is a high-level, interpreted language. C has many of the same types of programming constructs as in Python: arrays, loops, conditionals, functions,

More information

Introduction to the C++ Programming Language

Introduction to the C++ Programming Language L E S S O N S E T 2 Introduction to the C++ Programming Language PURPOSE PROCEDURE 1. To briefly introduce the C++ programming language 2. To show the use of memory in programming 3. To introduce variables

More information

Control Structure. Pseudocode: Input number If number is even Then Print even Else print odd. Flowchart: Begin. End. Print Odd. number even?

Control Structure. Pseudocode: Input number If number is even Then Print even Else print odd. Flowchart: Begin. End. Print Odd. number even? Control Structure Normally, a program is executed in a sequential manner.however, in many cases, a program has to choose among alternative statements C++ provides constructs that enable the programmer

More information

switch Multiple-Selection Statement

switch Multiple-Selection Statement switch Multiple-Selection Statement (This feature is rarely useful, although it s perfect for programming the iterative song The Twelve Days of Christmas!) If no match occurs, the default case is executed,

More information

Final Exam Review. CS 1428 Fall Jill Seaman. Final Exam

Final Exam Review. CS 1428 Fall Jill Seaman. Final Exam Final Exam Review CS 1428 Fall 2011 Jill Seaman 1 Final Exam Friday, December 9, 11:00am to 1:30pm Derr 241 (here) Closed book, closed notes, clean desk Comprehensive (covers entire course) 25% of your

More information

Standard C Input/Output. Output: printf() Table of Contents

Standard C Input/Output. Output: printf() Table of Contents Standard C Input/Output 1 Output: printf() 2 Table of Contents Output: printf( ) - syntax & sematics Output: printf( ) - examples Output: printf( ) - format control Screen / Printer Control Input: scanf(

More information

Pemrograman Dasar. Basic Elements Of Java

Pemrograman Dasar. Basic Elements Of Java Pemrograman Dasar Basic Elements Of Java Compiling and Running a Java Application 2 Portable Java Application 3 Java Platform Platform: hardware or software environment in which a program runs. Oracle

More information

C AND C++ PROGRAMMING

C AND C++ PROGRAMMING C AND C++ PROGRAMMING Bharathidasan University A Courseware prepared by University Informatics Centre Part I - Programming in C Getting Started This courseware is intended to be an introduction to C programming

More information

Course Topics - Outline

Course Topics - Outline Course Topics - Outline Lecture 1 - Introduction Lecture 2 - Lexical conventions Lecture 3 - Data types Lecture 4 - Operators Lecture 5 - Behavioral modeling Lecture 6 - Data flow modeling Lecture 7 -

More information

CMSC 106 Lecture Set #2. C language syntax. Syntax vs Semantics Examples

CMSC 106 Lecture Set #2. C language syntax. Syntax vs Semantics Examples CMSC 106 Lecture Set #2 C Language Introduction C language syntax Syntax rules of the grammar vocabulary recognized by the language ANSI standard American National Standards Institute Semantics the meaning

More information

Convert Temperature CMPE-013/L. Constants and Literals. The Code #include <stdio.h> Gabriel Hugh Elkaim Winter 2014

Convert Temperature CMPE-013/L. Constants and Literals. The Code #include <stdio.h> Gabriel Hugh Elkaim Winter 2014 CMPE-013/L Constants and Literals Gabriel Hugh Elkaim Winter 2014 Convert Temperature Want to write a program to convert the temperature from Fahrenheit to Celsius for a range of temperatures. Demonstrates

More information

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement? 1. Distinguish & and && operators. PART-A Questions 2. How does an enumerated statement differ from a typedef statement? 3. What are the various members of a class? 4. Who can access the protected members

More information

CS101 Computer programming and utilization

CS101 Computer programming and utilization CS101 Computer programming and utilization Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal Rekhi Building IIT Bombay Lecture 3, Basic features of C++ Tuesday, 2 August 2011

More information

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

3) Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging?

3) Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging? Freshers Club Important 100 C Interview Questions & Answers 1) How do you construct an increment statement or decrement statement in C? There are actually two ways you can do this. One is to use the increment

More information

OBJECT ORIENTED PROGRAMMING IN C++

OBJECT ORIENTED PROGRAMMING IN C++ OBJECT ORIENTED PROGRAMMING IN C++ For Off Campus BSc Computer Science Programme UNIT 1 1. The goal of programmers is to develop software that are. A. Correct B. Reliable and maintainable C. Satisfy all

More information

Key concepts. C++ character set. Tokens. Keywords Identifiers Literals Punctuators Operators. Integrated Development Environment (IDE)

Key concepts. C++ character set. Tokens. Keywords Identifiers Literals Punctuators Operators. Integrated Development Environment (IDE) 5 1 Key concepts C++ character set Tokens o o o o o Keywords Identifiers Literals Punctuators Operators Integrated Development Environment (IDE) o o Turbo C++ IDE Geany IDE C++ (pronounced "C plus plus")

More information

Java Review (Essentials of Java for Hadoop)

Java Review (Essentials of Java for Hadoop) Java Review (Essentials of Java for Hadoop) Have You Joined Our LinkedIn Group? What is Java? Java JRE - Java is not just a programming language but it is a complete platform for object oriented programming.

More information

Introduction to Computers and Programming

Introduction to Computers and Programming 16.070 Introduction to Computers and Programming March 14 Recitation 6 Spring 2002 Topics: Quick review of PS4 issues Fundamental Data types ASCII / Arithmetic Conversion Number Systems / Logical Operation

More information

Chapter 2. Values, Variables, and Types. 2.1 Java Values in DrJava s Interaction Pane

Chapter 2. Values, Variables, and Types. 2.1 Java Values in DrJava s Interaction Pane 14 Chapter 2 Values, Variables, and Types In this chapter we explore the primitive building blocks that are used to develop Java programs. We experiment with the following concepts within DrJava s interactive

More information

PROGRAMMING IN C PROGRAMMING IN C CONTENT AT A GLANCE

PROGRAMMING IN C PROGRAMMING IN C CONTENT AT A GLANCE PROGRAMMING IN C CONTENT AT A GLANCE 1 MODULE 1 Unit 1 : Basics of Programming Unit 2 : Fundamentals Unit 3 : C Operators MODULE 2 unit 1 : Input Output Statements unit 2 : Control Structures unit 3 :

More information

Sources: On the Web: Slides will be available on:

Sources: On the Web: Slides will be available on: C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,

More information

CS201- Introduction to Programming Latest Solved Mcqs from Final term Papers July 11,2011

CS201- Introduction to Programming Latest Solved Mcqs from Final term Papers July 11,2011 CS201- Introduction to Programming Latest Solved Mcqs from Final term Papers July 11,2011 Mc100401285 moaaz.pk@gmail.com Moaaz Siddiq Bc100400662 bc100400662asad@gmail.com Asad Ali Latest Mcqs FINALTERM

More information

Informatica e Sistemi in Tempo Reale

Informatica e Sistemi in Tempo Reale Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)

More information

Programming for MSc Part I

Programming for MSc Part I Herbert Martin Dietze University of Buckingham herbert@the-little-red-haired-girl.org July 24, 2001 Abstract The course introduces the C programming language and fundamental software development techniques.

More information

Huazhong University of Science and Technology JAVA Programming Language Lecture 2:Variables and Data Types

Huazhong University of Science and Technology JAVA Programming Language Lecture 2:Variables and Data Types JAVA Programming Language Lecture 2:Variables and Data Types Chengwei Zhang ( 张成伟 ) School of Electronic Information and Communications Huazhong University of Science and Technology Mar. 2015 Outline Quick

More information

Variables and constants linked with operators. Uses relational and logical operators Evaluates to 1 or 0 (true or false) only

Variables and constants linked with operators. Uses relational and logical operators Evaluates to 1 or 0 (true or false) only Expressions 1 Expressions Variables and constants linked with operators Arithmetic expressions Uses arithmetic operators Can evaluate to any value Logical expressions Uses relational and logical operators

More information

Comp181 Midterm Examination, Fall Name Surname: Number: 90 min. 18/11/09

Comp181 Midterm Examination, Fall Name Surname: Number: 90 min. 18/11/09 Comp181 Midterm Examination, Fall 09 10 Name Surname: Number: 90 min. 18/11/09 Answer ALL off the following questions. 1.What does the term hardware refer to? a. The relative difficulty of programming

More information

The Fundamentals of C++

The Fundamentals of C++ The Fundamentals of C++ Basic programming elements and concepts JPC and JWD 2002 McGraw-Hill, Inc. Program Organization Program statement Definition Declaration Action Executable unit Named set of program

More information

C++ INTERVIEW QUESTIONS

C++ INTERVIEW QUESTIONS C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get

More information

Your first C program. Which one is best?

Your first C program. Which one is best? Your first C program #include void main(void) { printf( Hello, world!\n ); } #include void main(void) { printf( Hello, ); printf( world! ); printf( \n ); } Which one is best? #include

More information

Programming Fundamental. Instructor Name: Lecture-2

Programming Fundamental. Instructor Name: Lecture-2 Programming Fundamental Instructor Name: Lecture-2 Today s Lecture What is Programming? First C++ Program Programming Errors Variables in C++ Primitive Data Types in C++ Operators in C++ Operators Precedence

More information

[Page 70 (continued)] a. are used to document a program and improve its readability. [Page 71]

[Page 70 (continued)] a. are used to document a program and improve its readability. [Page 71] [Page 70 (continued)] Exercises 2.7 Discuss the meaning of each of the following objects: a. std::cin b. std::cout 2.8 Fill in the blanks in each of the following: a. are used to document a program and

More information

C++ Basics. C++ Basics: Names: Identifiers. Names: Identifiers. Display 2.1 A C++ Program (1 of 2) Display 2.1 A C++ Program (2 of 2)

C++ Basics. C++ Basics: Names: Identifiers. Names: Identifiers. Display 2.1 A C++ Program (1 of 2) Display 2.1 A C++ Program (2 of 2) C++ Basics C++ Basics: 2.1 Variables and Assignments Variables and Assignments Input and Output Data Types and Expressions Simple Flow of Control Program Style A C++ variable can hold a number or other

More information

The programmers guide to C++

The programmers guide to C++ The programmers guide to C++ Adrian P. Robson Northumbria University April 1996 Preprint for Ann, Alice and John Copyright 1997, 2011 by Adrian P. Robson Issue 2.1 - Pre-print draft with post-print errata

More information

School of Informatics, University of Edinburgh

School of Informatics, University of Edinburgh CS1Ah Lecture Note 5 Java Expressions Many Java statements can contain expressions, which are program phrases that tell how to compute a data value. Expressions can involve arithmetic calculation and method

More information

,!7IA3C1-dcahfj!:t;K;k;K;k. Addison-Wesley s JavaScript Reference Card. Kathleen M. Goelz and Carol J. Schwartz, Rutgers University VARIABLES

,!7IA3C1-dcahfj!:t;K;k;K;k. Addison-Wesley s JavaScript Reference Card. Kathleen M. Goelz and Carol J. Schwartz, Rutgers University VARIABLES Addison-Wesley s JavaScript Reference Card Kathleen M. Goelz and Carol J. Schwartz, Rutgers University Javascript: A scripting language designed to be integrated into HTML code to produce enhanced, dynamic,

More information

Chapter II Binary Data Representation

Chapter II Binary Data Representation Chapter II Binary Data Representation The atomic unit of data in computer systems is the bit, which is actually an acronym that stands for BInary digit. It can hold only 2 values or states: 0 or 1, true

More information

C A short introduction

C A short introduction About these lectures C A short introduction Stefan Johansson Department of Computing Science Umeå University Objectives Give a short introduction to C and the C programming environment in Linux/Unix Go

More information

Data Representation. Representing Data

Data Representation. Representing Data Data Representation COMP 1002/1402 Representing Data A computer s basic unit of information is: a bit (Binary digit) An addressable memory cell is a byte (8 bits) Capable of storing one character 10101010

More information

Programming in C 1. Bharat Kinariwala Tep Dobry. 1 Copyright c1993 by B.Kinariwala and T. Dobry. All rights reserved.

Programming in C 1. Bharat Kinariwala Tep Dobry. 1 Copyright c1993 by B.Kinariwala and T. Dobry. All rights reserved. Programming in C 1 Bharat Kinariwala University ofhawai`i Tep Dobry University ofhawai`i January 5, 1993 1 Copyright c1993 by B.Kinariwala and T. Dobry. All rights reserved. Contents Table of Contents

More information

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand: Introduction to Programming and Algorithms Module 2 CS 146 Sam Houston State University Dr. Tim McGuire Introduction To Computers And Java Chapter Objectives To understand: the meaning and placement of

More information

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java

More information

Overview of a C Program

Overview of a C Program Overview of a C Program Programming with C CSCI 112, Spring 2015 Patrick Donnelly Montana State University Programming with C (CSCI 112) Spring 2015 2 / 42 C Language Components Preprocessor Directives

More information

Programming Assignments

Programming Assignments Programming Assignments 1. A number is called an Armstrong number if the sum of the cubes of the digits of the number is equal to the number. For example 153 = 1^3 + 5^3 + 3^3. Write a C program that asks

More information

()A Crash Course in Programming with C++ and the Ubuntu O.S. June 8, / 47

()A Crash Course in Programming with C++ and the Ubuntu O.S. June 8, / 47 A Crash Course in Programming with C++ and the Ubuntu O.S. Dr. Daniel A. Ray MCS Dept UVa-Wise June 8, 2010 ()A Crash Course in Programming with C++ and the Ubuntu O.S. June 8, 2010 1 / 47 Outline What

More information

So far we have considered only numeric processing, i.e. processing of numeric data represented

So far we have considered only numeric processing, i.e. processing of numeric data represented Chapter 4 Processing Character Data So far we have considered only numeric processing, i.e. processing of numeric data represented as integer and oating point types. Humans also use computers to manipulate

More information

C++ Essentials. Sharam Hekmat PragSoft Corporation www.pragsoft.com

C++ Essentials. Sharam Hekmat PragSoft Corporation www.pragsoft.com C++ Essentials Sharam Hekmat PragSoft Corporation www.pragsoft.com Contents Contents Preface 1. Preliminaries 1 A Simple C++ Program 2 Compiling a Simple C++ Program 3 How C++ Compilation Works 4 Variables

More information

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON PROBLEM SOLVING WITH SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON Addison Wesley Boston San Francisco New York London

More information

Lecture Set 2: Starting Java

Lecture Set 2: Starting Java Lecture Set 2: Starting Java 1. Java Concepts 2. Java Programming Basics 3. User output 4. Variables and types 5. Expressions 6. User input 7. Uninitialized Variables CMSC 131 - Lecture Outlines - set

More information

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system. http://www.tutorialspoint.com/java/java_quick_guide.htm JAVA - QUICK GUIDE Copyright tutorialspoint.com What is Java? Java is: Object Oriented Platform independent: Simple Secure Architectural- neutral

More information

C PROGRAMMING FOR MATHEMATICAL COMPUTING

C PROGRAMMING FOR MATHEMATICAL COMPUTING UNIVERSITY OF CALICUT SCHOOL OF DISTANCE EDUCATION BSc MATHEMATICS (2011 Admission Onwards) VI Semester Elective Course C PROGRAMMING FOR MATHEMATICAL COMPUTING QUESTION BANK Multiple Choice Questions

More information

Introduction to Problem Solving Techniques

Introduction to Problem Solving Techniques UNIT 1 Introduction to Problem Solving Techniques Structure 1.0 Introduction 1.1 Procedure (steps involved in problem solving) 1.2 Algorithm 1.3 Flow Chart 1.4 Symbols used in Flow Charts 1.5 Pseudo Code

More information

Python to C/C++ Fall 2011

Python to C/C++ Fall 2011 Python to C/C++ Fall 2011 1. Main Program Python: Program code is indented after colon : def main(): body of program C/C++: Have more setup overhead. C: Both require #include directives to access libraries

More information

Reading. C Programming Language. Basic syntax Whitespaces. Whitespaces (cont d) #include. Basic syntax Comments

Reading. C Programming Language. Basic syntax Whitespaces. Whitespaces (cont d) #include. Basic syntax Comments Reading C Programming Language Types, operators, expressions Control flow, functions Basic IO K&R Chapter 2 Types, Operators, and Expressions K&R Chapter 3 Control Flow K&R Chapter 7 Basic I/O NEWS Assignment

More information

Object Oriented Software Design

Object Oriented Software Design Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 28, 2010 G. Lipari (Scuola Superiore Sant Anna) Introduction

More information

Java: Primitive Data Types, Variables and Constants

Java: Primitive Data Types, Variables and Constants Java: Primitive Data Types, Variables and Constants Introduction A primitive data type is a data type provided as a basic building block by a programming language. It is predefined by the programming language

More information

C Programming Language CIS 218

C Programming Language CIS 218 C Programming Language CIS 218 Description C is a procedural languages designed to provide lowlevel access to computer system resources, provide language constructs that map efficiently to machine instructions,

More information