Lecture 2OutlineSubmission SystemProject SubmissionSubmission ResultsSubmission HistorySubmission Email ResultsFunction Analysis 1Function Analysis 2Value ParametersReference Parameters 1Reference Parameters 2In-class ExerciseFormatting Doubles 1Formatting Doubles 2Formatting Tables 1Formatting Tables 2Homework 2Monday, August 30 CS 215 Fundamentals of Programming II - Lecture 3 1Lecture 3Log into LinuxDoes everyone have a completed cipher.cpp file for Homework 1?File must have a comment at the top of file:// Class: CS 215// Assignment: Homework 1// Programmer: <your name>Monday, August 30 CS 215 Fundamentals of Programming II - Lecture 3 2OutlineSubmission systemFunction analysisFunction parametersOutput formattingHomework 2Monday, August 30 CS 215 Fundamentals of Programming II - Lecture 3 3Submission SystemThe automated submission system is at http://submission.evansville.eduACENET username, WebAdvisor student ID passwordMonday, August 30 CS 215 Fundamentals of Programming II - Lecture 3 4Project SubmissionThe file to be submitted must be on the local machine.Monday, August 30 CS 215 Fundamentals of Programming II - Lecture 3 5Submission ResultsIgnore the score! Sometimes it is 0, when late.Submission resultsMonday, August 30 CS 215 Fundamentals of Programming II - Lecture 3 6Submission HistoryMost recent submission is graded, unless otherwise requestedThis includes following commenting and coding guidelinesMonday, August 30 CS 215 Fundamentals of Programming II - Lecture 3 7Submission Email ResultsSubmission system also emails grading script output.Compiles program and makes test runs.Compares generated results with expected results.Uses UNIX diff command on filesUses internal streams and stringsExamples from Homework 1 athttp://csserver.evansville.edu/~hwang/f10-courses/cs215/hwk1.suberrors.htmlMonday, August 30 CS 215 Fundamentals of Programming II - Lecture 3 8Function AnalysisConsider a (mathematical) function as a black box that receives data and returns an unnamed result.In C, received data is implemented using a value parameter. This also is done in C++.f(x, y, z, ...)xyz...Monday, August 30 CS 215 Fundamentals of Programming II - Lecture 3 9Function AnalysisIn C++, data also may be passed back through a parameter (with or without receiving data).Passed back data is implemented using a reference parameter.f(x, y, z, ...)xyz...Monday, August 30 CS 215 Fundamentals of Programming II - Lecture 3 10Value ParametersValue parameter is a copy of the corresponding actual argument.Changes to a value parameter are not reflected in the corresponding actual argument.Corresponding argument may be any expression.3 3 7int x = 3, y;y = f(x);cout << x << y;xint f (int r) { r = 7; return 0;}rMonday, August 30 CS 215 Fundamentals of Programming II - Lecture 3 11Reference ParametersReference parameter is another name (i.e., alias) for the corresponding actual argument.Changes to a reference parameter are reflected in the corresponding actual argument.Corresponding argument must be a variable.(In C, this is done with explicit pointers.)3 7int x = 3, y;y = f(x);cout << x << y;xint f (int &r) { r = 7; return 0;}rMonday, August 30 CS 215 Fundamentals of Programming II - Lecture 3 12Reference ParametersSyntax for declaring a reference parameter is:<type> & <parameter name>Parameter is dereferenced automatically in the function, so the name is used directly.Example:void GetInput (int & anInt, double & aDouble) { cout << "Enter an integer and a double: "; cin >> anInt >> aDouble;}Monday, August 30 CS 215 Fundamentals of Programming II - Lecture 3 13In-class ExerciseComplete the in-class exercise sheetCopy file inclass3.cpp, put name in commentsWrite ComputeSalesTaxAndTotal functionCompile and test programOutput formatting will be fixed laterMonday, August 30 CS 215 Fundamentals of Programming II - Lecture 3 14Formatting DoublesDefault format in C++ for doubles is like %g specifier for printf( )To change formatting, two stream member functions:setf ( ) - set formatting flags; most common are ios::fixed, ios::showpoint, ios::scientificprecision ( ) - set number of displayed digitsMonday, August 30 CS 215 Fundamentals of Programming II - Lecture 3 15Formatting DoublesExample: always display point in fixed notation with 2 digits after on screencout.setf(ios::fixed|ios::showpoint);cout.precision(2); // # digits after .Finish the in-class exercise to format the output this way.Monday, August 30 CS 215 Fundamentals of Programming II - Lecture 3 16Formatting TablesTo format data into tables, want to output data into a fixed-width field.In C++, done using I/O manipulators defined in <iomanip>. Manipulators are "output" to a stream using insertion operator (<<).setw(n) – output the next item in a field of size nleft, right – change justification within fields (default is right). This is in force until the next justification manipulator.Monday, August 30 CS 215 Fundamentals of Programming II - Lecture 3 17Formatting TablesExample:cout << left;cout << setw(4) << "n" << " " << setw(6) << "2^n" << endl;cout << setw(4) << "----" << " " << setw(6) << "------" << endl;cout << right;for (int i = 0; i < 16; i=i+4) cout << setw(4) << i << " " << setw(6) << pow(2,i) << endl;Output:n 2^n---- ------ 0 1 4 16 8 256 12 4096Monday, August 30 CS 215 Fundamentals of Programming II - Lecture 3 18Homework 2Assignment is posted to the course webpage.Submission system will be set up by Wednesday evening to accept submissions.May submit as many times as needed.Must be submitted electronically by Friday at 4:30pm for full credit. Weekend counts as one day, so submit by Monday at 4:30pm is 10%
View Full Document