Exam 2 Study Guide
Exam 2 Study Guide CSCI 240
Popular in Computer programming in C++
CHMY 141N - 00
verified elite notetaker
Popular in ComputerScienence
Mariah J. Bibbs
verified elite notetaker
Bio 114 (Science, Dr. Hyman, Organisms)
verified elite notetaker
This 0 page Study Guide was uploaded by Grace Notetaker on Tuesday November 10, 2015. The Study Guide belongs to CSCI 240 at Northern Illinois University taught by margie musich in Fall 2015. Since its upload, it has received 206 views. For similar materials see Computer programming in C++ in ComputerScienence at Northern Illinois University.
Reviews for Exam 2 Study Guide
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 11/10/15
Data Types lnt oatcharstringdoube Keyword const denotes that the variable never changes Const char points to a constant character39s address ASCII stands for the American Standard Code for Information Interchange Allows you to use a character as an integer representation Ex char ch39A Int l Cout ltlt intch This is typecasting lt temporaly makes the character ch an integer this will display he integer representation of ch which is 65 Character functions Toupper and tolower allow you to convert character cases This function tests if the passed in character is a digit It returns true if the isdi it g character 1s a d1g1t and false otherw1se This function tests if the passed in character is alphabetic It returns true if the 1sa1pha character 1s a alphabet1c and false otherw1se isu er This function tests if the passed in character is an uppercase alphabetic character pp It returns true if the character is an uppercase character and false otherwise This function tests if the passed in character is a lowercase alphabetic character It 1slower returns true 1f the character 1s a lowercase character and false otherw1se isalnum This function tests if the passed in character is an alphanumeric character It returns true if the character is alphanumeric and false otherwise This function tests if the passed in character is a whitespace character space tab isspace newline etc It returns true if the character is a whitespace character and false otherwise This function tests if the passed in character is a punctuation character It is unct p returns true 1f the character 1s punctuatlon and false otherw1se Arrays Arrays are a set of whatever data type you declared For example int a3 this is a declaration of an array that holds 3 integers lnt a3123 input values into the area CallbyReference To pass an argument to a function by reference so that the function can change it you must 0 declare a variable of the proper type in the calling program to hold the value value that Will be passed and changed 0 use an amp in the function prototype and header after the data type of the argument 0 alter the argument using its local name in the function directly Here is an example Caller prototype void fh intamp variable declaration int num fUnction call fhnum Function void fh int ampi actually stores 10 into num back in the caller i 10 Notice that if you look at the function call itself you can39t tell if it is passbyvalue or passbyreference Only by looking at the function prototype or header can you tell that the argument is passed by reference so it can be altered Likewise if you look in the function body you can39t tell The only way to tell is to look at the function prototype or header That39s What the C compiler looks at When it sees that amp it Will quietly arrange to pass the address of the variable to the function so the function can access the original So passbyreference is really passing an address but it39s done automatically when you use the amp Here is the divide function and calling code mentioned above Caller prototype void divide int int intamp intamp declarations int numl 20 num2 6 quo rem fUnction call divide numl num2 quo rem now quo has a value of 3 and rem has a value of 2 Function void divide int dividend int divisor intamp q intamp r dividend divisor dividend divisor um I Notice that we passed the divisor and dividend by value since we just wanted to use their values and not alter them We passed the quotient and remainder by reference since the purpose of the function is to alter both of these values Notice too that quotient and remainder were not initialized by the caller since their values are never actually used in the function they are just assigned values But the divisor and dividend were initialized since their values were used to compute the answers For example remember swap as explained in lecture It could be written as a function as follows void swap double a int top int small I double temp temp atqp atqp asmall asmall temp In this case we had to pass the array and two integers to serve as the subscripts of the elements we wanted to swap because the only way to use a function to change a part of the array was to pass the whole thing We would call it as follows swap ar top s Now however we could write it using reference arguments void rSwap double amp vall double amp valZ I double temp temp vall vall valZ va12 temp And it would be called by code like this rSwap artqp arS i In fact any two double in memory could be swapped using this function now not just doubles in a particular array double first 47 double second 68 rSwapfirst second Here is a summary of a small subset of the string functions The arguments called s1 and s2 are names of arrays of char A quotvalid stringquot is one with a null terminator strcpys1 s2 This function will copy s2 into s1 s1 may or may not have a valid string in it s2 must be a valid string either a character array With a null terminator OR a string literal s2 must not be bigger than s1 or array over ow Will result strcats1 s2 This function concatenates s2 to the end of SI Both s1 and s2 must be valid strings but s2 could be a string literal There must be room in SI for the entire result int strlens1 This function returns the integer length of SI This is the number of chars in SI but DOES NOT include the null terminator int strcmps1s2 This function compares the two string arguments alphabetically It returns 0 a positive value if s1 is alphabetically greater than s2 0 a negative value if s1 is alphabetically less than s2 0 0 if s1 is alphabetically equal to s2 Create a string by de ning an array of characters Char a4 AOquotsquotA1 39a and so on Test your knowledge and take the practice exam on the course webpage
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'