80 likes | 266 Views
CSC 200. Lecture 3 1/27/06 Matt Kayala. Numerical Computation. Maple example of Computer Algebra system Symbolic Computation We could build a system like this with C++ At the level we are at, there are facilities for Numerical Computation Library that must be included #include<cmath>.
E N D
CSC 200 Lecture 3 1/27/06 Matt Kayala
Numerical Computation • Maple example of Computer Algebra system • Symbolic Computation • We could build a system like this with C++ • At the level we are at, there are facilities for Numerical Computation • Library that must be included #include<cmath>
Strings • char data type holds a single character • Data type to hold more than one char (ie. a “string”) would be useful. • Built into a standard library. • Add this to your code: #include <string>
Strings 2 • Now string is a data type, just like int, double, char, bool. • Can assign vals, use in cin/cout stmts • Ex: string myName = “Matt Kayala”, yourName; cout << “My name is “ << myName << endl; cout << “What is your name? “; cin >> yourName;
Input with Strings • cin with strings inputs up to whitespace • Ex. On this line: cin >> yourName; (I type:)Matt[space]Kayala[enter] Then only up to the first space would be “inserted” into the var yourName. • Is there a way to get around this?
getline() • To get a whole line from the user (not just up to the first whitespace character) we must use “getline” • Syntax: getline(cin, str_var_name); • What it does: extracts up to the newline character (ie. user presses enter) • Ex: string yourName; getline(cin, yourName);