1 / 28

Software System Design

Software System Design. Lecture 1 CS240 C++ and Linux. Administrative. Read handouts on coding guidelines Read “Java to C++” handout Read “Unix Tutorial for Beginners” (Intro, Tutorial 1, Tutorial 2 – links on class web page) HW #1 assigned Due Monday, 8/30 at 11:59pm. Documentation.

rtoner
Download Presentation

Software System Design

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Software System Design • Lecture 1 • CS240 • C++ and Linux

  2. Administrative • Read handouts on coding guidelines • Read “Java to C++” handout • Read “Unix Tutorial for Beginners” (Intro, Tutorial 1, Tutorial 2 – links on class web page) • HW #1 assigned • Due Monday, 8/30 at 11:59pm

  3. Documentation • Code standards and additional guidelines (class web page) • Java2C++ guide (supplemental materials – class web page) • Online Resources • UR CS Tools • Unix documentation (online manual pages) • C++ documentation (see class web page for links)

  4. Linux • Linux accounts • Log in using UR netid and password • 10 machines - 6 in 225, 4 in 228 (locked) • ats-jps-g30-l1 aka mathcs01 • ats-jps-g30-l2 aka mathcs02 • ... • ats-jps-g30-l10 aka mathcs10

  5. Linux • Linux is an operating system just like Windows and MacOS • Linux uses a command prompt • Lots of commands typed in window • Kind of like DOS command prompt used for compiling in CS150

  6. Hierarchical File Systems / dev etc home usr console lbarnett blawson share cs240 cpp_examples README

  7. Linux File System • Hierarchical • Special directory names: • Root directory: “/” • Current directory: “.” • Parent directory: “..” (allows you to go up) • User’s home directory: “~” • Some other user’s home: “~lbarnett” • Using given names, only need two operations to navigate entire name space: • cd <name> : move into directory “name” • ls : enumerate all names in current directory

  8. Log into Linux machines

  9. Basic Linux Commands

  10. Linux Documentation:man Pages Note: Also see Unix documentation placed on web page

  11. C++ Intro:Arrays #include <iostream> using namespace std; int main() { int num[10]; //array of integers for(int i = 0; i < 10; i++){ //read each integer in from user cin >> num[i]; } cout << “User entered”; for(int i = 9; i >= 0; i--){ cout << num[i] << “ “; } } Reminder: Arrays do NOT have a length method

  12. C++ Intro:Functions #include <iostream> using namespace std; intfoo(); // declaration int main() { cout << “Foo “<< foo(); //call } intfoo() //definition { return 5; } • Global functions • ex. main • Function declarations required if used before defined

  13. C++ Intro:Functions #include <iostream> using namespace std; intfoo() //definition { return 5; } int main() { cout << “Foo “<<foo(); //call } • Global functions • ex. main • Function declarations required if used before defined

  14. C++ Intro:Function Parameters Pass-by-copy • Pass-by-copy • Copy of variable sent to function • Changes to variable in function not reflected at caller • Also called “pass-by-value” void foo(int x) { x = 5; } int main() { int x = 3; foo(x); cout << “value of x is “<< x; }

  15. C++ Intro:Function Parameters Pass-by-reference • Pass-by-reference • Reference to variable in caller sent to function • Changes to variable in function reflected at caller void foo(int &x) { x = 5; } int main() { int x = 3; foo(x); cout << “value of x is “<< x; }

  16. C++ Intro:C-style strings int main() { char foo[10] = “bob”; //access individual chars foo[2] = ‘t’; // “bot” } • Array of null terminated chars • #include <string.h> to perform functions on these strings • strcpy(dest, src) • copies src into dest • strcat(dest, src) • appends src to dest • More functions in Standard C string library (man string)

  17. C++ Intro:strings • To use, #include <string> • Declarations and initializations: • string s1(“Amsterdam, NY”); • string s2 = “Amsterdam, NY”; • Lots of other ways; see documentation • Can index into like c-style strings • s2[0] will return ‘A’

  18. C++ Intro:string Methods Find more functions as part of C++ Standard Template Library

  19. C++ Intro:strings • strings can be compared with standard relational operations • > , <, == • strings can be concatenated with “+” and “+=“

  20. C++ Intro:Command-line Arguments • You can specify arguments to your executable when you execute it • Parameters to main() must be: • int argc • Number of arguments specified at command line • char *argv[] • Array of C-style strings • argv[0] is always executable name

  21. C++ Intro:Input and Output • Streams • Input / output streams • #include <iostream> • std::cin / std::cout • File input / output streams • #include <fstream> • ifstream/ ofstream • Streams for console and files all work the same

  22. std::cin/std::cout • The >> stream input operator reads whitespace-delimited words / numbers • To read entire line, use getline(cin, var) • The stream output operator << prints either text or variables

  23. C++ Introduction: ifstream

  24. using namespace std; #include <iostream> #include <fstream> #include <string> int main() { ifstream infile; infile.open("phone.txt"); if(infile.is_open() == false){ cerr << "Unable to open file " << endl; exit(1); } while(infile.good()){ string firstName, lastName; int phoneNum; infile >> firstName >> lastName >> phoneNum; if(infile.fail()) break; cout << firstName << "'s number: " << phoneNum << endl; } infile.close(); }

  25. C++ Intro: ofstream

  26. Together • Write a main method that • is passed a single file name via command line arguments, • passes that C-style string to a method • which writes the values from 1 to 10 into the file using a loop.

More Related