Unformatted text preview:

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 3Log into LinuxDoes 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 2OutlineSubmission systemFunction analysisFunction parametersOutput formattingHomework 2Monday, August 30 CS 215 Fundamentals of Programming II - Lecture 3 3Submission SystemThe automated submission system is at http://submission.evansville.eduACENET username, WebAdvisor student ID passwordMonday, August 30 CS 215 Fundamentals of Programming II - Lecture 3 4Project SubmissionThe file to be submitted must be on the local machine.Monday, August 30 CS 215 Fundamentals of Programming II - Lecture 3 5Submission ResultsIgnore the score! Sometimes it is 0, when late.Submission resultsMonday, August 30 CS 215 Fundamentals of Programming II - Lecture 3 6Submission HistoryMost recent submission is graded, unless otherwise requestedThis includes following commenting and coding guidelinesMonday, August 30 CS 215 Fundamentals of Programming II - Lecture 3 7Submission Email ResultsSubmission system also emails grading script output.Compiles program and makes test runs.Compares generated results with expected results.Uses UNIX diff command on filesUses internal streams and stringsExamples 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 AnalysisConsider 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 AnalysisIn 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 ParametersValue 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 ParametersReference 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 ParametersSyntax 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 ExerciseComplete the in-class exercise sheetCopy file inclass3.cpp, put name in commentsWrite ComputeSalesTaxAndTotal functionCompile and test programOutput formatting will be fixed laterMonday, August 30 CS 215 Fundamentals of Programming II - Lecture 3 14Formatting DoublesDefault 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::scientificprecision ( ) - set number of displayed digitsMonday, August 30 CS 215 Fundamentals of Programming II - Lecture 3 15Formatting DoublesExample: 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 TablesTo 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 nleft, 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 TablesExample: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 2Assignment 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

UE CS 215 - LECTURE NOTES

Documents in this Course
Lecture 4

Lecture 4

14 pages

Lecture 5

Lecture 5

18 pages

Lecture 6

Lecture 6

17 pages

Lecture 7

Lecture 7

28 pages

Lecture 1

Lecture 1

16 pages

Lecture 5

Lecture 5

15 pages

Lecture 7

Lecture 7

28 pages

Load more
Download LECTURE NOTES
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view LECTURE NOTES and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view LECTURE NOTES 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?