C++ Programming Applied to Robotics, Mark Aull Lesson 2: Intro to Visual Studio, debugger Intro to C++, variables, conditionals, loops, strings
|
|
- Preston Cooper
- 6 years ago
- Views:
Transcription
1 C++ Programming Applied to Robotics, Mark Aull Lesson 2: Intro to Visual Studio, debugger Intro to C++, variables, conditionals, loops, strings As in the first lesson, open visual studio, start a new empty project named lesson2, add a new.cpp file to that project, and paste the code in the Appendix into the.cpp file. The header files indicate that functions involving standard input/output and string manipulation can be called from this.cpp file. Main is called with no parameters as before. Attempt to build the code. On most modern compilers, this code will produce an error on the line for (ii=4,jj=1;ii>1;jj*=ii,ii--);//null for loop complaining about jj not being defined. Notice that jj is defined in the previous loop: for (int jj=0;jj<2*ii;jj++)//scope of jj varies by compiler this shows the scope of variables: a variable declared inside of a block (a loop, if statement, etc) doesn't exist outside of it. Some older versions of visual studio did not enforce this rule correctly, so you will occasionally come across code where variables are declared in loops, and used outside of them. The fix is to move the declaration for jj to the top of the file: int ii=23; changes to int ii=23,jj; and for (int jj=0;jj<2*ii;jj++)//scope of jj varies by compiler changes to for (jj=0;jj<2*ii;jj++)//scope of jj varies by compiler Now the code should build correctly. Start the debugger by selecting step over or pressing F10.
2 Pressing F10 one more time will move to the first line of main. The variables declared at the beginning of the function are created as seen in the locals tab in the variable window, which is hopefully on the bottom left. Note the data types, integer, double precision floating point, and character array (string). Also note the call stack tab on the bottom right. It currently indicates the function main(). This will be much more useful when multiple functions are in use; you can move to whichever level you wish by double-clicking on the desired function in that tab. Stepping few a few more lines (with F10), the variables are initialized to the values indicated. Then the values are displayed by the formatted print (printf()) statement. %s indicates a string value, %c a character, %d an integer (in decimal) and %f a floating point number. The numbers indicate the width allowed, and the number after the dot indicates the precision with which to display a floating point number.
3 The next few lines demonstrate some mathematical operations. Addition, subtraction, multiplication and division occur as you would expect, but additionally, the ++ operator adds 1 to any number, -- subtracts 1, x+=y is equivalent to x=x+y, and the same works with -=x, *=x, and /=. strcat() is a string concatenation function. It takes the second string and appends it to the first string.
4 Note that the value if ii is currently 24, which is greater than 23, so the first branch of this if statement is evaluated. Also note that even though ii==24 is true, the second branch is not evaluated because the first already was. The printf() statement includes a few escape characters: \n is a newline, and \t is a tab. Similarly \b is a backspace, \r is a carriage return, \f is a form feed, \a is a beep. \\ generates a \ character. \' and \ are needed to produce those characters. Note: when using '\b', the character is not actually deleted, but the position where characters will be written is moved back, so that the next character will overwrite the current one.
5 Next a /= and a -= command are demonstrated. Note the new values of ii and p. Also, the string formatted print (sprintf()) command is introduced. It works like printf(), but its first parameter is a string, into which the output is stored, rather than being printed on the screen. The printf() command on the next line displays the output of the sprintf() command.
6 Next, predict which branch of the if statement will be executed given the current values of the variables, and what will be printed. A for loop in C++ contains three parameters: initialization, conditional and an increment. The initialization runs before the beginning of the loop, after a ; is the conditional which is tested before the code in the loop is run, and the increment step after the next ; is run after the code in the loop. Attempt to predict what the loop will display before running it. You should then use the debugger to slowly step through the code, verifying that the description below is correct. for (int jj=0;jj<2*ii;jj++)//scope of jj varies by compiler {//1 printf("jj=%d\n",jj);//2 if (jj<6)//3 jj++; }//4 jj at 1 jj displayed (value at 2) (jj at 3)<6 (true or false) jj at 4 0 First, ii is 6 from before, and jj is set to 0. Since 0 is less that 2*6=12, the code between the { } is executed, displaying jj=0, then, since 0 is less than 6, incrementing jj to 1. Next the increment section of the for loop (containing a jj++) is run, increasing jj to 2. The conditional is then evaluated: 2 is less than 12, so the loop is run again, displaying jj==2, and since 2 is less than 6, increasing jj to 3. The increment section increases jj to 4. Once again, jj=4 is displayed, and by the next time the loop is evaluated, jj is increased to 6. After jj=6 is displayed, the if statement does not run because 6 is not less than 6. After this, the if statement is never true again, and the loop displays jj= for each value between 7 and 11. After this, jj++ is run, increasing jj to 12. Since now jj<2*ii is no longer true, the
7 code stops running the loop. The next line demonstrates an important fact to remember about C and C++: an operation involving a data type yields that data type as a result. A character plus a character is a character, a double times a double is a double, etc. When multiple data types are combined, the larger or more inclusive is used: an integer plus a character is an integer, an integer time a float is a float, etc. The only time this behavior is counter-intuitive is for integer division: an integer divided by an integer is the mathematical definition of a rational number, however according to the rules above, the result is an integer. Here, 5 and 2 are both read as integers, and the quotient is processed as 2, not 2.5, even though it is being stored into a floating point variable. Replacing 5/2 with double(5)/2 or even 5.0/2 or 5./2 would correct this behavior. The next line introduces the concept of a null for loop, i.e. a for loop terminated by a ; instead of being followed by a loop in { }. Null for loops therefore run in a single line; the line after is outside the loop. This line also shows that multiple initialization and increment steps are allowed, separated by commas. The conditional can be as complex as desired, incorporating multiple statements connected by and (&&) and or ( ), but only one decision value must be computed (the loop either continues to run or it does not). This null for loop runs like a function where ii is an input and jj is an output (f(ii)=jj). The reader's task is to fill in the table below without running the code, in order to predict the final value of jj. The initial values have been filled in to help you. for (ii=4,jj=1;ii>1;jj*=ii,ii--);//null for loop printf("f(4)=%d\n",jj);//displays ii jj ii>1 4 1 true Next, verify that your answer is correct. Looking back at the numbers above, inductively obtain the function (f) implemented by this loop and use that knowledge to predict the value of jj calculated by the next loop, which is identical except for the initial value of ii. The following is a short code demonstrating the getch() function (get character) in the conio (console input\output) library. This function grabs any key pressed on the keyboard, and stores it to a. It is then displayed on the screen as an integer and as a character. Note that a while loop is used, which has the conditional parameter like a for loop, but does not use the other sections as a for loop does. A while (1) loop runs forever, until the program is stopped externally, e.g. by clicking the x in the upper right of the window. Using this program, you can see what each keystroke outputs. The shift, ctrl, and alt keys modify these outputs. For example, note that ctrl-g produces a 7 and a beep. This is not so much useful as interesting.
8 #include <stdio.h> #include <conio.h> void main(void) {//main function int a=0; while(1) {//while loop (until ctrl-c or X) a=getch(); //get character from keyboard printf("%10d %5c\n",a,a);//display character as integer and character }//end while loop }//end main Escape returns 27, and special keys, such as function keys, arrow keys, etc are noted to produce two outputs: a zero or 224, followed by another character, i.e. the up arrow produces a 224 followed by an H. Compare this with shift-h. Therefore, the program can be modified to handle special characters differently, and exit on the escape key: #include <stdio.h> #include <conio.h> void main(void) {//main function int a=0; while(a!=27) {//while loop (until esc) a=getch(); printf("%10d %5c\n",a,a); if (a==224 a==0) {//control key a=getch(); printf("command: %10d %5c\n",a,a); }//end control key }//end while }//end main function The code available on the website stretches this a little further by including a large if-else statement displaying what keys are hit for selected special characters.
9 Assignment: Produce a program that drives the Galil motion controller using the libraries as demonstrated in lesson 1 and the keyboard, using the getch function. The program must: not move the robot when started until the user commands a motion, stop the robot when the program stops, display instructions describing all behavior on startup, send commands AC 80000,80000 and DC 80000,80000 to the Galil to limit acceleration, have a designated key to stop the robot (by sending ST to the Galil), have a designated key to exit the program, control both the speed and turning rate of the robot (using the JG command, as shown in the previous lesson), send a to each controller after one keystroke (This is a good choice for a lowest speed), and have comments describing its operation at each important step (using // or /* */ as seen above), i.e. I should be able to put the robot wherever I want, pointing in whatever direction I want fairly safely with your program. Reminders: after the JG command, the first number is the right motor, in reverse, and the second number is the left motor, forward. Also, you must send a BG command after the first JG command sent after startup or after the first JG command sent after an ST command. It is more reliable to send s BG command after each JG command.
10 Appendix: source code for part 1 /*comments, whitespace doesn't do anything, for readability only start lecture math ops, ++, --, +-* /= printf, sprintf, strcat conditional, loop (different from MATLAB)*/ #include <stdio.h> #include <string.h> void main(void) {//main function int ii=23; double p=3.1415; char string[80]="hello"; printf("%s,%10d,%11.7f\n",string,ii,p);//displays ii++;//increment to p*=2;//p= strcat(string," world");//concatenate printf("%s,%5d,%10.7f\n",string,ii,p);// displays if (ii>23)//displays { printf("ii >23\n\ttestf\b\n"); } else if(ii==24) printf("ii=24\n"); else printf("ii<=23\n"); ii/=4;//decrement to p-=ii;//p= sprintf(string,"%s,%10d,%11.7f\n",string); printf("%s",string,ii,p);//displays if (ii==6&&p==0)//displays { printf("ii is 6 and p is 0\n"); } else if(ii!=6) printf("ii is not 6\n"); else printf("p is not 0\n"); for (int jj=0;jj<2*ii;jj++)//scope of jj varies by compiler { printf("jj=%d\n",jj); if (jj<6) jj++; } p=5/2;// data type rules printf("p = %f\n",p); for (ii=4,jj=1;ii>1;jj*=ii,ii--);//null for loop printf("f(4)=%d\n",jj);//displays for (ii=6,jj=1;ii>1;jj*=ii,ii--); printf("f(6)=%d\n",jj);//f(x)= }// end main
UNIT - I. Introduction to C Programming. BY A. Vijay Bharath
UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been
More informationCS102: Standard I/O. %<flag(s)><width><precision><size>conversion-code
CS102: Standard I/O Our next topic is standard input and standard output in C. The adjective "standard" when applied to "input" or "output" could be interpreted to mean "default". Typically, standard output
More informationc) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.
2.1 Introduction (No questions.) 2.2 A Simple Program: Printing a Line of Text 2.1 Which of the following must every C program have? (a) main (b) #include (c) /* (d) 2.2 Every statement in C
More informationVariables and Operators 2/20/01 Lecture #
Variables and Operators 2/20/01 Lecture #6 16.070 Variables, their characteristics and their uses Operators, their characteristics and their uses Fesq, 2/20/01 1 16.070 Variables Variables enable you to
More informationECET 264 C Programming Language with Applications. C Program Control
ECET 264 C Programming Language with Applications Lecture 7 C Program Control Paul I. Lin Professor of Electrical & Computer Engineering Technology http://www.etcs.ipfw.edu/~lin Lecture 7 - Paul I. Lin
More informationCS313D: ADVANCED PROGRAMMING LANGUAGE
CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 2 : C# Language Basics Lecture Contents 2 The C# language First program Variables and constants Input/output Expressions and casting
More informationبسم اهلل الرمحن الرحيم
بسم اهلل الرمحن الرحيم Fundamentals of Programming C Session # 10 By: Saeed Haratian Fall 2015 Outlines Examples Using the for Statement switch Multiple-Selection Statement do while Repetition Statement
More informationUnit 3. Operators. School of Science and Technology INTRODUCTION
INTRODUCTION Operators Unit 3 In the previous units (unit 1 and 2) you have learned about the basics of computer programming, different data types, constants, keywords and basic structure of a C program.
More informationFull file at C How to Program, 6/e Multiple Choice Test Bank
2.1 Introduction 2.2 A Simple Program: Printing a Line of Text 2.1 Lines beginning with let the computer know that the rest of the line is a comment. (a) /* (b) ** (c) REM (d)
More informationC Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee
C Language Part 1 (Minor modifications by the instructor) References C for Python Programmers, by Carl Burch, 2011. http://www.toves.org/books/cpy/ The C Programming Language. 2nd ed., Kernighan, Brian,
More informationComputers Programming Course 6. Iulian Năstac
Computers Programming Course 6 Iulian Năstac Recap from previous course Data types four basic arithmetic type specifiers: char int float double void optional specifiers: signed, unsigned short long 2 Recap
More informationModel Viva Questions for Programming in C lab
Model Viva Questions for Programming in C lab Title of the Practical: Assignment to prepare general algorithms and flow chart. Q1: What is a flowchart? A1: A flowchart is a diagram that shows a continuous
More informationComputers Programming Course 5. Iulian Năstac
Computers Programming Course 5 Iulian Năstac Recap from previous course Classification of the programming languages High level (Ada, Pascal, Fortran, etc.) programming languages with strong abstraction
More informationChapter 9 Strings. With this array declaration: char s[10];
Chapter 9 Strings 9.1 Chapter Overview There is no data type in C called ʻstringʼ; instead, strings are represented by an array of characters. There is an assortment of useful functions for strings that
More informationIntroduction to C Language
Introduction to C Language Instructor: Professor I. Charles Ume ME 6405 Introduction to Mechatronics Fall 2006 Instructor: Professor Charles Ume Introduction to C Language History of C Language In 1972,
More informationFeatures of C. Portable Procedural / Modular Structured Language Statically typed Middle level language
1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC
More informationUNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered ) FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING
( Word to PDF Converter - Unregistered ) http://www.word-to-pdf-converter.net FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING INTRODUCTION TO C UNIT IV Overview of C Constants, Variables and Data Types
More informationCharacters in C consist of any printable or nonprintable character in the computer s character set including lowercase letters, uppercase letters,
Strings Characters in C consist of any printable or nonprintable character in the computer s character set including lowercase letters, uppercase letters, decimal digits, special characters and escape
More informationCS6202 - PROGRAMMING & DATA STRUCTURES UNIT I Part - A 1. W hat are Keywords? Keywords are certain reserved words that have standard and pre-defined meaning in C. These keywords can be used only for their
More informationAN OVERVIEW OF C. CSE 130: Introduction to Programming in C Stony Brook University
AN OVERVIEW OF C CSE 130: Introduction to Programming in C Stony Brook University WHY C? C is a programming lingua franca Millions of lines of C code exist Many other languages use C-like syntax C is portable
More informationIECD Institute for Entrepreneurship and Career Development Bharathidasan University, Tiruchirappalli 23.
Subject code - CCP01 Chapt Chapter 1 INTRODUCTION TO C 1. A group of software developed for certain purpose are referred as ---- a. Program b. Variable c. Software d. Data 2. Software is classified into
More informationUnit 4. Input/Output Functions
Unit 4 Input/Output Functions Introduction to Input/Output Input refers to accepting data while output refers to presenting data. Normally the data is accepted from keyboard and is outputted onto the screen.
More informationLecture 3. More About C
Copyright 1996 David R. Hanson Computer Science 126, Fall 1996 3-1 Lecture 3. More About C Programming languages have their lingo Programming language Types are categories of values int, float, char Constants
More informationOverview of C, Part 2. CSE 130: Introduction to Programming in C Stony Brook University
Overview of C, Part 2 CSE 130: Introduction to Programming in C Stony Brook University Integer Arithmetic in C Addition, subtraction, and multiplication work as you would expect Division (/) returns the
More informationFull file at
Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class
More informationProgramming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan
Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah Lecturer Department of Computer Science & IT University of Balochistan 1 Outline p Introduction p Program development p C language and beginning with
More informationChapter 11 Introduction to Programming in C
Chapter 11 Introduction to Programming in C Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox, Colorado State University C: A High-Level Language! Gives
More informationOBJECT ORIENTED PROGRAMMING
OBJECT ORIENTED PROGRAMMING LAB 1 REVIEW THE STRUCTURE OF A C/C++ PROGRAM. TESTING PROGRAMMING SKILLS. COMPARISON BETWEEN PROCEDURAL PROGRAMMING AND OBJECT ORIENTED PROGRAMMING Course basics The Object
More informationCMPT 102 Introduction to Scientific Computer Programming. Input and Output. Your first program
CMPT 102 Introduction to Scientific Computer Programming Input and Output Janice Regan, CMPT 102, Sept. 2006 0 Your first program /* My first C program */ /* make the computer print the string Hello world
More informationProgramming I Laboratory - lesson 01
Programming I Laboratory - lesson 0 Introduction in C++ programming environment. The C++ program structure. Computer programs are composed of instructions and data. Instructions tell the computer to do
More informationObjectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program
Objectives Chapter 2: Basic Elements of C++ 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 informationChapter 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 informationC OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed
C Overview C OVERVIEW Goals speed portability allow access to features of the architecture speed C fast executables allows high-level structure without losing access to machine features many popular languages
More informationFundamentals of C. Structure of a C Program
Fundamentals of C Structure of a C Program 1 Our First Simple Program Comments - Different Modes 2 Comments - Rules Preprocessor Directives Preprocessor directives start with # e.g. #include copies a file
More informationChapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction
Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers
More informationMultiple Choice Questions ( 1 mark)
Multiple Choice Questions ( 1 mark) Unit-1 1. is a step by step approach to solve any problem.. a) Process b) Programming Language c) Algorithm d) Compiler 2. The process of walking through a program s
More informationB.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University
Unit 1 Programming Language and Overview of C 1. State whether the following statements are true or false. a. Every line in a C program should end with a semicolon. b. In C language lowercase letters are
More informationC++ Programming Applied to Robotics, Mark Aull Lesson 5a: Arrays and Pointers
C++ Programming Applied to Robotics, Mark Aull Lesson 5a: Arrays and Pointers This lesson introduces the concept of templated functions. These allow you to write a function that takes parameters of an
More informationLecture 02 C FUNDAMENTALS
Lecture 02 C FUNDAMENTALS 1 Keywords C Fundamentals auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void
More information6.096 Introduction to C++ January (IAP) 2009
MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture
More informationCSI33 Data Structures
Outline Department of Mathematics and Computer Science Bronx Community College October 24, 2018 Outline Outline 1 Chapter 8: A C++ Introduction For Python Programmers Expressions and Operator Precedence
More informationChapter 11 Introduction to Programming in C
C: A High-Level Language Chapter 11 Introduction to Programming in C Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox, Colorado State University! Gives
More informationProgramming. C++ Basics
Programming C++ Basics Introduction to C++ C is a programming language developed in the 1970s with the UNIX operating system C programs are efficient and portable across different hardware platforms C++
More informationC Concepts - I/O. Lecture 19 COP 3014 Fall November 29, 2017
C Concepts - I/O Lecture 19 COP 3014 Fall 2017 November 29, 2017 C vs. C++: Some important differences C has been around since around 1970 (or before) C++ was based on the C language While C is not actually
More information2 nd Week Lecture Notes
2 nd Week Lecture Notes Scope of variables All the variables that we intend to use in a program must have been declared with its type specifier in an earlier point in the code, like we did in the previous
More informationIntroduction to C# Applications
1 2 3 Introduction to C# Applications OBJECTIVES To write simple C# applications To write statements that input and output data to the screen. To declare and use data of various types. To write decision-making
More informationChapter 8 - Characters and Strings
1 Chapter 8 - Characters and Strings Outline 8.1 Introduction 8.2 Fundamentals of Strings and Characters 8.3 Character Handling Library 8.4 String Conversion Functions 8.5 Standard Input/Output Library
More informationLESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:
LESSON 1 FUNDAMENTALS OF C The purpose of this lesson is to explain the fundamental elements of the C programming language. C like other languages has all alphabet and rules for putting together words
More information.. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar..
.. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar.. A Simple Program. simple.c: Basics of C /* CPE 101 Fall 2008 */ /* Alex Dekhtyar */ /* A simple program */ /* This is a comment!
More informationc++ keywords: ( all lowercase ) Note: cin and cout are NOT keywords.
Chapter 1 File Extensions: Source code (cpp), Object code (obj), and Executable code (exe). Preprocessor processes directives and produces modified source Compiler takes modified source and produces object
More informationFundamental of Programming (C)
Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering
More informationC OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure
C Overview Basic C Program Structure C OVERVIEW BASIC C PROGRAM STRUCTURE Goals The function main( )is found in every C program and is where every C program begins speed execution portability C uses braces
More informationComputer Programming
Computer Programming Introduction Marius Minea marius@cs.upt.ro http://cs.upt.ro/ marius/curs/cp/ 26 September 2017 Course goals Learn programming fundamentals no prior knowledge needed for those who know,
More informationSome Computer Preliminaries
Some Computer Preliminaries Before we get started, let's look at some basic components that play a major role in a computer's ability to run programs: 1) Central Processing Unit: The "brains" of the computer
More informationExpressions and Data Types CSC 121 Spring 2015 Howard Rosenthal
Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types
More informationLaboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information
Laboratory 2: Programming Basics and Variables Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information 3. Comment: a. name your program with extension.c b. use o option to specify
More informationhttps://www.eskimo.com/~scs/cclass/notes/sx8.html
1 de 6 20-10-2015 10:41 Chapter 8: Strings Strings in C are represented by arrays of characters. The end of the string is marked with a special character, the null character, which is simply the character
More informationStrings and Library Functions
Unit 4 String String is an array of character. Strings and Library Functions A string variable is a variable declared as array of character. The general format of declaring string is: char string_name
More informationCS102: Variables and Expressions
CS102: Variables and Expressions The topic of variables is one of the most important in C or any other high-level programming language. We will start with a simple example: int x; printf("the value of
More informationChapter 8: Character & String. In this chapter, you ll learn about;
Chapter 8: Character & String Principles of Programming In this chapter, you ll learn about; Fundamentals of Strings and Characters The difference between an integer digit and a character digit Character
More informationC-Programming. CSC209: Software Tools and Systems Programming. Paul Vrbik. University of Toronto Mississauga
C-Programming CSC209: Software Tools and Systems Programming Paul Vrbik University of Toronto Mississauga https://mcs.utm.utoronto.ca/~209/ Adapted from Dan Zingaro s 2015 slides. Week 2.0 1 / 19 What
More informationLecture 05 I/O statements Printf, Scanf Simple statements, Compound statements
Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 05 I/O statements Printf, Scanf Simple
More informationChapter 12 Variables and Operators
Chapter 12 Variables and Operators Highlights (1) r. height width operator area = 3.14 * r *r + width * height literal/constant variable expression (assignment) statement 12-2 Highlights (2) r. height
More informationChapter 11 Introduction to Programming in C
Chapter 11 Introduction to Programming in C Original slides from Gregory Byrd, North Carolina State University Modified by Chris Wilcox, Yashwant Malaiya Colorado State University C: A High-Level Language
More informationString Computation Program
String Computation Program Reference Manual Scott Pender scp2135@columbia.edu COMS4115 Fall 2012 10/31/2012 1 Lexical Conventions There are four kinds of tokens: identifiers, keywords, expression operators,
More informationChapter 2: Using Data
Chapter 2: Using Data TRUE/FALSE 1. A variable can hold more than one value at a time. F PTS: 1 REF: 52 2. The legal integer values are -2 31 through 2 31-1. These are the highest and lowest values that
More informationChapter 3: Operators, Expressions and Type Conversion
101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To
More informationCOSC121: Computer Systems: Runtime Stack
COSC121: Computer Systems: Runtime Stack Jeremy Bolton, PhD Assistant Teaching Professor Constructed using materials: - Patt and Patel Introduction to Computing Systems (2nd) - Patterson and Hennessy Computer
More informationM4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE
M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be
More informationVariables and literals
Demo lecture slides Although I will not usually give slides for demo lectures, the first two demo lectures involve practice with things which you should really know from G51PRG Since I covered much of
More informationRoom 3P16 Telephone: extension ~irjohnson/uqc146s1.html
UQC146S1 Introductory Image Processing in C Ian Johnson Room 3P16 Telephone: extension 3167 Email: Ian.Johnson@uwe.ac.uk http://www.csm.uwe.ac.uk/ ~irjohnson/uqc146s1.html Ian Johnson 1 UQC146S1 What is
More informationCSC 2400: Computer Systems. Arrays and Strings in C
CSC 2400: Computer Systems Arrays and Strings in C Lecture Overview Arrays! List of elements of the same type Strings! Array of characters ending in \0! Functions for manipulating strings 1 Arrays: C vs.
More informationPES INSTITUTE OF TECHNOLOGY (BSC) I MCA, First IA Test, November 2015 Programming Using C (13MCA11) Solution Set Faculty: Jeny Jijo
PES INSTITUTE OF TECHNOLOGY (BSC) I MCA, First IA Test, November 2015 Programming Using C (13MCA11) Solution Set Faculty: Jeny Jijo 1. (a)what is an algorithm? Draw a flowchart to print N terms of Fibonacci
More informationAssoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.
Assoc. Prof. Dr. Marenglen Biba (C) 2010 Pearson Education, Inc. All for repetition statement do while repetition statement switch multiple-selection statement break statement continue statement Logical
More informationChapter 11 Introduction to Programming in C
C: A High-Level Language Chapter 11 Introduction to Programming in C Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox, Colorado State University Gives
More informationCAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE
CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE a) Mention any 4 characteristic of the object car. Ans name, colour, model number, engine state, power b) What
More informationLESSON 4. The DATA TYPE char
LESSON 4 This lesson introduces some of the basic ideas involved in character processing. The lesson discusses how characters are stored and manipulated by the C language, how characters can be treated
More informationFundamentals of Programming. Lecture 11: C Characters and Strings
1 Fundamentals of Programming Lecture 11: C Characters and Strings Instructor: Fatemeh Zamani f_zamani@ce.sharif.edu Sharif University of Technology Computer Engineering Department The lectures of this
More informationZheng-Liang Lu Java Programming 45 / 79
1 class Lecture2 { 2 3 "Elementray Programming" 4 5 } 6 7 / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch. 2 in HS 11 / Zheng-Liang Lu Java Programming 45 / 79 Example Given a radius
More informationCSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018
CSE 1001 Fundamentals of Software Development 1 Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018 Identifiers, Variables and Data Types Reserved Words Identifiers in C Variables and Values
More informationCC112 Structured Programming
Arab Academy for Science and Technology and Maritime Transport College of Engineering and Technology Computer Engineering Department CC112 Structured Programming Lecture 3 1 LECTURE 3 Input / output operations
More informationLecture 6. Statements
Lecture 6 Statements 1 Statements This chapter introduces the various forms of C++ statements for composing programs You will learn about Expressions Composed instructions Decision instructions Loop instructions
More informationThe Hyderabad Public School, Begumpet, Hyderabad, A.P
The Hyderabad Public School, Begumpet, Hyderabad, A.P. 500 016 2012-13 Department of Computer Science Class 8 Worksheet 3 1) How many times will the following statement execute? ( ) int a=5; while(a>6)
More informationCOSC2031 Software Tools Introduction to C
COSC2031 Software Tools Introduction to C Instructor: Matt Robinson matt@cs.yorku.ca http://www.cs.yorku.ca/course/2031/ From Last Day What this course is about A (brief) History of Unix and C Some sample
More informationChapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic
More informationCMPT 125: Lecture 3 Data and Expressions
CMPT 125: Lecture 3 Data and Expressions Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 3, 2009 1 Character Strings A character string is an object in Java,
More informationWork relative to other classes
Work relative to other classes 1 Hours/week on projects 2 C BOOTCAMP DAY 1 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Overview C: A language
More informationUNIT- 3 Introduction to C++
UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage
More informationCSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI
CSCI 2010 Principles of Computer Science Data and Expressions 08/09/2013 CSCI 2010 1 Data Types, Variables and Expressions in Java We look at the primitive data types, strings and expressions that are
More informationCSC 2400: Computer Systems. Arrays and Strings in C
CSC 2400: Computer Systems Arrays and Strings in C Lecture Overview Arrays! List of elements of the same type Strings! Array of characters ending in \0! Functions for manipulating strings 1 Arrays in C
More informationCOMS W4115 Programming Languages & Translators GIRAPHE. Language Reference Manual
COMS W4115 Programming Languages & Translators GIRAPHE Language Reference Manual Name UNI Dianya Jiang dj2459 Vince Pallone vgp2105 Minh Truong mt3077 Tongyun Wu tw2568 Yoki Yuan yy2738 1 Lexical Elements
More informationCS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor
CS 261 Fall 2017 Mike Lam, Professor C Introduction Variables, Memory Model, Pointers, and Debugging The C Language Systems language originally developed for Unix Imperative, compiled language with static
More informationTHE FUNDAMENTAL DATA TYPES
THE FUNDAMENTAL DATA TYPES Declarations, Expressions, and Assignments Variables and constants are the objects that a prog. manipulates. All variables must be declared before they can be used. #include
More informationExpressions and Data Types CSC 121 Fall 2015 Howard Rosenthal
Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and
More informationA variable is a name for a location in memory A variable must be declared
Variables A variable is a name for a location in memory A variable must be declared, specifying the variable's name and the type of information that will be held in it data type variable name int total;
More informationChapter 6 Primitive types
Chapter 6 Primitive types Lesson page 6-1. Primitive types Question 1. There are an infinite number of integers, so it would be too ineffient to have a type integer that would contain all of them. Question
More informationChapter 2: Data and Expressions
Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University January 15, 2015 Chapter 2: Data and Expressions CS 121 1 / 1 Chapter 2 Part 1: Data
More informationFundamentals of Programming
Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables
More informationLecture 2. Examples of Software. Programming and Data Structure. Programming Languages. Operating Systems. Sudeshna Sarkar
Examples of Software Programming and Data Structure Lecture 2 Sudeshna Sarkar Read an integer and determine if it is a prime number. A Palindrome recognizer Read in airline route information as a matrix
More informationThe C Programming Language Guide for the Robot Course work Module
The C Programming Language Guide for the Robot Course work Module Eric Peasley 2018 v6.4 1 2 Table of Contents Variables...5 Assignments...6 Entering Numbers...6 Operators...7 Arithmetic Operators...7
More information