TakeHomeQuiz - CSC 124 Take Home Quiz Due 10/26/07 The...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CSC 124 Take Home Quiz Due 10/26/07 The purpose of this quiz is to help us put together some specific items we have learned so far. For each item, you are to write (1) an explanation and a (2) short sequence of instructions . If you do a great job with this, you then have a very good quick reference material for you at your disposal all made by you. For example: Demonstrate use of cin and cout Answer: (1): cin and cout: input and output stream variables. cin uses extraction operator, >>, to extract data from standard input device. cout uses insertion operator,<<, todisplay results on a standard output device. (2) #include<iostream> int main () { int a; char ch; double c; cout<<” Enter an integer number followed by a character and then a double”<<end; cin>>a; cin>>ch; cin>>double; return 0 ; } It is strongly advisable that you compile and run some of those instructions so as to feel comfortable using them. Make sure you make a habit of commenting lines and organizing code. For all demonstrations, make examples of your own. A- Demonstrate use of each of the following: Chapter 2 and 3 items 1- the predefined function pow The power function can be used to calculate x^y in a program. The numbers in the function pow are called arguments or parameters. EX: pow (x,y) = x^y 2- type conversion (int, double, character) ( PG 47) To avoid implicit type coercion, C++ provides for explicit type conversion through the use of a cast operator. The cast operator is also called type conversion. EX: static_cast<dataTypeName> (expression) 3- cin and get function (PG 125) The variable cin can access the stream function get, which is used to read chatacyer data. The get function inputs the very next character, including white space characters from the input stream and stores it in the memory location indicated by its argument. EX: cin.get (varChar);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4- using string data type (initialize a variable to a string value and print result to the screen) (PG 79) To use the string data type, you need to access its definition from the header file string. EX: #include <string> String a; Cout << “Enter a string” Cin >> a; Cout << a; INPUT: This is a test OUTPUT: Enter a string. This is a test. 5- ignore function (PG 126) When you want to process only partial data (say, within a line), you can use the stream function ignore to discard a portion of the input. EX: cin.ignore (inExp, chExp); 5- putback and peek functions (PG 128) The stream function putback let’s you put the last character extracted from the input stream by the get function back into the input stream. EX: istreamVar.putback (ch1); The stream function peek looks into the input stream and tells you what the next character is without removing it from the input stream. EX: ch = istreamVar.peek ( );
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This test prep was uploaded on 04/21/2008 for the course CSC 120 taught by Professor Goodside during the Spring '07 term at California University of Pennsylvania.

Page1 / 8

TakeHomeQuiz - CSC 124 Take Home Quiz Due 10/26/07 The...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online