January 30, 2014CS410 – Software Engineering Lecture #2: Hello, C++ World! 1Ubuntu You will develop your course projects in C++ under Ubuntu Linux. If.

Slides:



Advertisements
Similar presentations
Lecture Computer Science I - Martin Hardwick Strings #include using namespace std; int main () { string word; cout
Advertisements

C++ Introduction.
Creating a Virtual Machine Researched and Created by Bryan Bankhead.
Device Drivers.
C++ Language Fundamentals. 2 Contents 1. Introduction to C++ 2. Basic syntax rules 3. Declaring and using variables.
EC-111 Algorithms & Computing Lecture #1 Instructor: Jahan Zeb Department of Computer Engineering (DCE) College of E&ME NUST.
 The easiest way to put Ubuntu onto your stick is to use the USB installer provided at pendrivelinux.com.pendrivelinux.com  You’ll need to download.
COSC 120 Computer Programming
General Computer Science for Engineers CISC 106 Lecture 26 Dr. John Cavazos Computer and Information Sciences 04/24/2009.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 1 Introduction.
Go to & click on Install/Download Menu optionhttp://osddlinux.osdd.net/ Go to & click on Install/Download.
Creating Clusters in a Virtual Environment Purpose: To create a development environment with limited hardware resources that allows the testing of parallel.
Installation Ubuntu for Libraries. Step 1: Download Head on to Pick Ubuntu LTS; just click the big orange.
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
© 2012 The McGraw-Hill Companies, Inc. All rights reserved. 1 Third Edition Chapter 3 Desktop Virtualization McGraw-Hill.
Red Hat Installation. Installing Red Hat Linux is the process of copying operating system files from a CD, DVD, or USB flash drive to hard disk(s) on.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
COMPUTER PROGRAMMING. Introduction to C++ History Merges notions from Smalltalk and notions from C The class concept was borrowed from Simular67 Developed.
Space Science and Engineering Center University of Wisconsin-Madison Virtual Machines: A method for distributing DB processing software Liam Gumley.
Ashita Srivastava ISM High Five Corporations Chain of fast food restaurants Using Windows XP for clients and Windows Server 2008 Needs a robust.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
Intro. to Game Programming Want to program a game?
SOFTWARE.
C++ Programming. Table of Contents History What is C++? Development of C++ Standardized C++ What are the features of C++? What is Object Orientation?
Go to & click on Install/Download Menu optionhttp://osddlinux.osdd.net/ Go to & click on Install/Download.
Tutorial 11 Installing, Updating, and Configuring Software
DIY: Your First VMware Server. Introduction to ESXi, VMWare's free virtualization Operating System.
VMWare Workstation Installation. Starting Vmware Workstation Go to the start menu and start the VMware Workstation program. *Note: The following instructions.
NUMOSS NURUL ‘IZZATI BINTI OTHMAN A
Hands-On Virtual Computing
© 2012 The McGraw-Hill Companies, Inc. All rights reserved. 1 Third Edition Chapter 5 Windows XP Professional McGraw-Hill.
Cap 333 Network Administration. Solution Rules  Your solution must be typed by computer. Otherwise, it will not be accepted.  If the question is a project.
Instructor: Tina Tian. About me Office: RLC 203A Office Hours: Wednesday 1:30 - 4:30 PM or .
Exercise #1: Exploring Open- Source Operating Systems with Virtual Machines J. H. Wang Mar. 9, 2010.
Linux in a Virtual Environment Nagarajan Prabakar School of Computing and Information Sciences Florida International University.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
Multiboot System under Windows XP – Ubuntu – Windows 7 Qiong LIN - 28 April 2012.
Chapter 0 Getting Started. Objectives Understand the basic structure of a C++ program including: – Comments – Preprocessor instructions – Main function.
We will talking about story of JAVA language. By Kristsada Songpartom.
LINUX MINT 13. ADVANTAGES Linux mint is basically the same thing as Ubuntu. It uses the same repo's etc...for example. In the terminal if I type in Sudo.
VMWare Workstation Installation. Starting Vmware Workstation Go to the start menu and start the VMware Workstation program. *Note: The following instructions.
OPERATING SYSTEMS BY LANDON, KYLE, AND ETHAN. WHAT IS THEIR PURPOSE? (1) manage the computer's resources, such as the central processing unit (2) establish.
Introduction to Windows 10 Windsor Senior Computer Users Group October 12, 2015.
Linux Mint 1 Introduction Linux Mint is a computer operating system based on the Linux distribution Ubuntu. Linux Mint is intended to be a modern, elegant.
Exercise #1: Exploring Open- Source Operating Systems with Virtual Machines J. H. Wang Sep. 25, 2015.
 Linux Mint is a computer operating system designed to work on most modern systems, including typical x86 and x64 PC’s. Linux Mint can be thought of.
CS Computer Science I. BCPL was developed in 1967 as a language for writing operating systems and software compilers In 1970, the creators of the.
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
Java & C++ Comparisons How important are classes and objects?? What mechanisms exist for input and output?? Are references and pointers the same thing??
Virtual Machines Module 2. Objectives Define virtual machine Define common terminology Identify advantages and disadvantages Determine what software is.
 Prepared by: Eng. Maryam Adel Abdel-Hady
