CISC 181: Introduction to
Computer Science
An introduction to the language of C++ for students
with programming experience.
Meeting times: Tuesday/Thursday, 4:30 - 6:15PM
Lab time: Tuesdays, 6:30 – 8:00 PM
TA: Scott Grauer-Gray
Instructor: Eric Schrag
Welcome!
●
A little about me:
–
–
●
I am a graduate student here at UD
I received my M.S. in Computer Science in 2005
Things to know (also on your syllabus)
–
–
–
–
Course website
TA's email address
My email address
Course and Lab meeting time
What will CISC 181 cover?
●
We will
–
–
–
–
–
–
Review UNIX use and C programming practices
Discuss proper programming standards
Learn about memory in computers
Learn basic data structures
Learn about Object Oriented Programming and
the use of Classes
Discuss some basic algorithms like sorting
About C++
●
●
C++ was made by Bjarne Stroustrup in 1970
C++ is a compiled language
–
–
–
–
●
The code's syntax is checked in advance
Then object files are created
Which are then compiled into an executable file
Compiled code is different for every machine
type
C++ is “Unmanaged”
–
This means that YOU, the programmer, are
responsible for memory!
Today's Lecture
●
Since the course is 10 weeks instead of 14,
we're going to dive right in today
–
–
–
–
●
Unix refresher
C refresher
Intro to basic C++ Input/Output
Coding Standards
There will be a lab today after this lecture!
–
A basic introductory lab to get you back into the
swing of things
Unix Refresher
●
●
●
You'll be working this summer on the Sun
Blades when you're in lab.
Outside of lab, you can either use machines
in the lab, in Smith Basement, or you can
connect from home.
To connect from home (and this is also what
I'll demo things on in class) use Secure Shell
SSH.
Secure Shell SSH
●
Available at http://udeploy.udel.edu/index.html
Basic UNIX commands
●
●
●
●
●
●
●
●
●
mkdir – Creates a new directory
cd – Changes to a different directory
pwd – Tells you what directory you are in
ls – Lists the files in your directory
more – a way to read files interactively
cat – A fast file display
script – A command to capture screen I/O
And more.
Let's do a demo!
C/C++ refresher
●
A lot of the things you learned in C are the
same or very similar in C++
–
–
–
–
–
Variables and Assignment
Conditional Statements
Control Structures
Mathematical Operators
Basic data types
Making a C++ program
●
There are six basic steps for a program
–
–
–
–
–
–
Editing code – This is when you write code.
Preprocessing \
Compiling
|- This is the compiler's job.
Linking
/
Loading – Bringing it into memory
Executing – The actual runtime
C++ - Basic Variables
●
●
●
●
int testInteger, testIntegerTwo;
char letter = 'a';
const float pi = 3.142;
Declaring variables is telling the compiler:
–
–
●
The type of data you want to store
An identifier for the data (a name)
Variables can be declared constant if they
should not change.
C++ - Assignment
●
●
●
●
testInteger = 7;
testInteger = 4 + (testInteger2 = 6);
Assignment is done using the assignment
operator: =
Assignments always have a variable on the
left hand side, and an expression on the right
hand side
Assignment
●
●
●
The right hand side is evaluated, then the left
hand variable is set to the right hand side.
The right hand side can be complex!
Order of operations can come in to play here;
we will discuss it more later.
Basic Math Operators
+ :
- :
* :
/ :
%:
++:
-- :
Addition operator
Subtraction operator
Multiplication operator
Division operator
Modulus (or Remainder) operator
Increment operator
Decrement operator
Conditional Statements
●
These are operators that evaluate differently
depending on a comparison
–
–
–
–
–
–
●
<
<=
>=
>
==
!=
They compare the left and right side, and
evaluate to true or false (and if you use that
as an int, 1 or 0)
Operator Precedence
●
●
●
●
●
●
●
1: ()
2: *,/,%
3: +,4: << , >>
5: <, <=, >, >=
6: ==, !=
7: =
Assignments and Equality
●
== and = look very similar, but are very
different. What will happen in the code below?
----------------------------------------------------int a = 4;
if(a = 7)
cout << “Equal to 7!” << endl;
else
cout << “Not equal to 7!” << endl;
Type Casting
●
●
●
●
We've discussed division with floats versus
division with ints and seen the difference.
What if you need to divide two integers and
get an accurate value, though?
You can cast one of the variables to a float or
double, and get the precisions you need!
Casting is a method that allows you to
change the type of a value.
How can you cast variables?
●
Old ways: (Don't use these anymore!)
–
–
●
New ways:
–
–
–
–
●
(double)feetWalked
double(feetWalked)
static_cast<type>(expression)
const_cast<type>(expression)
dynamic_cast<type>(expression)
reinterpret_cast<type>(expression)
For now, static_cast is all you need to know.
Coding Style
●
●
Before we move on, let's look at some code.
It's important to get into good coding habits
now!
Is this code easy to
understand?
#include <iostream>
using namespace std;
float calc(int, int);
int main(){
int x = 4;
int y = 7;
cout << calc(x,y) << endl;
}
float calc(int x, int y){
return ((static_cast<float>(x)/y)*9);
}
How about this code?
#include <iostream>
using namespace std;
float calculateERA(int, int);
int main(){
int earnedRunsToday = 4;
int inningsPitchedToday = 7;
cout << calculateERA(earnedRunsToday,
inningsPitchedToday) << endl;
}
float calculateERA(int ER, int IP){
float runsPerInning = static_cast<float>(ER)/IP;
return (runsPerInning*9);
}
How about this code?
/*****************************
* Author: Eric Schrag
* This is a simple earned run average calculator.
* You can change the earned runs and innings pitched
* variables to find out what an ERA for that game is.
*****************************/
#include <iostream>
using namespace std;
float calculateERA(int, int);
int main(){
int earnedRunsToday = 4;
int inningsPitchedToday = 7;
cout << calculateERA(earnedRunsToday, inningsPitchedToday) << endl;
}
/***************************
* calculateERA takes two arguments: Earned Runs and
* Innings Pitched. It then calculates ERA by the formula (ER/IP)*9.
***************************/
float calculateERA(int ER, int IP){
float runsPerInning = static_cast<float>(ER)/IP;
return (runsPerInning*9);
}
Coding Standard
●
Following good coding standards is crucial!
●
A common standard lets other people:
–
–
–
–
●
Understand your code easier
Learn what's going on faster
Maintain and reuse code better
Helps YOU remember what your code is doing!
Following a standard is a good general
practice.
A Coding Standard to Follow
●
A Comment Block at the top of each file
–
–
–
●
●
●
●
●
●
Author Name
Date
Description of the file's purpose: what does the
code in here do?
Descriptive Variable Names
Descriptive Function Names
Consistent Case: namesLikeThis
Indent in loops
No magic numbers
Use constants for numbers that are always
the same
Basic C++ Input/Output
●
●
●
●
●
Using the library <iostream> (more on
libraries later) you can access cin, cout, and
cerr.
cout is the standard output stream
cin is the standard input stream
cerr is the standard error stream
You can use << and >> (the insertion and
extraction operators) to manipulate these.
Printing using cout
●
●
cout is the stream that outputs to the
console.
You can print to the screen using cout with
the insertion operator:
–
–
–
●
cout << “Hello, class.” << endl;
cout << “You “ << “can “ << “print many things”;
cout << “Even “ << (2 + 2 + x) << “ expressions”;
You can print newlines by using either the
endl statement, or “\n”.
Formatting in cout
●
●
If you want to format your output, there are
special stream functions to do so.
For now, this is your “magic formula”
–
–
–
●
●
●
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2)
This will let you have only the last two
decimal points showing.
Whatever number is in precision will be the
amount of decimal places shown.
After this code, anything to cout after will use
this format.
Output with cerr
●
●
●
●
cerr is the standard error stream.
It also generally writes to the screen.
It is useful to know in that you can send
different streams to different files.
So, if you want to capture regular output, but
not errors
–
–
–
Put normal things on cout
Put error statements on cerr
You can then pipe them to different files.
Input using cin
●
●
●
cin is the standard input stream
It lets you capture input from the keyboard.
You can use it like you use cout, but
backwards:
–
–
●
●
cin >> aUsersNumber;
cin >> userNumberOne >> userNumberTwo;
It will wait for input from the keyboard – after
an enter press, it then reads what was typed
into the variable(s).
Input can be separated by spaces, or entered
one at a time with return presses each time.
C++ Libraries
●
●
●
C++ has many standard libraries that contain
useful code.
We've seen this already with <iostream>
You can include these libraries with #include
–
●
●
#include <iostream>
Libraries also have namespaces – these are
collections of name definitions. Functions can
have different definitions in different
namespaces.
For now, we can just discuss the standard
namespace.
C++ libraries
●
Access namespaces with the using directive
–
●
If you didn't want to use everything from std
–
●
#include <iostream>
using namespace std;
#include <iostream>
using std::cin;
using std::cout;
C++ is in transition. The compilers on
Strauss work right, you may need to use
different library names. (p.38, Savitch)
© Copyright 2026 Paperzz