SlideShare a Scribd company logo
1 of 33
C++ Overview


•   History and major features of C++
•   Input and output
•   Preprocessor directives
•   Comments




    January 26, 2012   CS410 – Software Engineering              1
                                 Lecture #2: Hello, C++ World!
History of C++
1972: C language developed at Bell Labs
   •Dennis Ritchie wrote C for Unix OS
   •Needed C for work with Unix
late 70s: C becomes popular for OS development by
   many vendors
   •Many variants of the language developed
   •ANSI standard C in 1987-89
History of C++ (continued)
early 80s: Bjarne Stroustrup adds OO features to C
  creating C++
90s: continued evolution of the language and its
  applications
   •preferred language for OS and low level
 programming
   •popular language for application development
   •low level control and high level power
History of C++
•   1980: “C-with-classes” developed by Bjarne Stroustrup




•   1983: C-with-classes redesigned and called C++
•   1985: C++ compilers made available
•   1989: ANSI/ISO C++ standardization starts
•   1998: ANSI/ISO C++ standard approved
    January 26, 2012   CS410 – Software Engineering              4
                                 Lecture #2: Hello, C++ World!
Conceptually what is C++


Alternatives:
   •is it C, with lots more options and features?
   •is it an OO programming language with C as
its core?
   •is it a development environment?
On most systems it is a development environment,
  language, and library, used for both procedural
  and object oriented programming, that can be
  customized and extended as desired
Versions of C++



ANSI C++
Microsoft C++ (MS Visual C++ 6.0)
Other vendors: Borland, Symantec, Turbo, …
Many older versions (almost annual) including
  different version of C too
Many vendor specific versions
Many platform specific versions
For this class: Unix / Linux based versions
   •g++
Characteristics of C++ as a Computer
                 Language
Procedural
Object Oriented
Extensible
...
Other OO Languages
Smalltalk
   •pure OO language developed at PARC
Java
   •built on C/C++
   •objects and data types
Eifel and others
What you can do with C++



Apps (standalone, Web apps, components)
Active desktop (Dynamic HTML, incl Web)
Create graphical apps
Data access (e-mail, files, ODBC)
Integrate components w/ other languages
Major Features of C++
•   Almost upward compatible with C
     •Not all valid C programs are valid C++
      programs.
    • Why?
    • Because of reserved words in C++ such as
      ‘class’
•   Extends C with object-oriented features
•   Compile-time checking: strongly typed
•   Classes with multiple inheritance
•   No garbage collection, but semi-automatic
    storage reclamation
    January 26, 2012    CS410 – Software Engineering              10
                                  Lecture #2: Hello, C++ World!
Disadvantages of C++


Tends to be one of the less portable languages
Complicated?
    •40 operators, intricate precedence, pointers,
 etc.
    •can control everything
    •many exceptions and special cases
    •tremendous libraries both standard, vendor
 specific, and available for purchase, but all are
 intricate
Aspects above can result in high maintenance
Advantages of C++


Available on most machines
Can get good performance
Can get small size
Can manage memory effectively
Can control everything
Good supply of programmers
Suitable for almost any type of program (from
  systems programs to applications)
Sample C++ Program
#include <iostream>                                     if (enteredPasswd == deptChairPasswd)
#include <string>                                       {
using namespace std;                                        cout << "Thank you!" << endl;
                                                            passwdOK = true;
int main()                                              }
{                                                       else
   string deptChairName, deptChairPasswd,               {
    enteredPasswd;                                          cout << "Hey! Are you really " <<
   bool passwdOK;                                            deptChairName << "?n";
   int attempts = 0;                                        cout << "Try again!n";
                                                            passwdOK = false;
  deptChairName = GetDeptChairName();                   }
  deptChairPasswd = GetDeptChairPasswd();             }
                                                      while (!passwdOK && attempts < 3);
  cout << "How are you today, " <<                    if (passwdOK)
   deptChairName << "?n";                                SetNewParameters();
  do                                                  else
  {                                                   {
     cout << "Please enter your password: ";              Shout(“Warning! Illegal access!”);
     cin >> enteredPasswd;                                CallCampusPolice();
     attempts++;                                      }
                                                      return 0;
                                                  }
     January 26, 2012   CS410 – Software Engineering                                       13
                                  Lecture #2: Hello, C++ World!