The Future With Windows XP Microsoft announced that after April 16, 2014 it will not longer support Windows XP. No statement on continued inclusion of.
A Brief Introduction to Linux Cheng-Han Du. History.
Software Engineering Algorithms, Compilers, & Lifecycle.
Installing iHRIS on VMWare
Presented by Dave Mawdsley, DACS Member, Linux SIG Member
Different Operating Systems
Exercise #1: Exploring Open-Source Operating Systems with Virtual Machines J. H. Wang Sep. 20, 2016.
Creating Clusters in a Virtual Environment
CSC227: Operating Systems
CS410 – Software Engineering Lecture #2: Hello, C++ World!
Installation and Configuration
CISC/CMPE320 - Prof. McLeod
Exercise #1: Exploring Open-Source Operating Systems with Virtual Machines J. H. Wang Sep. 19, 2017.
Hands-On Virtualization in the Classroom
Exercise #1: Exploring Open-Source Operating Systems with Virtual Machines J. H. Wang Sep. 21, 2018.
Different Operating Systems
CS410 – Software Engineering Lecture #2: Hello, C++ World!
Presentation transcript:

January 30, 2014CS410 – Software Engineering Lecture #2: Hello, C++ World! 1Ubuntu You will develop your course projects in C++ under Ubuntu Linux. If your home computer or laptop is running under Windows, an easy and painless way of installing Ubuntu is Wubi: installer installer The Wubi installer will put the latest version of Ubuntu onto your computer.

January 30, 2014CS410 – Software Engineering Lecture #2: Hello, C++ World! 2Ubuntu Wubi does not require its own partition on your hard drive but simulates a file system within one large file. As a consequence, file operations are slightly less efficient than in an actual Ubuntu installation, but that difference does not matter for our purposes. When your computer starts, you will see a boot menu that allows you to choose between Windows and Ubuntu. Wubi can easily be uninstalled, in which case the boot menu will no longer show up.

January 30, 2014CS410 – Software Engineering Lecture #2: Hello, C++ World! 3Ubuntu Another possibility is to download a Ubuntu CD image (.iso file): … and then run it as a virtual machine using the VMWare Player: In either case, also download the g++ compiler from your Ubuntu terminal by typing: $ sudo apt-get install g++

January 30, 2014CS410 – Software Engineering Lecture #2: Hello, C++ World! 4 C++ Overview History and major features of C++History and major features of C++ Input and outputInput and output Preprocessor directivesPreprocessor directives CommentsComments

January 30, 2014CS410 – Software Engineering Lecture #2: Hello, C++ World! 5 History of C : C-with-classes developed by Bjarne Stroustrup 1980: C-with-classes developed by Bjarne Stroustrup 1983: C-with-classes redesigned and called C : C-with-classes redesigned and called C : C++ compilers made available 1985: C++ compilers made available 1989: ANSI/ISO C++ standardization starts 1989: ANSI/ISO C++ standardization starts 1998: ANSI/ISO C++ standard approved 1998: ANSI/ISO C++ standard approved

January 30, 2014CS410 – Software Engineering Lecture #2: Hello, C++ World! 6 Major Features of C++ Almost upward compatible with C Almost upward compatible with C Not all valid C programs are valid C++ programs. Not all valid C programs are valid C++ programs. Why? Why? Because of reserved words in C++ such as class Because of reserved words in C++ such as class Extends C with object-oriented features Extends C with object-oriented features Compile-time checking: strongly typed Compile-time checking: strongly typed Classes with multiple inheritance Classes with multiple inheritance No garbage collection, but semi-automatic storage reclamation No garbage collection, but semi-automatic storage reclamation

January 30, 2014CS410 – Software Engineering Lecture #2: Hello, C++ World! 7 Sample C++ Program #include #include using namespace std; int main() { string deptChairName, deptChairPasswd, enteredPasswd; string deptChairName, deptChairPasswd, enteredPasswd; bool passwdOK; bool passwdOK; int attempts = 0; int attempts = 0; deptChairName = GetDeptChairName(); deptChairName = GetDeptChairName(); deptChairPasswd = GetDeptChairPasswd(); deptChairPasswd = GetDeptChairPasswd(); cout << "How are you today, " << deptChairName << "?\n"; cout << "How are you today, " << deptChairName << "?\n"; do do { cout << "Please enter your password: "; cout << "Please enter your password: "; cin >> enteredPasswd; cin >> enteredPasswd; attempts++; attempts++; if (enteredPasswd == deptChairPasswd) if (enteredPasswd == deptChairPasswd) { cout << "Thank you!" << endl; cout << "Thank you!" << endl; passwdOK = true; passwdOK = true; } else else { cout << "Hey! Are you really " << deptChairName << "?\n"; cout << "Hey! Are you really " << deptChairName << "?\n"; cout << "Try again!\n"; cout << "Try again!\n"; passwdOK = false; passwdOK = false; } } while (!passwdOK && attempts < 3); while (!passwdOK && attempts < 3); if (passwdOK) if (passwdOK) SetNewParameters(); SetNewParameters(); else else { Shout(Warning! Illegal access!); Shout(Warning! Illegal access!); CallCampusPolice(); CallCampusPolice(); } return 0; return 0;}

