To use many of these manipulators, a program would need to include the header file iomanip.h. #include <iomanip. h>

Size: px
Start display at page:

Download "To use many of these manipulators, a program would need to include the header file iomanip.h. #include <iomanip. h>"

Transcription

1 Appendices Appendix A: C++ style input/output Streams cout cin cerr Nonnally the tenninal screen. Nonnally the tenninal keyboard. It is usual that this stream will always cause output to go to the users tenninal. Output Note: cout, cin, and cerrare of type ostream. Output manipulators are used as if they are a nonnal data item to be output. However, instead of data being output, changes are set which detennine how the data to be output should be fonnatted. For example, to set the field width to 5 places in which the number 42 is printed, a user could write: I cout «setw(5) «42; To use many of these manipulators, a program would need to include the header file iomanip.h. #include <iomanip. h> Manipulator Item Effect setw(int n) next Sets the field width in which the next item will be printed to n spaces. hex all Sets the output base for all subsequent integer items to be base 16 (hexadecimal). oct all Sets the output base for all subsequent integer items to be base 8 (octal). dec all Sets the output base for all subsequent integer items to be base 10 (decimal). setfill(int c) next Sets the fill character to make up the characters to pad the next item to field width size to be c. setprecision( int n) all Sets the number of decimal places to display for all subsequent floating point numbers to be n places. endl next Inserts newline and flush stream. flush next Flushs the stream. ends next Inserts the end of string tenninator. Note: The second column indicates if the effect is for all subsequent items to be output or just the next item output.