Input and Output
• Some standard functions for input and output are
  provided by the iostream library.
• The iostream library is part of the standard library.
• Input from the terminal (standard input) is tied to
  the iostream object cin.
• Output to the terminal (standard output) is tied to
  the iostream object cout.
• Error and warning messages can be sent to the user
  via the iostream object cerr (standard error).


  January 26, 2012   CS410 – Software Engineering              14
                               Lecture #2: Hello, C++ World!
Input and Output
• Use the output operator (<<) to direct a value to
  standard output.
• Successive use of << allows concatenation.
• Examples:
     •cout << “Hi there!n”;
     •cout << “I have “ << 3 + 5 << “ classes today.”;
     •cout << “goodbye!” << endl; (new line & flush)




  January 26, 2012   CS410 – Software Engineering              15
                               Lecture #2: Hello, C++ World!
Input and Output
• Use the input operator (>>) to read a value from
  standard input.
• Standard input is read word by word (words are
  separated by spaces, tabs, or newlines).
• Successive use of >> allows reading multiple words
  into separate variables.
• Examples:
     •cin >> name;
     •cin >> nameA >> nameB;


  January 26, 2012   CS410 – Software Engineering              16
                               Lecture #2: Hello, C++ World!
Input and Output
How can we read an unknown number of input
values?
int main()
{
   string word;
   while (cin >> word)
      cout << “word read is: “ << word << “n”;
   cout << “OK, that’s all.n”;
   return 0;
}
  January 26, 2012   CS410 – Software Engineering              17
                               Lecture #2: Hello, C++ World!
Input and Output
The previous program will work well if we use a file
instread of the console (keyboard) as standard input.
In Linux, we can do this using the “<“ symbol.
Let us say that we have created a text file “input.txt”
(e.g., by using gedit) in the current directory.
It contains the following text:
“This is just a stupid test.”
Let us further say that we stored our program in a file
named “test.C” in the same directory.


  January 26, 2012   CS410 – Software Engineering              18
                               Lecture #2: Hello, C++ World!
Input and Output
We can now compile our program using the g++
compiler into an executable file named “test”:
$ g++ test.C –o test
The generated code can be executed using the
following command:
$ ./test
If we would like to use the content of our file “input.txt”
as standard input for this program, we can type the
following command:
$ ./test < input.txt

  January 26, 2012   CS410 – Software Engineering              19
                               Lecture #2: Hello, C++ World!
Input and Output
We will then see the following output in our terminal:
Word read is: This
Word read is: is
Word read is: just
Word read is: a
Word read is: stupid
Word read is: test.
OK, that’s all.




  January 26, 2012   CS410 – Software Engineering              20
                               Lecture #2: Hello, C++ World!
Input and Output
If we want to redirect the standard output to a file, say
“output.txt”, we can use the “>” symbol:
$ ./test < input.txt > output.txt
We can read the contents of the generated file by
simply typing:
$ less output.txt
We will then see that the file contains the output that
we previously saw printed in the terminal window.
(By the way, press “Q” to get the prompt back.)



  January 26, 2012   CS410 – Software Engineering              21
                               Lecture #2: Hello, C++ World!
Input and Output
If you use keyboard input for your program, it will
never terminate but instead wait for additional input.
Use the getline command to read an entire line from
cin, and put it into a stringstream object that can be
read word by word just like cin.
Using stringstream objects requires the inclusion of
the sstream header file:
#include <sstream>




  January 26, 2012   CS410 – Software Engineering              22
                               Lecture #2: Hello, C++ World!
Input and Output
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main()
{
  string userinput, word;
  getline(cin, userinput);
  stringstream mystream(userinput);
  while (mystream >> word)
     cout << "word read is: " << word << "n";
  cout << "OK, that’s all.n";
  return 0;
}
   January 26, 2012   CS410 – Software Engineering              23
                                Lecture #2: Hello, C++ World!
Input and Output
By the way, you are not limited to strings when using
cin and cout, but you can use other types such as
integers.
However, if your program expects to read an integer
and receives a string, the read operation will fail.

If your program always uses file input and output, it is
better to use fstream objects instead of cin and cout.




  January 26, 2012   CS410 – Software Engineering              24
                               Lecture #2: Hello, C++ World!
