SlideShare una empresa de Scribd logo
1 de 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!

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Destacado

open source technology
open source technologyopen source technology
open source technologyparmsidhu
 
Mobile Networking
Mobile NetworkingMobile Networking
Mobile Networkingparmsidhu
 
C++ Introduction
C++ IntroductionC++ Introduction
C++ Introductionparmsidhu
 
Mobile Networking
Mobile NetworkingMobile Networking
Mobile Networkingparmsidhu
 
Biometric Sensors
Biometric SensorsBiometric Sensors
Biometric Sensorsparmsidhu
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerLuminary Labs
 

Destacado (8)

open source technology
open source technologyopen source technology
open source technology
 
Mobile Networking
Mobile NetworkingMobile Networking
Mobile Networking
 
C++ Introduction
C++ IntroductionC++ Introduction
C++ Introduction
 
Parm
ParmParm
Parm
 
Mobile Networking
Mobile NetworkingMobile Networking
Mobile Networking
 
Biometric Sensors
Biometric SensorsBiometric Sensors
Biometric Sensors
 
(2012) Evolution of the Human Biometric Sensor Interaction model
(2012) Evolution of the Human Biometric Sensor Interaction model(2012) Evolution of the Human Biometric Sensor Interaction model
(2012) Evolution of the Human Biometric Sensor Interaction model
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI Explainer
 

Similar a Parm

Similar a 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++ 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++_programs.ppt
C++_programs.pptC++_programs.ppt
C++_programs.ppt
 
C++_programs.ppt
C++_programs.pptC++_programs.ppt
C++_programs.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++ basics
C++ basicsC++ basics
C++ basics
 
Introduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxIntroduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptx
 

Último

Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 

Último (20)

Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 

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!