January 30, 2014CS410 – Software Engineering Lecture #2: Hello, C++ World! 8 Input and Output Some standard functions for input and output are provided by the iostream library.Some standard functions for input and output are provided by the iostream library. The iostream library is part of the standard library.The iostream library is part of the standard library. Input from the terminal (standard input) is tied to the iostream object cin.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.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).Error and warning messages can be sent to the user via the iostream object cerr (standard error).

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

January 30, 2014CS410 – Software Engineering Lecture #2: Hello, C++ World! 10 Input and Output Use the input operator (>>) to read a value from standard input.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).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.Successive use of >> allows reading multiple words into separate variables. Examples:Examples: cin >> name;cin >> name; cin >> nameA >> nameB;cin >> nameA >> nameB;

January 30, 2014CS410 – Software Engineering Lecture #2: Hello, C++ World! 11 Input and Output How can we read an unknown number of input values? int main() { string word; string word; while (cin >> word) cout > word) cout << word read is: << word << \n; cout << OK, thats all.\n; cout << OK, thats all.\n; return 0; } return 0; }

January 30, 2014CS410 – Software Engineering Lecture #2: Hello, C++ World! 12 Input and Output The previous program will work well if we use a file instead 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 30, 2014CS410 – Software Engineering Lecture #2: Hello, C++ World! 13 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 30, 2014CS410 – Software Engineering Lecture #2: Hello, C++ World! 14 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, thats all.

January 30, 2014CS410 – Software Engineering Lecture #2: Hello, C++ World! 15 Input and Output If we want to redirect the standard output to a file, say output.txt, we can use the > symbol: $./test 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 30, 2014CS410 – Software Engineering Lecture #2: Hello, C++ World! 16 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 #include

January 30, 2014CS410 – Software Engineering Lecture #2: Hello, C++ World! 17 Input and Output #include #include #include using namespace std; int main() { string userinput, word; getline(cin, userinput); stringstream mystream(userinput); stringstream mystream(userinput); while (mystream >> word) while (mystream >> word) cout << "word read is: " << word << "\n"; cout << "word read is: " << word << "\n"; cout << "OK, thats all.\n"; cout << "OK, thats all.\n"; return 0; return 0;}

January 30, 2014CS410 – Software Engineering Lecture #2: Hello, C++ World! 18 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 30, 2014CS410 – Software Engineering Lecture #2: Hello, C++ World! 19 File Input and Output #include #include using namespace std; int main() { ofstream outfile(out_file.txt); ofstream outfile(out_file.txt); ifstream infile(in_file.txt); ifstream infile(in_file.txt); if (!infile) if (!infile) { cerr << error: unable to open input file; cerr << error: unable to open input file; return –1; return –1; } if (!outfile) if (!outfile) { cerr << error: unable to open output file; cerr << error: unable to open output file; return –2; return –2; } string word; string word; while (infile >> word) while (infile >> word) outfile << word << _; outfile << word << _; return 0; return 0;}

January 30, 2014CS410 – Software Engineering Lecture #2: Hello, C++ World! 20 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 #include #include my_file.h

January 30, 2014CS410 – Software Engineering Lecture #2: Hello, C++ World! 21 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 30, 2014CS410 – Software Engineering Lecture #2: Hello, C++ World! 22 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 */ /* shout.h definitions go here */#endif

January 30, 2014CS410 – Software Engineering Lecture #2: Hello, C++ World! 23 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 30, 2014CS410 – Software Engineering Lecture #2: Hello, C++ World! 24 Preprocessor Directives int main() { #ifdef DEBUG cout << Beginning execution of main()\n; cout << Beginning execution of main()\n;#endif string word; string word; while (cin >> word) cout > word) cout << word read is: << word << \n; cout << OK, thats all.; cout << OK, thats all.; return 0; } return 0; }

January 30, 2014CS410 – Software Engineering Lecture #2: Hello, C++ World! 25Comments Comments are an important aid to human readers of our programs.Comments are an important aid to human readers of our programs. Comments need to be updated as the software develops.Comments need to be updated as the software develops. Do not obscure your code by mixing it with too many comments.Do not obscure your code by mixing it with too many comments. Place a comment block above the code that it is explaining.Place a comment block above the code that it is explaining. Comments do not increase the size of the executable file.Comments do not increase the size of the executable file.

January 30, 2014CS410 – Software Engineering Lecture #2: Hello, C++ World! 26Comments In C++, there are two different comment delimiters: the comment pair (/*, */),the comment pair (/*, */), the double slash (//).the double slash (//). The comment pair is identical to the one used in C: The sequence /* indicates the beginning of a comment.The sequence /* indicates the beginning of a comment. The compiler treats all text between a /* and the following */ as 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.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.Comment pairs do not nest.

January 30, 2014CS410 – Software Engineering Lecture #2: Hello, C++ World! 27Comments 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. 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.