0% found this document useful (0 votes)
14 views

Introduction To C++

This document provides an introduction and overview for a course on C++ programming. It outlines the course objectives which are to learn the basics of C++, how to compile and run programs, and use C++ to implement small programs. It also describes the course structure, assumptions, terminology related to programming and the C++ language, a basic C++ program structure, and a first program example to sum two numbers. Key aspects of C++ like comments, header files, data types, variables, and I/O are also introduced.

Uploaded by

José Manuel
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Introduction To C++

This document provides an introduction and overview for a course on C++ programming. It outlines the course objectives which are to learn the basics of C++, how to compile and run programs, and use C++ to implement small programs. It also describes the course structure, assumptions, terminology related to programming and the C++ language, a basic C++ program structure, and a first program example to sum two numbers. Key aspects of C++ like comments, header files, data types, variables, and I/O are also introduced.

Uploaded by

José Manuel
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 17

Introduction to C++

CS 160

INTEC CS160 - Jeanine Ingber


Jeanine Ingber

Phone: 277-1401
email: [email protected]
url: www.cs.unm.edu/~ingber/

INTEC CS160 - Jeanine Ingber


INTEC Information
 Course Coordinator:
– Sara Reed
– 844-6343
 Tape Library
– ILC 109
– Check tapes out overnight 4pm-8am

INTEC CS160 - Jeanine Ingber


Video Tapes
 Sign them out
 Don’t keep them longer than overnight

INTEC CS160 - Jeanine Ingber


Course Objectives
 Learn the basics of the C++ programming
language
 Understand how to compile and run a C++
program
 Use C++ to implement small programs

INTEC CS160 - Jeanine Ingber


My Assumptions
 Knowledge of
– a text editor
– files
– variables
– I/O
– sequential programming

INTEC CS160 - Jeanine Ingber


Course Structure
 Interactive! Lecture
– Please feel free to ask questions at any time
 Lab Exercises
– Attempt every assignment
– Grading is a check, plus comments
– Recommended due date is beginning of next class
meeting
– Turn in source code plus sample runs of your
program.
INTEC CS160 - Jeanine Ingber
The C++ Programming Language
 A superset of C
– C++ compilers can be used to compile C
programs
 Supports
– Object Oriented Programming (OOP)
– Templates
– Overloading of functions and operators
 Best to think of C++ as its own language
INTEC CS160 - Jeanine Ingber
Terminology
 Operating System
– unix, windows, linux, ...
 Source Code
– Printable/Readable Program file
 Object Code
– Nonprintable machine readable file
 Executable Code
– Nonprintable executable code
 Compiler
– Converts source code to object code
 Linker
– Converts object code to executable code

INTEC CS160 - Jeanine Ingber


Terminology
 Syntax errors
– reported by the compiler
 Linker errors
– reported by the linker
 Execution/Run-time errors
– reported by the operating system
 Logic errors
– not reported

INTEC CS160 - Jeanine Ingber


Program Cycle - Following Design

O bject E xecuta ble


C om piler L inker CPU
file file

S ource S yntax
file errors

linker run tim e


E ditor e rro rs errors

INTEC CS160 - Jeanine Ingber


Basic C++ Program Structure
/***********************************************************************
* Header Comments
***********************************************************************/
global declarations

int main()
{
declarations and executable statements
return 0;
}//end block of main

INTEC CS160 - Jeanine Ingber


First Program - sum two numbers
/
****************************************************************************
* Sum two numbers
****************************************************************************
/

#include <iostream> //declares standard I/O library


using namespace std;

int main() //must have one and only one function named main
{
int number1, number2; //declare two integer variables
cout << “enter two integers” << endl; //prompt for input
cin >> number1 >> number2; //input values for two variables from keyboard
cout << number1 + number2; //output sum of two numbers to the screen
return 0;
}//end block of main
INTEC CS160 - Jeanine Ingber
First Program
•Comments have two forms in C++
•//Single line comments
•/*Multi-line comments*/

•#include files
•<filename.h> //Standard C library header file
•<filename> //Standard C++ library files
•“myfile.h” //Your files (need full path)
•using namespace std;
INTEC CS160 - Jeanine Ingber
Simple I/O

cin
• is an istream object
•streams input from standard input
•uses the >> (input operator)

cout
•is an ostream object
•streams output to standard output
•uses the << (output) operator

INTEC CS160 - Jeanine Ingber


C++ Data Types
Keyword Example of a constant
bool true
char ‘5’
int 25
double 25.0

INTEC CS160 - Jeanine Ingber


Variables and Identifiers
A variable is a memory location. The name of the variable
(the identifer) is the address of the memory location.
Identifiers
•case sensitive
•must begin with a letter or underscore
•consist of letter, digits and underscore only (no special characters)
•can not use reserve words (key words)

INTEC CS160 - Jeanine Ingber

You might also like