File Input and Output
#include <iostream>                                   if (!outfile)
#include <fstream>                                    {
#include <string>                                         cerr << “error: unable to open
using namespace std;
                                                           output file”;
int main()                                                return –2;
{                                                     }
   ofstream outfile(“out_file.txt”);
   ifstream infile(“in_file.txt”);                    string word;
                                                      while (infile >> word)
  if (!infile)                                           outfile << word << “_”;
  {
      cerr << “error: unable to open                  return 0;
        input file”;                              }
      return –1;
  }
     January 26, 2012   CS410 – Software Engineering                               25
                                  Lecture #2: Hello, C++ World!
Preprocessor Directives
Preprocessor directives are specified by placing a
pound sign (#) in the very first column of a line in our
program.
For example, header files are made part of our
program by the preprocessor include directive.
The preprocessor replaces the #include directive with
the contents of the named file.
There are two possible forms:
#include <standard_file.h>
#include “my_file.h”

  January 26, 2012   CS410 – Software Engineering              26
                               Lecture #2: Hello, C++ World!
Preprocessor Directives
If the file name is enclosed in angle brackets (<, >),
the file is presumed to be a standard header file.
Therefore, the preprocessor will search for the file in
a predefined set of locations.
If the file name is enclosed by a pair of quotation
marks, the file is presumed to be a user-supplied
header file.
Therefore, the search for the file begins in the
directory in which the including file is located (project
directory).

  January 26, 2012   CS410 – Software Engineering              27
                               Lecture #2: Hello, C++ World!
Preprocessor Directives
The included file may itself contain an #include
directive (nesting).
This can lead to the same header file being included
multiple times in a single source file.
Conditional directives guard against the multiple
processing of a header file.
Example:
#ifndef SHOUT_H
#define SHOUT_H
   /* shout.h definitions go here */
#endif
  January 26, 2012   CS410 – Software Engineering              28
                               Lecture #2: Hello, C++ World!
Preprocessor Directives

The #ifdef, #ifndef, and #endif directives are most
frequently used to conditionally include program code
depending on whether a preprocessor constant is
defined.

This can be useful, for example, for debugging:




  January 26, 2012   CS410 – Software Engineering              29
                               Lecture #2: Hello, C++ World!
Preprocessor Directives
int main()
{

#ifdef DEBUG
   cout << “Beginning execution of main()n”;
#endif

    string word;
    while (cin >> word)
       cout << “word read is: “ << word << “n”;
    cout << “OK, that’s all.”;
    return 0;
}
    January 26, 2012   CS410 – Software Engineering              30
                                 Lecture #2: Hello, C++ World!
Comments
• Comments are an important aid to human readers
  of our programs.
• Comments need to be updated as the software
  develops.
• Do not obscure your code by mixing it with too
  many comments.
• Place a comment block above the code that it is
  explaining.
• Comments do not increase the size of the
  executable file.

  January 26, 2012   CS410 – Software Engineering              31
                               Lecture #2: Hello, C++ World!
Comments
In C++, there are two different comment delimiters:
• the comment pair (/*, */),
• the double slash (//).
The comment pair is identical to the one used in C:
• The sequence /* indicates the beginning of a
  comment.
• The compiler treats all text between a /* and the
  following */ as a comment.
• A comment pair can be multiple lines long and can
  be placed wherever a tab, space, or newline is
  permitted.
• Comment pairs do not nest.
  January 26, 2012   CS410 – Software Engineering              32
                               Lecture #2: Hello, C++ World!
Comments
The double slash serves to delimit a single-line
comment:
• Everything on the program line to the right of the
  delimiter is treated as a comment and ignored by
  the compiler.

A typical program contains both types of comments.
In general, use comment pairs to explain the
capabilities of a class and the double slash to explain
a single operation.

  January 26, 2012   CS410 – Software Engineering              33
                               Lecture #2: Hello, C++ World!

More Related Content

What's hot

Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...Guillaume Laforge
 
Accelerated Mac OS X Core Dump Analysis training public slides
Accelerated Mac OS X Core Dump Analysis training public slidesAccelerated Mac OS X Core Dump Analysis training public slides
Accelerated Mac OS X Core Dump Analysis training public slidesDmitry Vostokov
 
Lightweight Xtext Editors as SWT Widgets
Lightweight Xtext Editors as SWT WidgetsLightweight Xtext Editors as SWT Widgets
Lightweight Xtext Editors as SWT Widgetsmeysholdt
 
EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4Max Kleiner
 
CLI, the other SAPI
CLI, the other SAPICLI, the other SAPI
CLI, the other SAPICombell NV
 
Ekon 25 Python4Delphi_MX475
Ekon 25 Python4Delphi_MX475Ekon 25 Python4Delphi_MX475
Ekon 25 Python4Delphi_MX475Max Kleiner
 
Introduction to Functional Programming with Scheme
Introduction to Functional Programming with SchemeIntroduction to Functional Programming with Scheme
Introduction to Functional Programming with SchemeDoc Norton
 
Experiments in Sharing Java VM Technology with CRuby
Experiments in Sharing Java VM Technology with CRubyExperiments in Sharing Java VM Technology with CRuby
Experiments in Sharing Java VM Technology with CRubyMatthew Gaudet
 
Metrics ekon 14_2_kleiner
Metrics ekon 14_2_kleinerMetrics ekon 14_2_kleiner
Metrics ekon 14_2_kleinerMax Kleiner
 
API management with Taffy and API Blueprint
API management with Taffy and API BlueprintAPI management with Taffy and API Blueprint
API management with Taffy and API BlueprintKai Koenig
 
2017: Kotlin - now more than ever
2017: Kotlin - now more than ever2017: Kotlin - now more than ever
2017: Kotlin - now more than everKai Koenig
 

What's hot (20)

Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
 
Accelerated Mac OS X Core Dump Analysis training public slides
Accelerated Mac OS X Core Dump Analysis training public slidesAccelerated Mac OS X Core Dump Analysis training public slides
Accelerated Mac OS X Core Dump Analysis training public slides
 
Lightweight Xtext Editors as SWT Widgets
Lightweight Xtext Editors as SWT WidgetsLightweight Xtext Editors as SWT Widgets
Lightweight Xtext Editors as SWT Widgets
 
EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4
 
CLI, the other SAPI
CLI, the other SAPICLI, the other SAPI
CLI, the other SAPI
 
Java Full Throttle
Java Full ThrottleJava Full Throttle
Java Full Throttle
 
Start dart
Start dartStart dart
Start dart
 
Book
BookBook
Book
 
Practical Groovy DSL
Practical Groovy DSLPractical Groovy DSL
Practical Groovy DSL
 
Intro to J Ruby
Intro to J RubyIntro to J Ruby
Intro to J Ruby
 
Ekon 25 Python4Delphi_MX475
Ekon 25 Python4Delphi_MX475Ekon 25 Python4Delphi_MX475
Ekon 25 Python4Delphi_MX475
 
Java sockets
Java socketsJava sockets
Java sockets
 
Introduction to Functional Programming with Scheme
Introduction to Functional Programming with SchemeIntroduction to Functional Programming with Scheme
Introduction to Functional Programming with Scheme
 
Experiments in Sharing Java VM Technology with CRuby
Experiments in Sharing Java VM Technology with CRubyExperiments in Sharing Java VM Technology with CRuby
Experiments in Sharing Java VM Technology with CRuby
 
Metrics ekon 14_2_kleiner
Metrics ekon 14_2_kleinerMetrics ekon 14_2_kleiner
Metrics ekon 14_2_kleiner
 
Preon (J-Fall 2008)
Preon (J-Fall 2008)Preon (J-Fall 2008)
Preon (J-Fall 2008)
 
OOPSLA Talk on Preon
OOPSLA Talk on PreonOOPSLA Talk on Preon
OOPSLA Talk on Preon
 
DSLs in JavaScript
DSLs in JavaScriptDSLs in JavaScript
DSLs in JavaScript
 
API management with Taffy and API Blueprint
API management with Taffy and API BlueprintAPI management with Taffy and API Blueprint
API management with Taffy and API Blueprint
 
2017: Kotlin - now more than ever
2017: Kotlin - now more than ever2017: Kotlin - now more than ever
2017: Kotlin - now more than ever
 

Viewers also liked

Viewers also liked (20)

Bitwise operators
Bitwise operatorsBitwise operators
Bitwise operators
 
Array and string
Array and stringArray and string
Array and string
 
Lecture 11 bitwise_operator
Lecture 11 bitwise_operatorLecture 11 bitwise_operator
Lecture 11 bitwise_operator
 
principle of oop’s in cpp
principle of oop’s in cppprinciple of oop’s in cpp
principle of oop’s in cpp
 
Graphics in C programming
Graphics in C programmingGraphics in C programming
Graphics in C programming
 
Inheritance, friend function, virtual function, polymorphism
Inheritance, friend function, virtual function, polymorphismInheritance, friend function, virtual function, polymorphism
Inheritance, friend function, virtual function, polymorphism
 
Structures
StructuresStructures
Structures
 
Lec 42.43 - virtual.functions
Lec 42.43 - virtual.functionsLec 42.43 - virtual.functions
Lec 42.43 - virtual.functions
 
15 bitwise operators
15 bitwise operators15 bitwise operators
15 bitwise operators
 
C++ Language
C++ LanguageC++ Language
C++ Language
 
Virtual function
Virtual functionVirtual function
Virtual function
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Embedded c programming22 for fdp
Embedded c programming22 for fdpEmbedded c programming22 for fdp
Embedded c programming22 for fdp
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
C pointer
C pointerC pointer
C pointer
 
Function in c
Function in cFunction in c
Function in c
 
operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++
 
Function in C
Function in CFunction in C
Function in C
 
C Pointers
C PointersC Pointers
C Pointers
 
File Handling in C++
File Handling in C++File Handling in C++
File Handling in C++
 

Similar to Parm

Introduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfIntroduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfAnassElHousni
 
Abhishek lingineni
Abhishek lingineniAbhishek lingineni
Abhishek lingineniabhishekl404
 
CPlusPus
CPlusPusCPlusPus
CPlusPusrasen58
 
C++_programs.ppt
C++_programs.pptC++_programs.ppt
C++_programs.pptInfotech27
 
C++_programs.ppt
C++_programs.pptC++_programs.ppt
C++_programs.pptTeacherOnat
 
C++_programs.ppt
C++_programs.pptC++_programs.ppt
C++_programs.pptJayarAlejo
 
C++_programs.ppt
C++_programs.pptC++_programs.ppt
C++_programs.pptJayarAlejo
 
C++_programs.ppt
C++_programs.pptC++_programs.ppt
C++_programs.pptEPORI
 
C++ programming: Basic introduction to C++.ppt
C++ programming: Basic introduction to C++.pptC++ programming: Basic introduction to C++.ppt
C++ programming: Basic introduction to C++.pptyp02
 
Introduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to itIntroduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to itPushkarNiroula1
 
C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...bhargavi804095
 

Similar to Parm (20)

Fp201 unit2 1
Fp201 unit2 1Fp201 unit2 1
Fp201 unit2 1
 
Introduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfIntroduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdf
 
Lab 1.pptx
Lab 1.pptxLab 1.pptx
Lab 1.pptx
 
Abhishek lingineni
Abhishek lingineniAbhishek lingineni
Abhishek lingineni
 
CPlusPus
CPlusPusCPlusPus
CPlusPus
 
Software Engineering
Software EngineeringSoftware Engineering
Software Engineering
 
C++_programs.ppt
C++_programs.pptC++_programs.ppt
C++_programs.ppt
 
C++_programs.ppt
C++_programs.pptC++_programs.ppt
C++_programs.ppt
 
C++_programs.ppt
C++_programs.pptC++_programs.ppt
C++_programs.ppt
 
C++_programs.ppt
C++_programs.pptC++_programs.ppt
C++_programs.ppt
 
C++_programs.ppt
C++_programs.pptC++_programs.ppt
C++_programs.ppt
 
C++_programs.ppt
C++_programs.pptC++_programs.ppt
C++_programs.ppt
 
C++ programming: Basic introduction to C++.ppt
C++ programming: Basic introduction to C++.pptC++ programming: Basic introduction to C++.ppt
C++ programming: Basic introduction to C++.ppt
 
C++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWAREC++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWARE
 
1 c introduction
1 c introduction1 c introduction
1 c introduction
 
C++Basics2022.pptx
C++Basics2022.pptxC++Basics2022.pptx
C++Basics2022.pptx
 
Prog1-L1.pdf
Prog1-L1.pdfProg1-L1.pdf
Prog1-L1.pdf
 
Introduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to itIntroduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to it
 
C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...
 
C++ basics
C++ basicsC++ basics
C++ basics
 

More from parmsidhu

open source technology
open source technologyopen source technology
open source technologyparmsidhu
 
C++ Introduction
C++ IntroductionC++ Introduction
C++ Introductionparmsidhu
 
Mobile Networking
Mobile NetworkingMobile Networking
Mobile Networkingparmsidhu
 
Mobile Networking
Mobile NetworkingMobile Networking
Mobile Networkingparmsidhu
 
Biometric Sensors
Biometric SensorsBiometric Sensors
Biometric Sensorsparmsidhu
 

More from parmsidhu (6)

open source technology
open source technologyopen source technology
open source technology
 
C++ Introduction
C++ IntroductionC++ Introduction
C++ Introduction
 
Mobile Networking
Mobile NetworkingMobile Networking
Mobile Networking
 
Mobile Networking
Mobile NetworkingMobile Networking
Mobile Networking
 
Biometric Sensors
Biometric SensorsBiometric Sensors
Biometric Sensors
 
Parm
ParmParm
Parm
 

Recently uploaded

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 

Recently uploaded (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 

Parm

  • 1. C++ Overview • History and major features of C++ • Input and output • Preprocessor directives • Comments January 26, 2012 CS410 – Software Engineering 1 Lecture #2: Hello, C++ World!
  • 2. History of C++ 1972: C language developed at Bell Labs •Dennis Ritchie wrote C for Unix OS •Needed C for work with Unix late 70s: C becomes popular for OS development by many vendors •Many variants of the language developed •ANSI standard C in 1987-89
  • 3. History of C++ (continued) early 80s: Bjarne Stroustrup adds OO features to C creating C++ 90s: continued evolution of the language and its applications •preferred language for OS and low level programming •popular language for application development •low level control and high level power
  • 4. History of C++ • 1980: “C-with-classes” developed by Bjarne Stroustrup • 1983: C-with-classes redesigned and called C++ • 1985: C++ compilers made available • 1989: ANSI/ISO C++ standardization starts • 1998: ANSI/ISO C++ standard approved January 26, 2012 CS410 – Software Engineering 4 Lecture #2: Hello, C++ World!
  • 5. Conceptually what is C++ Alternatives: •is it C, with lots more options and features? •is it an OO programming language with C as its core? •is it a development environment? On most systems it is a development environment, language, and library, used for both procedural and object oriented programming, that can be customized and extended as desired
  • 6. Versions of C++ ANSI C++ Microsoft C++ (MS Visual C++ 6.0) Other vendors: Borland, Symantec, Turbo, … Many older versions (almost annual) including different version of C too Many vendor specific versions Many platform specific versions For this class: Unix / Linux based versions •g++
  • 7. Characteristics of C++ as a Computer Language Procedural Object Oriented Extensible ...
  • 8. Other OO Languages Smalltalk •pure OO language developed at PARC Java •built on C/C++ •objects and data types Eifel and others
  • 9. What you can do with C++ Apps (standalone, Web apps, components) Active desktop (Dynamic HTML, incl Web) Create graphical apps Data access (e-mail, files, ODBC) Integrate components w/ other languages
  • 10. Major Features of C++ • Almost upward compatible with C •Not all valid C programs are valid C++ programs. • Why? • Because of reserved words in C++ such as ‘class’ • Extends C with object-oriented features • Compile-time checking: strongly typed • Classes with multiple inheritance • No garbage collection, but semi-automatic storage reclamation January 26, 2012 CS410 – Software Engineering 10 Lecture #2: Hello, C++ World!
  • 11. Disadvantages of C++ Tends to be one of the less portable languages Complicated? •40 operators, intricate precedence, pointers, etc. •can control everything •many exceptions and special cases •tremendous libraries both standard, vendor specific, and available for purchase, but all are intricate Aspects above can result in high maintenance
  • 12. Advantages of C++ Available on most machines Can get good performance Can get small size Can manage memory effectively Can control everything Good supply of programmers Suitable for almost any type of program (from systems programs to applications)
  • 13. Sample C++ Program #include <iostream> if (enteredPasswd == deptChairPasswd) #include <string> { using namespace std; cout << "Thank you!" << endl; passwdOK = true; int main() } { else string deptChairName, deptChairPasswd, { enteredPasswd; cout << "Hey! Are you really " << bool passwdOK; deptChairName << "?n"; int attempts = 0; cout << "Try again!n"; passwdOK = false; deptChairName = GetDeptChairName(); } deptChairPasswd = GetDeptChairPasswd(); } while (!passwdOK && attempts < 3); cout << "How are you today, " << if (passwdOK) deptChairName << "?n"; SetNewParameters(); do else { { cout << "Please enter your password: "; Shout(“Warning! Illegal access!”); cin >> enteredPasswd; CallCampusPolice(); attempts++; } return 0; } January 26, 2012 CS410 – Software Engineering 13 Lecture #2: Hello, C++ World!
  • 14. Input and Output • Some standard functions for input and output are provided by the iostream library. • The iostream library is part of the standard library. • Input from the terminal (standard input) is tied to the iostream object cin. • Output to the terminal (standard output) is tied to the iostream object cout. • Error and warning messages can be sent to the user via the iostream object cerr (standard error). January 26, 2012 CS410 – Software Engineering 14 Lecture #2: Hello, C++ World!
  • 15. Input and Output • Use the output operator (<<) to direct a value to standard output. • Successive use of << allows concatenation. • Examples: •cout << “Hi there!n”; •cout << “I have “ << 3 + 5 << “ classes today.”; •cout << “goodbye!” << endl; (new line & flush) January 26, 2012 CS410 – Software Engineering 15 Lecture #2: Hello, C++ World!
  • 16. Input and Output • Use the input operator (>>) to read a value from standard input. • Standard input is read word by word (words are separated by spaces, tabs, or newlines). • Successive use of >> allows reading multiple words into separate variables. • Examples: •cin >> name; •cin >> nameA >> nameB; January 26, 2012 CS410 – Software Engineering 16 Lecture #2: Hello, C++ World!
  • 17. Input and Output How can we read an unknown number of input values? int main() { string word; while (cin >> word) cout << “word read is: “ << word << “n”; cout << “OK, that’s all.n”; return 0; } January 26, 2012 CS410 – Software Engineering 17 Lecture #2: Hello, C++ World!
  • 18. Input and Output The previous program will work well if we use a file instread of the console (keyboard) as standard input. In Linux, we can do this using the “<“ symbol. Let us say that we have created a text file “input.txt” (e.g., by using gedit) in the current directory. It contains the following text: “This is just a stupid test.” Let us further say that we stored our program in a file named “test.C” in the same directory. January 26, 2012 CS410 – Software Engineering 18 Lecture #2: Hello, C++ World!
  • 19. Input and Output We can now compile our program using the g++ compiler into an executable file named “test”: $ g++ test.C –o test The generated code can be executed using the following command: $ ./test If we would like to use the content of our file “input.txt” as standard input for this program, we can type the following command: $ ./test < input.txt January 26, 2012 CS410 – Software Engineering 19 Lecture #2: Hello, C++ World!
  • 20. Input and Output We will then see the following output in our terminal: Word read is: This Word read is: is Word read is: just Word read is: a Word read is: stupid Word read is: test. OK, that’s all. January 26, 2012 CS410 – Software Engineering 20 Lecture #2: Hello, C++ World!
  • 21. Input and Output If we want to redirect the standard output to a file, say “output.txt”, we can use the “>” symbol: $ ./test < input.txt > output.txt We can read the contents of the generated file by simply typing: $ less output.txt We will then see that the file contains the output that we previously saw printed in the terminal window. (By the way, press “Q” to get the prompt back.) January 26, 2012 CS410 – Software Engineering 21 Lecture #2: Hello, C++ World!
  • 22. Input and Output If you use keyboard input for your program, it will never terminate but instead wait for additional input. Use the getline command to read an entire line from cin, and put it into a stringstream object that can be read word by word just like cin. Using stringstream objects requires the inclusion of the sstream header file: #include <sstream> January 26, 2012 CS410 – Software Engineering 22 Lecture #2: Hello, C++ World!
  • 23. Input and Output #include <iostream> #include <sstream> #include <string> using namespace std; int main() { string userinput, word; getline(cin, userinput); stringstream mystream(userinput); while (mystream >> word) cout << "word read is: " << word << "n"; cout << "OK, that’s all.n"; return 0; } January 26, 2012 CS410 – Software Engineering 23 Lecture #2: Hello, C++ World!
  • 24. Input and Output By the way, you are not limited to strings when using cin and cout, but you can use other types such as integers. However, if your program expects to read an integer and receives a string, the read operation will fail. If your program always uses file input and output, it is better to use fstream objects instead of cin and cout. January 26, 2012 CS410 – Software Engineering 24 Lecture #2: Hello, C++ World!
  • 25. File Input and Output #include <iostream> if (!outfile) #include <fstream> { #include <string> cerr << “error: unable to open using namespace std; output file”; int main() return –2; { } ofstream outfile(“out_file.txt”); ifstream infile(“in_file.txt”); string word; while (infile >> word) if (!infile) outfile << word << “_”; { cerr << “error: unable to open return 0; input file”; } return –1; } January 26, 2012 CS410 – Software Engineering 25 Lecture #2: Hello, C++ World!
  • 26. Preprocessor Directives Preprocessor directives are specified by placing a pound sign (#) in the very first column of a line in our program. For example, header files are made part of our program by the preprocessor include directive. The preprocessor replaces the #include directive with the contents of the named file. There are two possible forms: #include <standard_file.h> #include “my_file.h” January 26, 2012 CS410 – Software Engineering 26 Lecture #2: Hello, C++ World!
  • 27. Preprocessor Directives If the file name is enclosed in angle brackets (<, >), the file is presumed to be a standard header file. Therefore, the preprocessor will search for the file in a predefined set of locations. If the file name is enclosed by a pair of quotation marks, the file is presumed to be a user-supplied header file. Therefore, the search for the file begins in the directory in which the including file is located (project directory). January 26, 2012 CS410 – Software Engineering 27 Lecture #2: Hello, C++ World!
  • 28. Preprocessor Directives The included file may itself contain an #include directive (nesting). This can lead to the same header file being included multiple times in a single source file. Conditional directives guard against the multiple processing of a header file. Example: #ifndef SHOUT_H #define SHOUT_H /* shout.h definitions go here */ #endif January 26, 2012 CS410 – Software Engineering 28 Lecture #2: Hello, C++ World!
  • 29. Preprocessor Directives The #ifdef, #ifndef, and #endif directives are most frequently used to conditionally include program code depending on whether a preprocessor constant is defined. This can be useful, for example, for debugging: January 26, 2012 CS410 – Software Engineering 29 Lecture #2: Hello, C++ World!
  • 30. Preprocessor Directives int main() { #ifdef DEBUG cout << “Beginning execution of main()n”; #endif string word; while (cin >> word) cout << “word read is: “ << word << “n”; cout << “OK, that’s all.”; return 0; } January 26, 2012 CS410 – Software Engineering 30 Lecture #2: Hello, C++ World!
  • 31. Comments • Comments are an important aid to human readers of our programs. • Comments need to be updated as the software develops. • Do not obscure your code by mixing it with too many comments. • Place a comment block above the code that it is explaining. • Comments do not increase the size of the executable file. January 26, 2012 CS410 – Software Engineering 31 Lecture #2: Hello, C++ World!
  • 32. Comments In C++, there are two different comment delimiters: • the comment pair (/*, */), • the double slash (//). The comment pair is identical to the one used in C: • The sequence /* indicates the beginning of a comment. • The compiler treats all text between a /* and the following */ as a comment. • A comment pair can be multiple lines long and can be placed wherever a tab, space, or newline is permitted. • Comment pairs do not nest. January 26, 2012 CS410 – Software Engineering 32 Lecture #2: Hello, C++ World!
  • 33. Comments The double slash serves to delimit a single-line comment: • Everything on the program line to the right of the delimiter is treated as a comment and ignored by the compiler. A typical program contains both types of comments. In general, use comment pairs to explain the capabilities of a class and the double slash to explain a single operation. January 26, 2012 CS410 – Software Engineering 33 Lecture #2: Hello, C++ World!