2 298 Appendices Parameters to the selectors setiosflags and resetiosflags Input output selector (ios) flags are set or unset with the respective manipulators setiosflags and resetiosflags. For example, to set all subsequent output to be right aligned in its selected output field width, a user could write: I c~~t «,etia,flag' ( ia," right ); [ The flags listed below are defined in the class i 0 s, and act as parameters for the manipulators setiosflags and resetiosflags. ios flag Item Effect ios::left all Items are left aligned in the output field width. ios::right all Items are right aligned in the output field width. ios: :scientific all Floating point items are output in scientific notation. For example 42.2 would be displayed as 4.22E+01. ios::fixed all Floating point items are output in decimal notation. For example 42.2 would be displayed as ios::showpoint all Floating point numbers are displayed with all the specified decimal places even if zero. For example 4.2 with 2 decimal places set would be displayed as ios::showpos all Show the + sign on output for positive numbers. For example 42 would be displayed as +42. For example, the following fragment of code: -cout «"Th:-:::::~:~::~'~:~:~age ['::'~ ~"~~_~~A cout «setiosflags( ios::left ); cout «setw(3) «setfill('+') «"e" «"j" «"\n"; ~._~~....~~_... _.~~... ~... ~~~... ~~. ~ ~...l would produce the output:

3 Appendix A: C++ style input/output 299 Input The following manipulators can be used on an input stream: Manipulators Item Effect ws Reads white space characters in input. oct, dec, hex all Set the input base to: octal, decimal or hexadecimal. Parameters to the selectors setiosoags and resetiosoags These are set or unset with the respective manipulators setiosflags and resetiosflags which take as a parameter the following flags defined in the class ios. ios t1a~ Item Effect ios::skipws all Input operations will ignore white space characters. resetiosflags( ios: :skipws ) will cause white space characters to be delivered. 110 to files The two classes ofstream and ifstream are classes derived respectively from ostream and istream. They add the ability to read and write to files. For example, the following code will write to the file mas.txt and then read back the data displaying it on a user's terminal. #include <fstream.h> #include <iomanip.h> void maine) { of stream sinki ifstream sourcei char Ci sink.open("mas.txt")i if (!sink) { II OU", put stream II input stream II connect to mas.txt II Failed to create cerr «"Failed to create mas.txt" «"\n"i exit(-l)i sink «"Hello world" «"\n" i sink.close()i source.open("mas.txt")i if (! source) { II close stream II connect to mas.txt II Failed to open cerr «"Failed to open mas.txt" «"\n"i exit(-2)i

4 300 Appendices source» resetiosflags( ios::skipws ); II Read white space while ( source»c,!source.eof(» II Copy mas.txt to cout { cout «c; source.close(); II close stream The output from this program would be: [~~~~i.::::~:~:~i.:::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::] Note: The include file f st ream. h which contains the definition of if stream and ofstream. String streams The classes ostrstream and istrstream are derived respectively from ostream and istream; they can be used to read and write to and from an area in memory. For example, the following program: tinclude <strstream.h> tinclude <iomanip.h> tinclude <string.h> const int MAX MES = 100; II Size of string void main () { char mes[max_mes]; II Output string char town[] = "Brighton East Sussex"; II Input string ostrstream ostr( mes, MAX_MES ); II output str stream istrstream istr( town, strlen(town) ); II input. str stream ostr «"The sum of 2+3 is " «(2+3) «"\n" «'\0'; cout «mes; II Write string mes istr» resetiosflags( ios::skipws ); char c; cout «"\n" «"["; while ( istr» c,!istr.eof() { cout «c; II read characters cout «"J" «"\n";

5 would produce the following output: Appendix A: C++ style input/output 301 The sum of 2+3 is 5 [Brighton East Sussex] Note: The string terminator has to be written to the string stream, ifit is to be used as a normal C++ string. The header file s trs tream. h contains a #include for iostream. h.

6 302 Appendices Appendix B: C style input/output Many C++ compilers will allow the inclusion of C style input and output. In C, like in C++, the I/O routines are not part of the language but are provided by a standard library of functions. In C however, the I/O system is not type safe. The C I/O philosophy revolves around the concept of a stream pointer which is associated with a file. This stream pointer is then used to read or write information from or to the selected file. Declarations pertaining to this I/O system are held in the header file stdio. h. A stream pointer is declared with: [i.~:~:::~:~:~~:::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::] and is associated with a file using the library function fopen as follows: The parameters and returned value of fopen are: ::::::: : :::::::::::::: ::::: ::: ::: : Parameter 1: Parameter 2: result: A string representing the filename. A string representing the way the file is to be accessed: r Open for reading. w Create for writing. a Open for writing at end if exists. Create for writing if the file does not exist. r+ Open an existing file for reading and writing. w+ Create a new file or reading and writing. a+ Open for writing at end if exists. Create for writing if the file does not exist. A stream pointer to the file. NULL if the file cannot be opened. Note: When a file is opened for write or append access for the first time it will be created, if it does not already exist. f open would normally be called as follows: sp = fopen ( "file. dat", "r" ); if ( sp == NULL ) { /* Take an appropriate action: file has not been opened */ Note: NULL is defined in the header file <stdio. h>.

7 Appendix B: C style input/output 303 Formatted output Information is written to the file with the library function fprintf. This function uses a format string which tells it how to interpolate the contents of its remaining parameters to the stream. This concept is best illustrated by an example: void main () { FILE *sp; char ch; sp = fopen ("tmp. dat", "w" ); for(int i=100;i<105;i++) { fprintf(sp,"character %c has ASCII code %d\n", i, i ); fclose (sp); which would write into the file tmp. da t: Character d has ASCII code 100 Character e has ASCII code 101 Character f has ASCII code 102 Character g has ASCII code 103 Character h has ASCII code 104 '~_""'-"-V."-"-""""""-"""-"-""'_'-"-',"."""""""'. '. ""'-',"'... Note: Thatfprintf cannot check on the type of arguments supplied; it implicitly trusts the writer of the code to gel it right. The parameters and some of the corresponding returned values of fprintf are: Parameter 1: The stream pointer. Parameter 2: A string representing how the parameters after this are to be interpolated into the output texl. Each parameter to be interpolated is introduced by a % followed by a character or characters indicating the format %d As a decimal number. %i As a decimal number. %u As an unsigned decimal number. %c As a character. %s As a string of characters [ string terminated with "{)' ]. %f As a noating point number [ format 1.23 ]. %e As a noating point number [ format 1.23e45 ]. %0 As an octal number. %x As a hcxadecimal number. %ld As a long integer. %1 As a long integer. %% The character %.

8 304 Appendices The fonnats may be modified with: %4d %-4d %04d %8.2f As a decimal number in a field width of 4 right justified. As a decimal number in a field width of 4 left justified. As %4d but with leading zeros. As a floating number in a field width of 8 right justified by 2 decimal places. result Success or failure of the operation. The following streams are usually pre-defined for the user. stdout stdin stderr Nonnallv the tenninal screen Nonnally the terminal keyboard Nonnally the terminal screen. It is usual that this stream will always cause output to go to the users terminal. Single character output fputc( ch, stdout )i putc( ch, stdout }i II A function call II May be a macro The parameters and returned value of fputc and putc are as follows: Parameter 1 Parameter 2 result The character to be output. The stream to be output on. Success or failure of the operation. Single character input ch fgetc( sp )i ch getc( sp )i II A function call II May be a macro The parameters and returned value of fgetc and getc are as follows: Parameter 1: The stream from which the character is to be input. result: The character input. If the end of file has been reached on the stream then EOP is returned. EOP is defined in <stdio. h>.

9 Appendix B: C style input/output 305 Close the stream I fclose( sp ); The parameters and returned value of fclose are as follows: Parameter 1: The stream to be closed. result: Success or failure of the operation. Position in file randomly The example below illustrates a positioning in the file, 12 bytes from the start of the file. I fseek ( sp, 12L, 0 ); The parameters and returned value of f seek are as follows: Parameter 1: Parameter 2: Parameter 3: result: The stream on which a random positioning is to be made. The number of bytes to be moved which must be a long value. o 1 2 The file start. The current position. The file end. Success or failure of the operation. Input and output shortcuts The following functions are special cases of the normal C input / output functions. Function Is equivalent to: printf( args )i fprintf{ stdout, aras )i putchar (ch) i putc{ ch, stdout ) i getchar() i qetc( stdin )i

10 306 Appendices Appendix C: Useful functions The routines and macros referred to in this appendix will usually be available on most C++ systems. They are, in fact, part of the normal C standard library functions. However, many of the routines operate on very low level structures, such as a C++ string. Care should be exercised in using these routines to make sure that the parameters contain valid data for the function to be performed. In some case the exact effect of the function will be implementation dependent as, for example, the case of the function system that will execute a job control language (JCL) command from within a program. Note: The routines described below perform little error checking on the data supplied to them. In many cases wrong or invalid data will lead to unpredictable results. Character types and conversions The following macros are used to determine if a character is an alphabetic character, a digit etc. The character passed must be representable as an unsigned char. To use these functions the file ctype. h which contains the macro definitions will need to be included. *include <ctype.h> Macro int isalnum( int c ) int isalpha( int c ) int iscntrl( int c ) int isdigit( int c ) int islower( int c ) int isgraph( int c ) int isprint( iot c ) int ispunct( int c ) int isspace( int c ) int isupper( int c ) int isxdigit( int c ) Description Returns TRUE if c is a digit or letter character, FALSE otherwise. Returns TRUE if c is a letter character, FALSE otherwise. Returns TRUE if c is a control character, FALSE otherwise. Returns TRUE if c is a digit character, FALSE otherwise. Returns TRUE if c is a lower case character, FALSE otherwise. Returns TRUE if c is a printing character, FALSE otherwise. Returns TRUE if c is a printing character including space FALSE otherwise. Returns TRUE if c is a punctuation character including space, FALSE otherwise. Returns TRUE if c is a space tab carrage return, new line, vertical tab or form feed character, FALSE otherwise. Returns TRUE if c is an upper case character, FALSE otherwise. Returns TRUE if c is a hexadecimal digit character, FALSE otherwise.

11 Appendix C: Usefulfunctions 307 The following functions convert between the case of a letter. To use these functions the file ctype. h which contains the macro definitions will need to be included. #include <ctype.h> Function int tolower( int c ) int toupper( int c ) Description Converts an upper case character to its lower case equivalent. Converts a lower case character to its upper case equivalent. String functions A C++ string is represented by a character pointer, which points to an area of store, which contains a vector of characters terminated by the character \0'. str To use these functions the file string. h which contains the function prototype definitions will need to be included. #include <string.h> Function Description char *strcat( char *d, const char *s ) Appends a copy of C++ string s onto the end of the C++ string d. Returns a pointer to the new string s. char *strcpy(char *d, const char *s) Copies the C++ string s to d including the terminator \0'. Returns a pointer to the new string s. int strcmp( const char *sl, Performs a comparison of the C++ strings s 1 const char *s2 ) & s 2 returning an integer which is: <0 if sl is less than s2 ==0 if sl is equal to s2 >0 if s 1 is ~reater than s 2 size t strlen( const char *s ) Returns the length of the string s. char *strncmp( char *d, const char *s, The same as strcmp but only compares up to size t max) max characters. char *strncpy( char *d, const char *s, Copies at most max characters of the C++ size_t max) string s into d terminating with the string terminator I \ 0' if s is not longer than max. Note: The header file stddefh contains the definition of size _t which is defined to be an integer value.

12 308 Appendices Other string functions char *strchr( const char * s, int c ) Returns a pointer to the first occurrence in the C++ string s of character c scanning from left to right. If character c is not in string s returns null. size_t strcspn( const char *sl, Returns the length of the prefix of s 1 which const char *s2 ) consists of characters not in s2. char *strerror( int n ) Return a string representing a description of the error number n which has been returned (usually from an I/O function). int stricmp( const char *sl, As per strcmp but not case sensitive, e.g. const char * s2 ) "ABC" and "abc" will be considered equal. char *strlwr( char *s ) Converts the upper case letters in s to lower case. char *strupr( char *s ) Converts the lower case letters in s to upper case. char *strncat( char *d, const char *s, Appends at most max characters of d to sand size t max) then appends the strin~ terminator "D'. char *strpbrk( const char *sl, Returns a pointer into sl of the first occurrence const char * s2 ) of a character in the string s2 otherwise returns null. char *strrchr( const char *s, int c) As per strchr but scans right to left. size_t strspn( const char *sl, Returns the length of the prefix of sl which const char *s2 ) consists of characters in s2. char * strtok( char * s 1, const char *s2 ) Mathematical functions Returns the tokens from s 1 that are delimited by characters in s2. Repeated calls to this function will return the next token in sl, a returned value of null indicates no more tokens. To use these functions the file math. h which contains the function prototype definitions will need to be included. In some cases the result will be undefined if the function is supplied with nonsensible values. #include <math.h> Function double sin( double x ) double cos( double x ) double tan( double x) Description sine ofx cosine ofx tangent of x

13 Appendix c: Useful functions 309 Function double asil}( double xl double acos( double x ) double atan( double x ) double atan2( double x, double y ) double sinh( double x ~ double cosh( double x ) double tanh( double x ) double exp( double x ) double loge double x ) double logl0( double x ) double pow( double x, double y ) double sqrt( double x ) double ldexp( double x, int n ) double fmod( double x, double y ) double ceil( double x ) double floor( double x ) double fabs( double x ) Description sine- l of x cosine-1ofx tangent- l of x tan~ent-l of xil hyperbolic sine of x hyperbolic cosine of x hyperbolic tangent of x ex Natural logarithm of x Base 10 logarithm of x xy The ~uare root of x x.2n Floating point remainder of x/y with the same sign as x. Smallest whole number not less than x Largest whole number notgreater than x Return the absolute value of x. (A negative x is made positive). The following functions can be used to find the absolute value of an integer quantity. To use these functions the file stdlib. h which contains the function prototype definitions will need to be included. #include <stdlib.h> Function Description int abs( int n ) Returns the absolute value of the int n. long labs( long n ) Returns the absolute value of the lojlq n. Random number generation The functions listed below are used in the generation of random numbers. To use these functions the file stdlib. h which contains the function prototype definitions will need to be included. #include <stdlib.h> Function int rand( void) void srand( unsigned int n ) Description Returns a pseudo random number in the range o to RAND MAX. Sets the seed for the random number generator. The initial seed is 1.

14 310 Appendices Character string to number conversions The following convert between numbers held in a C++ string and the physical representation of that number as an instance of the data type. To use these functions the file stdlib. h which contains the function prototype definitions will need to be included. #include <stdlib.h> Function double atof( const char *s ) int atoi( const char *s ) long atol( const char *s ) Description Converts the number represented by the C++ string s into a double. Converts the number represented by the C++ string s into an int. Converts the number represented by the C++ string s into a long. Exit from a C++ program The following are used to exit from a C++ program. To use these functions the file stdlib. h which contains the function prototype definitions will need to be included. #include <stdlib.h> Function void abort( void ) void exit( const int n ) int atexit ( void (*fun)( void) ) Execution of a JCL command Description Aborts the currently running program with an error SIGABRT. Exits the program with status n. exit(o) is considered the normal completion of a program. When the program terminates the function fun will be called. The result returned is non zero if the registration of the procedure cannot be made. The following is used to execute a JCL command by the host environment from within a running C++ program. To use these functions the file stdlib. h which contains the function prototype definitions will need to be included. #include <stdlib.h> Function int system( const char * s ) Description Executes the JCL command contained in the string s, the value returned is the result from executing the string. This function is very implementation dependent.

15 Appendix C: Usefulfunctions 311 Debugging The macro assert, can be used to test the validity of an assertion in a C++ program. If the symbol NDEBUG is defined #define NDEBUG then the macro is ignored and no code is generated. To use this macro, the file assert. h which contains the macro definition will need to be included. #include <assert.h> Macro void assert( const int expression) Description If the expression is FALSE then an error message of the form: Assertion failed: expression file filename, line number is written to stderr. Access to variable arguments to a function If a function is described with a variable number of arguments (... ) the following macros allow access in a machine independent manner to these arguments. For example: int surn_pararns( canst int last_real_arg,... )i To use these macros, the file stdarg. h which contains the macro definitions will need to be included. Before the use of any of these macros the variable p_args must be declared with: #include <stdarg.h> Macro va_start( va_list p_args, lascreal_arg ) type va_arg( va_list p_args, type) void va3nd( va_list p_args) Description Sets p_args to the first argument after the argument last_real_arg in the argument list. This will address the first of the arguments specified with... Returns as type the next argument from the variable argument list. After the arguments have been processed this must be called to clean up the process.

16 312 Appendices Appendix D: Priority of operators Operators of C++: Associates from high priority to low priority Notes Left to Right () [ 1 ->.... Right to Left! * Monadic operators & (type) sizeof new delete Left to Right * ->* Left to Right 9- * / 0 Left to Right + - Left to Right Left to Right < <= >= > Left to Right --!= Left to Right & Left to Right "- Left to Right I Left to Right && Left to Right I I Right to Left? : conditional expression Right to Left = *= /= etc. Left to Right, comma QQ.erator

17 Appendix E: String and character escape sequences 313 Appendix E: String and character escape sequences The following are the escape sequences for introducing control characters into a C++ string or character constant. Thus: \" A double quote" \' A single quote ' \0 The end of string marker \? The Question mark? \\ The \ character \a Bell \b Backspace \c Carrage return \ddd The character with octal value ddd \f Form Feed \n A newline \r Return \t Tab \v Vertical tab \xddd The character with hexadecimal value ddd cout «"\"A c++ String\"\n\tWith embedded escape sequences" would print "A C++ String" With embedded escape sequences

18 314 Appendices Appendix F: Fundamental types Tvpe char signed char unsigned char int unsigned int short int unsigned short int long int unsigned long int float double long double Abbreviation Len2th (bvtes) Min value Max value o or or 127 equal to char equal to char >= short equal to int short >= char unsigned short ~gual short int long >= int unsigned long equal long int dec. places 1O±37 >= float 10 dec. places 1O±37 >= double 10 dec. places 1O±37 Type Abbreviation Length Min Value Max Value Is the name of the type. Is an allowable abbreviation for the name. Is the relationship between the types and the bytes of storage occupied. Is the minimal value that must be representable (smaller values are allowed). Is the maximum value that must be representable (larger numbers are allowed). Note: The implementor of C++ for a particular machine will decide if char is to be signed or unsigned. signed may be used as a prefix on the integer types

19 Appendix G: Literals in C Appendix G: Literals in C++ A literal in C++ has a type, which will effect the way it is processed. Literal Example Type Commentary Character 'A' char Decimal Number int Type dependant on long int implementation sizes of int etc. Unsigned Number 1234U unsigned int Suffix of U or u unsigned long int Octal Number int Leading 0 denotes long int octal number Hexadecimal number OxFACE int Leading Ox or OX long int denotes hexadecimal number Large number 1L long Suffix of L or I Unsigned large number UL unsigned long Suffix UL or ul or any combination Real number 1. 23F float Suffix of F or f Large real number double Very Large real number 1.23L long double Suffix ofl or I Note: An integer number will have the type of the smallest representable unit from (int, unsigned int, long int and unsigned long int). Thus, the type of a literal number may differ depending on the size of fundamental types for a particular implementation. By default a real number (e.g. 1.23) has type double. A leading 0 to an integer means that the number is octal.

20 316 Appendices Appendix H: Keywords in C++ asm auto break case catch char class canst continue default delete do double else enum extern float for friend goto if inline int long new operator private protected public register return short signed sizeof static struct switch template this throw try typedef union unsigned virtual void volatile while Note: asm is reservedfor implementors to include a machine specific facility to pass information to an assembler. Operators!= % & && &= () * = -> ->* * / :? < ««= <= "= > >=» delete new sizeof [ 1 %= *= /=»= I I Keywords and tokens used by the macro processor # endif ## ifdef define ifndef elif include else defined

21 Appendix I: Compatibility of code Appendix I: Compatibility of code 317 The programs illustrated in this book were compiler with Borland C++ version 3.1 though in the early stages of development many other compilers where used. Compiler Problem Solution Borland C++ None - version 3.1 Sun C++ version Nested classes not supported. Remove nested class or struct to For example the class Set_of outside of the class on page 246. A friend of a class can not be a Use the mechanism to fake template class. template classes as described in For example, the class List has section a friend the class It_list <type> on page 256. Microsoft C++ Need to specify both array Specify both array bounds version 7.0 bounds when passing an array to a function. For example, the program on page 74. Template classes not supported. Use the mechanism to fake template classes as described in section C++ version 2 Main incompatibility Use the mechanism to fake compilers Template classes not supported. template classes as described in section There are many other 'minor' differences.

22 318 Appendices References Margaret A Ellis & Bjarne Stroustrup, The Annotated C++ Reference Manual, Addison Wesley Bjame Stroustrup, The C++ Programming Language, 2nd Edition, Addison Wesley, Grady Bouch Object Oriented Design with Applications, Addison Wesley, Borland C Manuals (Programmer's guide, User's guide, Library reference, and Tools and utilities guide) Borland International

23 Index *this 135 abs 309 abstract class 157 address arithmetic 170 aggregate 285 ambiguity function call 62 arithmetic 285 arrays 67 one dimensional 71 passing as a parameter 73 representation 73 safe 199 three dimensional 72 two dimensional 72 assert 311 assignment compatible conversions 138, 139 atexit 310 atoi 310 atol31o attribute linkage 279 storage class 279 type 279 visibility 279 auto 283 life time 279 base class 114 bit-field 198 boolean 16 break statement 8 C functions use of 227 call by reference 53 value 53 case label 7 statement 7 cast 24 cerr 297 char 16 character escape sequences 313 cin 297 class 30 abstract 157 constant 137 constant instance 77 example AbstracCAccount 157 Account 31, 91 A_Bag 255 A_It_Bag 255 Bag 259, 264 Bank 85 Board 99,104 Book 154 Cell 103 Computing 155 Counter 101 ECU 145 File_Name 235 Float 184, 274 Francs 146 Histogram 77 Int 275 InteresCAccount 113 ICBag 264 ICList 257 Line 235 List 256 Money 137, 140 Named_Account 125 Name_Address 68 Number 241 N_Account 158 ObjecCmaker 273 Office 124 Persistent 272 Player 98, 102 Pounds 143 Programming 155 Record 186 Room 123 Safe_array 204 Safe_vec 200 Secof246 Sink 234 Source 233

24 320 Index Special_InteresCAccount 118 Stack 81, 83,179 String 148 String_ vec 208 S_Account 162 implementation 44 inheritance rules 128 member static 90 no member functions 183 scope 282 specification 44 static member 90 visibility modifiers 121 private 120 protected 120 public 120 code in line 56 out of line 56 comment 3 compilation separate 45 conditional expression statement 7 const 17 instance of a class 137 member function 77 parameter 55 constants 17 constructor 32,85, 122 call in base class 116 copy 242 order of calling 127 container 253 bag 253 continue statement 8 conversion operator 143 copy constructor 242 deep 240, 243 shallow 240, 243 copy constructor when used 242 cout297 decimal number 315 declaration derived types 193 storage allocated 194 default label 7 delete 177 derived class 114 descriptor use of 239 destructor 85, 122 do while statement 6 double 16 dynamic life time 279 dynamic storage 177, 179 dynamic storage allocation metrics 184 encapsulation 30 enum 18 exit 310 extern 283 example of use 281 fclose 305 fgetc 304 file 302 scope 282 fixed manipulator 298 float 16 fopen 302 for statement 5 fprintf303 fputc 304 friend class 139 friend functions characteristics 139 fseek 305 function 32, 51, 285 ambiguity 62 argument matching 61 const 77 friend 137 inline 56 local variables 51 overloading 58 parameter matching 65 prototype 52,195 returning result to O/S 52 scope 282 static 91 template 63

25 Index 321 virtual 154 void 52 function call matching 61 function template 63 fundamental types 314 generic function 63 getc 304 goto 283 header file assert.h 311 ctype.h 306, 307 fstream 299 iomanip.h 297 math.h 308 stdarg.h 311 stddef.h 186 stdio.h 302 stdlib.h 309, 310 strstream 300 heap 288 hexadecimal number 315 identifier composed of 16 length 16 if statement 4, 6 ifstream 299 implementation ofa class 44 in line code 56, 57 pros vs. cons 57 inheritance 113 multiple 125 the same base class 129 virtual 129 initialising arrays 75 arrays of objects 147 inline function 56 int 16 integer promotions 23 iomanip.h 297 is a relationship 117 isalnum 306 isalpha 306 iscntrl306 isdigit 306 isgraph 306 islower 306 isprint 306 ispunct 306 isspace 306 istrstream 300 isupper 306 isxdigit 306 iterator 253 bag 253 label goto283 labs 309 left manipulator 298 life time auto 279 dynamic 279 static 279 linkage 281 literals 315 local scope 282 local name base 288 local variables 51 long 16 long double 16 lvalue 169 macro 213 #define 213 #endif216 #if 217 defined 218 #ifdef216 #ifndef217 #include 213 #Undef214 changing language 218 concatenation ##222 use in header file 219 manipulator ios: :fixed 298 ios::left 298 ios: :right 298

26 322 Index ios::scientific 298 ios::showpoint 298 ios:: showpos 298 ios::skipws'.299 resetiosflags 298 setiosflags 298 member functions characteristics 139 multiple inheritance 125 new 177 number 315 decimal 315 hexadecimal 315 octal 315 object 30 persistence 271 octal number 315 of stream 299 operator 1\ 20, 21! 20!= 19 % 18 & dyadic 20 monadic 169 &&20 * dyadic 18 monadic dyadic 18 monadic ,11 dyadic 18 monadic > 179 ->* * :: 44 :: example of use 91,161 < 19 «20 <= 19 == 19 >19 >= 19»20 address & 169 * 169 delete 177, 184 new 177, 184 precedence 312 sizeof " 20 operator precedence 312 operators inheritance rules 148 new and delete 186 ostrstream 300 out of line code 56, 57 overloading 57 «140 new 184 resolution 66 overloading delete 184 overloading resolution 65 parameter const reference 55 const value 55 default values to 60 reference 53 value 53 variable number 220 variable number of 59 parameterized type 83 persistence of objects 271 pointer polymorphism 188 polymorphism 153 using pointers 188 precedence operator 312 private visibility 120 promotions 22 integer 23 protected visibility 120

27 Index 323 prototype function 52 public visibility 120 putc 304 recursion 55 register 283 resetiosflags 298 return result from a program 52 return statement 34 right manipulator 298 rvalue 169 scientific manipulator 298 scope 282 class 282 file 282 function 282 local 282 setiosflags 298 short 16 showpoint manipulator 298 showpos manipulator 298 signed char 16 signed int 16 signed long 16 signed short 16 sizeof21 size_t 186,307 specification ofa class 44 srand 309 stack frame 288 statement break 8 continue 8 do while 6 for 5 if 4 return 34 switch 7 while 4 static 283 allocating static data members 91 life time 279 member functions 91 member variable 90 variable 89 static binding 128 static storage allocation metrics 184 stderr 304 stdin 304 stdout 304 storage class auto 283 extern 283 register 283 strcat 307 strcmp 307 strcpy 307 string escape sequences 313 strlen 307 strncmp 307 strncpy 307 struct 177, 183 bit-field 198 switch case label 7 default label 7 statement 7, 18 system 310 templates 83 tolower 307 toupper 307 truncation 62 type aggregate 285 arithmetic 285 char 16 double 16 enum 18 float 16 function 285 int 16 long 16 long double 16 scalar 285 short 16 signed char 16 signed int 16 signed long 16

28 324 Index signed short 16 unsigned char 16 unsigned int 16 unsigned long 16 unsigned short 16 types fundamental size 314 union 197 unsigned char 16 unsigned int 16 unsigned long 16 unsigned short 16 variable number of parameters access 311 vector 71 virtual inheritance 129 summary 167 virtual function 154 visibility 283 void 285 function 52 while statement 4 win 96 ws299 _cplusplus 218 _DATE_218 _FILE_ 215,218 _LINE_ 215,218 _TIME_218

Chapter 8 - Characters and Strings

Chapter 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 information

Contents. Preface. Introduction. Introduction to C Programming

Contents. Preface. Introduction. Introduction to C Programming c11fptoc.fm Page vii Saturday, March 23, 2013 4:15 PM Preface xv 1 Introduction 1 1.1 1.2 1.3 1.4 1.5 Introduction The C Programming Language C Standard Library C++ and Other C-Based Languages Typical

More information

C: How to Program. Week /May/28

C: How to Program. Week /May/28 C: How to Program Week 14 2007/May/28 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

More information

Chapter 15 - C++ As A "Better C"

Chapter 15 - C++ As A Better C Chapter 15 - C++ As A "Better C" Outline 15.1 Introduction 15.2 C++ 15.3 A Simple Program: Adding Two Integers 15.4 C++ Standard Library 15.5 Header Files 15.6 Inline Functions 15.7 References and Reference

More information

Chapter 8 C Characters and Strings

Chapter 8 C Characters and Strings Chapter 8 C Characters and Strings Objectives of This Chapter To use the functions of the character handling library (). To use the string conversion functions of the general utilities library

More information

SWEN-250 Personal SE. Introduction to C

SWEN-250 Personal SE. Introduction to C SWEN-250 Personal SE Introduction to C A Bit of History Developed in the early to mid 70s Dennis Ritchie as a systems programming language. Adopted by Ken Thompson to write Unix on a the PDP-11. At the

More information

A function is a named group of statements developed to solve a sub-problem and returns a value to other functions when it is called.

A function is a named group of statements developed to solve a sub-problem and returns a value to other functions when it is called. Chapter-12 FUNCTIONS Introduction A function is a named group of statements developed to solve a sub-problem and returns a value to other functions when it is called. Types of functions There are two types

More information

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University C Programming Notes Dr. Karne Towson University Reference for C http://www.cplusplus.com/reference/ Main Program #include main() printf( Hello ); Comments: /* comment */ //comment 1 Data Types

More information

Fundamentals of Programming. Lecture 11: C Characters and Strings

Fundamentals 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 information

C Libraries. Bart Childs Complementary to the text(s)

C Libraries. Bart Childs Complementary to the text(s) C Libraries Bart Childs Complementary to the text(s) 2006 C was designed to make extensive use of a number of libraries. A great reference for student purposes is appendix B of the K&R book. This list

More information

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University Fundamental Data Types CSE 130: Introduction to Programming in C Stony Brook University Program Organization in C The C System C consists of several parts: The C language The preprocessor The compiler

More information

cs3157: another C lecture (mon-21-feb-2005) C pre-processor (3).

cs3157: another C lecture (mon-21-feb-2005) C pre-processor (3). cs3157: another C lecture (mon-21-feb-2005) C pre-processor (1). today: C pre-processor command-line arguments more on data types and operators: booleans in C logical and bitwise operators type conversion

More information

Muntaser Abulafi Yacoub Sabatin Omar Qaraeen. C Data Types

Muntaser Abulafi Yacoub Sabatin Omar Qaraeen. C Data Types Programming Fundamentals for Engineers 0702113 5. Basic Data Types Muntaser Abulafi Yacoub Sabatin Omar Qaraeen 1 2 C Data Types Variable definition C has a concept of 'data types' which are used to define

More information

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and #include The Use of printf() and scanf() The Use of printf()

More information

Appendices E through H are PDF documents posted online at the book s Companion Website (located at

Appendices E through H are PDF documents posted online at the book s Companion Website (located at chtp7_printonlytoc.fm Page vii Monday, January 23, 2012 1:30 PM Appendices E through H are PDF documents posted online at the book s Companion Website (located at www.pearsonhighered.com/deitel). Preface

More information

C mini reference. 5 Binary numbers 12

C mini reference. 5 Binary numbers 12 C mini reference Contents 1 Input/Output: stdio.h 2 1.1 int printf ( const char * format,... );......................... 2 1.2 int scanf ( const char * format,... );.......................... 2 1.3 char

More information

CS3157: Advanced Programming. Outline

CS3157: Advanced Programming. Outline CS3157: Advanced Programming Lecture #8 Feb 27 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline More c Preprocessor Bitwise operations Character handling Math/random Review for midterm Reading: k&r ch

More information

CS3157: Advanced Programming. Outline

CS3157: Advanced Programming. Outline CS3157: Advanced Programming Lecture #12 Apr 3 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline Intro CPP Boring stuff: Language basics: identifiers, data types, operators, type conversions, branching

More information

Characters and Strings

Characters and Strings Characters and Strings 60-141: Introduction to Algorithms and Programming II School of Computer Science Term: Summer 2013 Instructor: Dr. Asish Mukhopadhyay Character constants A character in single quotes,

More information

Borland 105, 278, 361, 1135 Bounded array Branch instruction 7 break statement 170 BTree 873 Building a project 117 Built in data types 126

Borland 105, 278, 361, 1135 Bounded array Branch instruction 7 break statement 170 BTree 873 Building a project 117 Built in data types 126 INDEX = (assignment operator) 130, 816 = 0 (as function definition) 827 == (equality test operator) 146! (logical NOT operator) 159!= (inequality test operator) 146 #define 140, 158 #include 100, 112,

More information

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 4

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 4 BIL 104E Introduction to Scientific and Engineering Computing Lecture 4 Introduction Divide and Conquer Construct a program from smaller pieces or components These smaller pieces are called modules Functions

More information

Computer Programming

Computer Programming Computer Programming Make everything as simple as possible, but not simpler. Albert Einstein T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 1 Outline Functions Structure of a function

More information

Programming in C. Part 1: Introduction

Programming in C. Part 1: Introduction Programming in C Part 1: Introduction Resources: 1. Stanford CS Education Library URL: http://cslibrary.stanford.edu/101/ 2. Programming in ANSI C, E Balaguruswamy, Tata McGraw-Hill PROGRAMMING IN C A

More information

UNIT- 3 Introduction to C++

UNIT- 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 information

Computer Science XII Important Concepts for CBSE Examination Questions

Computer Science XII Important Concepts for CBSE Examination Questions Computer Science XII Important Concepts for CBSE Examination Questions LEARN FOLLOWIING GIVEN CONCEPS 1. Encapsulation: Wraps up data and functions under single unit through class. Create a class as example.

More information

Introduction to C++ Systems Programming

Introduction to C++ Systems Programming Introduction to C++ Systems Programming Introduction to C++ Syntax differences between C and C++ A Simple C++ Example C++ Input/Output C++ Libraries C++ Header Files Another Simple C++ Example Inline Functions

More information

CHAPTER 1 Introduction to Computers and Programming CHAPTER 2 Introduction to C++ ( Hexadecimal 0xF4 and Octal literals 031) cout Object

CHAPTER 1 Introduction to Computers and Programming CHAPTER 2 Introduction to C++ ( Hexadecimal 0xF4 and Octal literals 031) cout Object CHAPTER 1 Introduction to Computers and Programming 1 1.1 Why Program? 1 1.2 Computer Systems: Hardware and Software 2 1.3 Programs and Programming Languages 8 1.4 What is a Program Made of? 14 1.5 Input,

More information

I BSc(IT) [ Batch] Semester II Core: Object Oriented Programming With C plus plus - 212A Multiple Choice Questions.

I BSc(IT) [ Batch] Semester II Core: Object Oriented Programming With C plus plus - 212A Multiple Choice Questions. Dr.G.R.Damodaran College of Science (Autonomous, affiliated to the Bharathiar University, recognized by the UGC)Reaccredited at the 'A' Grade Level by the NAAC and ISO 9001:2008 Certified CRISL rated 'A'

More information

Programming in C++ 4. The lexical basis of C++

Programming in C++ 4. The lexical basis of C++ Programming in C++ 4. The lexical basis of C++! Characters and tokens! Permissible characters! Comments & white spaces! Identifiers! Keywords! Constants! Operators! Summary 1 Characters and tokens A C++

More information

6.096 Introduction to C++ January (IAP) 2009

6.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 information

CS2141 Software Development using C/C++ Stream I/O

CS2141 Software Development using C/C++ Stream I/O CS2141 Software Development using C/C++ Stream I/O iostream Two libraries can be used for input and output: stdio and iostream The iostream library is newer and better: It is object oriented It can make

More information

Scientific Programming in C V. Strings

Scientific Programming in C V. Strings Scientific Programming in C V. Strings Susi Lehtola 1 November 2012 C strings As mentioned before, strings are handled as character arrays in C. String constants are handled as constant arrays. const char

More information

c++ keywords: ( all lowercase ) Note: cin and cout are NOT keywords.

c++ 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 information

today cs3157-fall2002-sklar-lect05 1

today cs3157-fall2002-sklar-lect05 1 today homework #1 due on monday sep 23, 6am some miscellaneous topics: logical operators random numbers character handling functions FILE I/O strings arrays pointers cs3157-fall2002-sklar-lect05 1 logical

More information

Dr M Kasim A Jalil. Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson)

Dr M Kasim A Jalil. Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson) Lecture 9 Functions Dr M Kasim A Jalil Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson) Objectives In this chapter, you will learn: To understand how to construct programs modularly

More information

Introduction to C Language

Introduction 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 information

Review: Constants. Modules and Interfaces. Modules. Clients, Interfaces, Implementations. Client. Interface. Implementation

Review: Constants. Modules and Interfaces. Modules. Clients, Interfaces, Implementations. Client. Interface. Implementation Review: Constants Modules and s CS 217 C has several ways to define a constant Use #define #define MAX_VALUE 10000 Substitution by preprocessing (will talk about this later) Use const const double x =

More information

CSE2301. Functions. Functions and Compiler Directives

CSE2301. Functions. Functions and Compiler Directives Warning: These notes are not complete, it is a Skelton that will be modified/add-to in the class. If you want to us them for studying, either attend the class or get the completed notes from someone who

More information

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS Contents Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS 1.1. INTRODUCTION TO COMPUTERS... 1 1.2. HISTORY OF C & C++... 3 1.3. DESIGN, DEVELOPMENT AND EXECUTION OF A PROGRAM... 3 1.4 TESTING OF PROGRAMS...

More information

Characters, c-strings, and the string Class. CS 1: Problem Solving & Program Design Using C++

Characters, c-strings, and the string Class. CS 1: Problem Solving & Program Design Using C++ Characters, c-strings, and the string Class CS 1: Problem Solving & Program Design Using C++ Objectives Perform character checks and conversions Knock down the C-string fundamentals Point at pointers and

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

C PROGRAMMING. Characters and Strings File Processing Exercise

C PROGRAMMING. Characters and Strings File Processing Exercise C PROGRAMMING Characters and Strings File Processing Exercise CHARACTERS AND STRINGS A single character defined using the char variable type Character constant is an int value enclosed by single quotes

More information

Appendix A Developing a C Program on the UNIX system

Appendix A Developing a C Program on the UNIX system Appendix A Developing a C Program on the UNIX system 1. Key in and save the program using vi - see Appendix B - (or some other editor) - ensure that you give the program file a name ending with.c - to

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

Tokens, Expressions and Control Structures

Tokens, Expressions and Control Structures 3 Tokens, Expressions and Control Structures Tokens Keywords Identifiers Data types User-defined types Derived types Symbolic constants Declaration of variables Initialization Reference variables Type

More information

211: Computer Architecture Summer 2016

211: Computer Architecture Summer 2016 211: Computer Architecture Summer 2016 Liu Liu Topic: C Programming Data Representation I/O: - (example) cprintf.c Memory: - memory address - stack / heap / constant space - basic data layout Pointer:

More information

THE C STANDARD LIBRARY & MAKING YOUR OWN LIBRARY. ISA 563: Fundamentals of Systems Programming

THE C STANDARD LIBRARY & MAKING YOUR OWN LIBRARY. ISA 563: Fundamentals of Systems Programming THE C STANDARD LIBRARY & MAKING YOUR OWN LIBRARY ISA 563: Fundamentals of Systems Programming Announcements Homework 2 posted Homework 1 due in two weeks Typo on HW1 (definition of Fib. Sequence incorrect)

More information

Contents. 1 Introduction to Computers, the Internet and the World Wide Web 1. 2 Introduction to C Programming 26

Contents. 1 Introduction to Computers, the Internet and the World Wide Web 1. 2 Introduction to C Programming 26 Preface xix 1 Introduction to Computers, the Internet and the World Wide Web 1 1.1 Introduction 2 1.2 What Is a Computer? 4 1.3 Computer Organization 4 1.4 Evolution of Operating Systems 5 1.5 Personal,

More information

Contents. A Review of C language. Visual C Visual C++ 6.0

Contents. A Review of C language. Visual C Visual C++ 6.0 A Review of C language C++ Object Oriented Programming Pei-yih Ting NTOU CS Modified from www.cse.cuhk.edu.hk/~csc2520/tuto/csc2520_tuto01.ppt 1 2 3 4 5 6 7 8 9 10 Double click 11 12 Compile a single source

More information

Absolute C++ Walter Savitch

Absolute C++ Walter Savitch Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

More information

Split up Syllabus (Session )

Split up Syllabus (Session ) Split up Syllabus (Session- -17) COMPUTER SCIENCE (083) CLASS XI Unit No. Unit Name Marks 1 COMPUTER FUNDAMENTALS 10 2 PROGRAMMING METHODOLOGY 12 3 INTRODUCTION TO C++ 14 4 PROGRAMMING IN C++ 34 Total

More information

by Pearson Education, Inc. All Rights Reserved.

by Pearson Education, Inc. All Rights Reserved. The string-handling library () provides many useful functions for manipulating string data (copying strings and concatenating strings), comparing strings, searching strings for characters and

More information

AIR FORCE SCHOOL,BAMRAULI COMPUTER SCIENCE (083) CLASS XI Split up Syllabus (Session ) Contents

AIR FORCE SCHOOL,BAMRAULI COMPUTER SCIENCE (083) CLASS XI Split up Syllabus (Session ) Contents AIR FORCE SCHOOL,BAMRAULI COMPUTER SCIENCE (083) CLASS XI Split up Syllabus (Session- 2017-18) Month July Contents UNIT 1: COMPUTER FUNDAMENTALS Evolution of computers; Basics of computer and its operation;

More information

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things. A Appendix Grammar There is no worse danger for a teacher than to teach words instead of things. Marc Block Introduction keywords lexical conventions programs expressions statements declarations declarators

More information

Functions. Systems Programming Concepts

Functions. Systems Programming Concepts Functions Systems Programming Concepts Functions Simple Function Example Function Prototype and Declaration Math Library Functions Function Definition Header Files Random Number Generator Call by Value

More information

Chapter 8: Character & String. In this chapter, you ll learn about;

Chapter 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 information

A Fast Review of C Essentials Part I

A Fast Review of C Essentials Part I A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types

More information

Interview Questions of C++

Interview Questions of C++ Interview Questions of C++ Q-1 What is the full form of OOPS? Ans: Object Oriented Programming System. Q-2 What is a class? Ans: Class is a blue print which reflects the entities attributes and actions.

More information

C Functions. 5.2 Program Modules in C

C Functions. 5.2 Program Modules in C 1 5 C Functions 5.2 Program Modules in C 2 Functions Modules in C Programs combine user-defined functions with library functions - C standard library has a wide variety of functions Function calls Invoking

More information

Multiple Choice Questions ( 1 mark)

Multiple 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 information

C++ Quick Guide. Advertisements

C++ Quick Guide. Advertisements C++ Quick Guide Advertisements Previous Page Next Page C++ is a statically typed, compiled, general purpose, case sensitive, free form programming language that supports procedural, object oriented, and

More information

BLM2031 Structured Programming. Zeyneb KURT

BLM2031 Structured Programming. Zeyneb KURT BLM2031 Structured Programming Zeyneb KURT 1 Contact Contact info office : D-219 e-mail zeynebkurt@gmail.com, zeyneb@ce.yildiz.edu.tr When to contact e-mail first, take an appointment What to expect help

More information

10/23/02 21:20:33 IO_Examples

10/23/02 21:20:33 IO_Examples 1 Oct 22 22:07 2000 extractor1.c Page 1 istream &operator>>( istream &in, Point &p ){ char junk; in >> junk >> p.x >> junk >> p.y >> junk; return in; 2 Oct 22 22:07 2000 extractor2.c Page 1 istream &operator>>(

More information

Converting a Lowercase Letter Character to Uppercase (Or Vice Versa)

Converting a Lowercase Letter Character to Uppercase (Or Vice Versa) Looping Forward Through the Characters of a C String A lot of C string algorithms require looping forward through all of the characters of the string. We can use a for loop to do that. The first character

More information

Programming. C++ Basics

Programming. 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 information

C Programming Multiple. Choice

C Programming Multiple. Choice C Programming Multiple Choice Questions 1.) Developer of C language is. a.) Dennis Richie c.) Bill Gates b.) Ken Thompson d.) Peter Norton 2.) C language developed in. a.) 1970 c.) 1976 b.) 1972 d.) 1980

More information

+2 Volume II OBJECT TECHNOLOGY OBJECTIVE QUESTIONS R.Sreenivasan SanThome HSS, Chennai-4. Chapter -1

+2 Volume II OBJECT TECHNOLOGY OBJECTIVE QUESTIONS R.Sreenivasan SanThome HSS, Chennai-4. Chapter -1 Chapter -1 1. Object Oriented programming is a way of problem solving by combining data and operation 2.The group of data and operation are termed as object. 3.An object is a group of related function

More information

Strings and Stream I/O

Strings and Stream I/O Strings and Stream I/O C Strings In addition to the string class, C++ also supports old-style C strings In C, strings are stored as null-terminated character arrays str1 char * str1 = "What is your name?

More information

Lab 6. Review of Variables, Formatting & Loops By: Dr. John Abraham, Professor, UTPA

Lab 6. Review of Variables, Formatting & Loops By: Dr. John Abraham, Professor, UTPA Variables: Lab 6 Review of Variables, Formatting & Loops By: Dr. John Abraham, Professor, UTPA We learned that a variable is a name assigned to the first byte of the necessary memory to store a value.

More information

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Features 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 information

Programming in C and C++

Programming in C and C++ Programming in C and C++ 1. Types Variables Expressions & Statements Dr. Anil Madhavapeddy University of Cambridge (based on previous years thanks to Alan Mycroft, Alastair Beresford and Andrew Moore)

More information

Model Viva Questions for Programming in C lab

Model 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 information

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above P.G.TRB - COMPUTER SCIENCE Total Marks : 50 Time : 30 Minutes 1. C was primarily developed as a a)systems programming language b) general purpose language c) data processing language d) none of the above

