{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture 4 - Working with Batches of Data

# Lecture 4 - Working with Batches of Data - Working with...

This preview shows pages 1–10. Sign up to view the full content.

Working with Batches of Data Lecture 4 Hartmut Kaiser http://www.cct.lsu.edu/˜hkaiser/fall_2011/csc1254.html

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Abstract So far we looked at simple ‘read a string – print a string’ problems. Now we will look at more complex problems involving multiple pieces of similar data. 9/1/2011, Lecture 4 CSC 1254, Fall 2011, Working with Batches of Data 2
Computing Student Grades Calculate the overall grade of a student (20% midterm, 40% final exam, 40% homework) ▫ Read values interactively ▫ Arbitrary number of homework grades 9/1/2011, Lecture 4 CSC 1254, Fall 2011, Working with Batches of Data 3

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Computing Student Grades // #include directives // using directives int main() { // ask for and read the student's name // ask and read the midterm and final grades // ask for the homework grades // write the result return 0; } 9/1/2011, Lecture 4 CSC 1254, Fall 2011, Working with Batches of Data 4
#include and using directives // #include directives #include <iomanip> // std::setprecision #include <ios> // std::streamsize #include <iostream> #include <string> // using directives using std::cin; using std::setprecision; using std::cout; using std::string; using std::endl; using std::streamsize; int main() { // ask for and read the student's name cout << "Please enter your first name: " ; string name; cin >> name; cout << "Hello, " << name << "!" << endl; // . .. return 0; } 9/1/2011, Lecture 4 CSC 1254, Fall 2011, Working with Batches of Data 5

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Computing Student Grades Calculate and output overall grade //. .. // write the result streamsize prec = cout.precision(); cout << name << ", your final grade is: " << setprecision(3) << 0.2 * midterm + 0.4 * final + 0.4 * sum / count << setprecision(prec) << endl; return 0; } 9/1/2011, Lecture 4 CSC 1254, Fall 2011, Working with Batches of Data 7

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Testing for end of Input We have seen: while (cin >> x) { /*…*/ } Generally istreams can be used as conditions: if (cin >> x) { /*…*/ } Which is equivalent to: cin >> x ; if (cin) { /*…*/ } Detects: ▫ Operation reached end of input ▫ Input characters are not compatible with expected type ▫ System has detected hardware failure 9/1/2011, Lecture 4 CSC 1254, Fall 2011, Working with Batches of Data 8
Calculating the Median Value So far we throw away the values right after

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 25

Lecture 4 - Working with Batches of Data - Working with...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online