CIS 3142 Advice — Chapter 1

CISC 3142
Programming Paradigms in C++
Part 1 — Introduction
Chapter 2 — A Tour of C++: The Basics

Reading from the Text

Chapter 2 — A Tour of C++ : The Basics

Overview

Primarily the imperative features and topics we've already introduced in the Sample Programs lecture

Topics

Declarations

A declaration is a statement that introduces a name into the program. It specifies a type for the named entity:

auto

Pointers

Arrays

References

User-defined Types

Structures
Classes
class Stack {
public:
	Stack();			// (default) constructor
	void push(int val);		// function headers
	int pop();
	bool isEmpty() const;		// 'const' indicates the receiving object is not modified in function
private:
	static int MAX_SIZE = 100;	// static primitive type can be initialized 'in place'
	int arr[MAX_SIZE];		// data members
	int tos;
};
Member Initializer List
There is a specific syntax for the initialization of data members in a constructor:
class Counter {
	Counter(int limit) : val(0), limit(limit) {…}
	…
private:
	int count;
	int limit;
};
The notation : val(0), limit(limit) is a list of data-members followed by a parenthesized initializer: data-member(expression), …

Enumerations
enum class DayOfWeek {SUN, MON, TUE, WED, THU, FRI, SAT}
…
DayOfWeek dow;
…
dow = DayOfWeek::WED;

Modularity