More information

Streams - Object input and output in C++

Streams - Object input and output in C++ Streams - Object input and output in C++ Dr. Donald Davendra Ph.D. Department of Computing Science, FEI VSB-TU Ostrava Dr. Donald Davendra Ph.D. (Department of Computing Streams - Object Science, input

More information

CSE123. Program Design and Modular Programming Functions 1-1

CSE123. Program Design and Modular Programming Functions 1-1 CSE123 Program Design and Modular Programming Functions 1-1 5.1 Introduction A function in C is a small sub-program performs a particular task, supports the concept of modular programming design techniques.

More information

cs3157: c++ lecture #2 (mon-11-apr-2005) chronology of some programming languages... C++ vs Java identifiers.

cs3157: c++ lecture #2 (mon-11-apr-2005) chronology of some programming languages... C++ vs Java identifiers. cs3157: c++ lecture #2 (mon-11-apr-2005) chronology of some programming languages... today: language basics: identifiers, data types, operators, type conversions, branching and looping, program structure

More information

PIC10B/1 Winter 2014 Exam I Study Guide

PIC10B/1 Winter 2014 Exam I Study Guide PIC10B/1 Winter 2014 Exam I Study Guide Suggested Study Order: 1. Lecture Notes (Lectures 1-8 inclusive) 2. Examples/Homework 3. Textbook The midterm will test 1. Your ability to read a program and understand

More information

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

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 information

COMP322 - Introduction to C++ Lecture 02 - Basics of C++

COMP322 - Introduction to C++ Lecture 02 - Basics of C++ COMP322 - Introduction to C++ Lecture 02 - Basics of C++ School of Computer Science 16 January 2012 C++ basics - Arithmetic operators Where possible, C++ will automatically convert among the basic types.

More information

Structured programming

Structured programming Exercises 10 Version 1.0, 13 December, 2016 Table of Contents 1. Strings...................................................................... 1 1.1. Remainders from lectures................................................

More information

Axivion Bauhaus Suite Technical Factsheet MISRA

Axivion Bauhaus Suite Technical Factsheet MISRA MISRA Contents 1. C... 2 1. Misra C 2004... 2 2. Misra C 2012 (including Amendment 1). 10 3. Misra C 2012 Directives... 18 2. C++... 19 4. Misra C++ 2008... 19 1 / 31 1. C 1. Misra C 2004 MISRA Rule Severity

More information

Introduction to Programming Systems

Introduction to Programming Systems Introduction to Programming Systems CS 217 Thomas Funkhouser & Bob Dondero Princeton University Goals Master the art of programming Learn how to be good programmers Introduction to software engineering

More information

Computers Programming Course 5. Iulian Năstac

Computers 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 information

Structure of this course. C and C++ Past Exam Questions. Text books

Structure of this course. C and C++ Past Exam Questions. Text books Structure of this course C and C++ 1. Types Variables Expressions & Statements Alastair R. Beresford University of Cambridge Lent Term 2008 Programming in C: types, variables, expressions & statements

More information

C: Arrays, and strings. Department of Computer Science College of Engineering Boise State University. September 11, /16

C: Arrays, and strings. Department of Computer Science College of Engineering Boise State University. September 11, /16 Department of Computer Science College of Engineering Boise State University September 11, 2017 1/16 1-dimensional Arrays Arrays can be statically declared in C, such as: int A [100]; The space for this

More information

Outline. Computer Programming. Structure of a function. Functions. Function prototype. Structure of a function. Functions

Outline. Computer Programming. Structure of a function. Functions. Function prototype. Structure of a function. Functions Outline Computer Programming Make everything as simple as possible, but not simpler. Albert Einstein Functions Structure of a function Function invocation Parameter passing Functions as parameters Variable

More information

Course organization. Course introduction ( Week 1)

Course organization. Course introduction ( Week 1) Course organization Course introduction ( Week 1) Code editor: Emacs Part I: Introduction to C programming language (Week 2-9) Chapter 1: Overall Introduction (Week 1-3) Chapter 2: Types, operators and

More information

Engineering Problem Solving with C++, Etter/Ingber

Engineering Problem Solving with C++, Etter/Ingber Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs C++, Second Edition, J. Ingber 1 Simple C++ Programs Program Structure Constants and Variables C++ Operators Standard Input

More information

8. Characters, Strings and Files

8. Characters, Strings and Files REGZ9280: Global Education Short Course - Engineering 8. Characters, Strings and Files Reading: Moffat, Chapter 7, 11 REGZ9280 14s2 8. Characters and Arrays 1 ASCII The ASCII table gives a correspondence

More information

Engineering Problem Solving with C++, 3e Chapter 2 Test Bank

Engineering Problem Solving with C++, 3e Chapter 2 Test Bank 1. Match each of the following data types with literal constants of that data type. A data type can be used more than once. A. integer B 1.427E3 B. double D "Oct" C. character B -63.29 D. string F #Hashtag

More information

C Legacy Code Topics. Objectives. In this appendix you ll:

C Legacy Code Topics. Objectives. In this appendix you ll: cppfp2_appf_legacycode.fm Page 1 Monday, March 25, 2013 3:44 PM F C Legacy Code Topics Objectives In this appendix you ll: Redirect keyboard input to come from a file and redirect screen output to a file.

More information

What we will learn about this week:

What we will learn about this week: What we will learn about this week: Streams Basic file I/O Tools for Stream I/O Manipulators Character I/O Get and Put EOF function Pre-defined character functions Objects 1 I/O Streams as an Introduction

More information

Data Types and Variables in C language

Data Types and Variables in C language Data Types and Variables in C language Basic structure of C programming To write a C program, we first create functions and then put them together. A C program may contain one or more sections. They are

More information

Basic Types, Variables, Literals, Constants

Basic Types, Variables, Literals, Constants Basic Types, Variables, Literals, Constants What is in a Word? A byte is the basic addressable unit of memory in RAM Typically it is 8 bits (octet) But some machines had 7, or 9, or... A word is the basic

More information

Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts

Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie, Absolute C++, by Walter

More information

Review Topics. Final Exam Review Slides

Review Topics. Final Exam Review Slides Review Topics Final Exam Review Slides!! Transistors and Gates! Combinational Logic! LC-3 Programming!! Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox,

More information

PART I. Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++.

PART I.   Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++. Unit - III CHAPTER - 9 INTRODUCTION TO C++ Choose the correct answer. PART I 1. Who developed C++? (a) Charles Babbage (b) Bjarne Stroustrup (c) Bill Gates (d) Sundar Pichai 2. What was the original name

More information

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

B.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 information

File Handling in C. EECS 2031 Fall October 27, 2014

File Handling in C. EECS 2031 Fall October 27, 2014 File Handling in C EECS 2031 Fall 2014 October 27, 2014 1 Reading from and writing to files in C l stdio.h contains several functions that allow us to read from and write to files l Their names typically

More information

System Design and Programming II

System Design and Programming II System Design and Programming II CSCI 194 Section 01 CRN: 10968 Fall 2017 David L. Sylvester, Sr., Assistant Professor Chapter 10 Characters, Strings, and the string Class Character Testing The C++ library

More information