Basics
Basics
Lecture 2
COP 3014 Fall 2018
Identifiers are the names for things (variables, functions, etc) in the
language. Some identifiers are built-in, and others can be created
by the programmer.
I User-defined identifiers can consist of letters, digits, and
underscores
I Must start with a non-digit
I Identifiers are case sensitive (count and Count are different
variables)
I Reserved words (keywords) cannot be used as identifiers
Style Conventions for Identifiers
numStudents = 10;
weight = 160.35;
letter = ‘A’;
Initializing Variables
#include <iostream>
using namespace std;
I The using statement tells the compiler that all uses of these
names (cout, cin, etc) will come from the ”standard”
namespace.
Using the Output Stream
int numStudents;
cin >>numStudents; // read an integer
double weight;
cin >>weight; // read a double
cout.setf(ios::showpoint);
// so that decimal point will always be shown
cout.precision(2);
// sets floating point types to print to 2
decimal places (or use your desired number)
cout.setf(ios::scientific);
// float types formatted in exponential notation
Magic Formula
cout <<fixed;
// uses the "fixed" stream manipulator
cout <<showpoint;
// uses the "showpoint" stream manipulator