DOC PREVIEW
CSUN COMP 106 - Fourth Programming Exercise

This preview shows page 1-2 out of 6 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

College of Engineering and Computer ScienceComputer Science DepartmentComputer Science 106 Computing in Engineering and ScienceSpring 2006 Class number: 11672 Instructor: Larry CarettoFourth Programming ExerciseObjectiveAfter completing this exercise you should be able to write commands that (1) use output formatting and (2) read input from and write output to files.Background for exerciseIn previous exercises you have used various cin and cout commands for input and output, respectively. You have accepted the default format for numbers provided by C++. In this exercise you will learn new ways to space output, ways to format the appearance of numerical output and using files in place of the keyboard for input and in place of the screen for output. All these tasks will extend what you have learned about cin and cout.Overview of exercise and its tasksThis exercise has four tasks. The first and third tasks only require you to copy code from the assignment and execute the code. The second and fourth tasks require you to modify the code inthe first and third tasks, respectively. In the third and fourth tasks you will be using input from andoutput to files. Use the same procedure you followed for exercises two and three to create a single file, called the submission file, to which you will copy all your listings and the screen displays from the program execution. See the notes for the second exercise for details about copying the screen to another file and preparing a single file to submit all your program listings and output. In this exercise you will have input and output files to view in addition to the source and submission files. Follow the instructions on which of these input and output files you should copy to the submission file.Programming tasksTask one: Output formats – Copy the code below into Visual C++ then compile and execute it. Change the name and date in the comments to your name and lab date. Review the output and compare the results to the various statements. You should be able to account for the differences in the format of the numbers and the differences in spacing between the cases run./*Comp 106L Programming exercise fourMyname Goeshere Place date hereTask one: Output formats*/#include <iostream>#include <iomanip>using namespace std;int main(){double x1 = 123.45678, y1 = -98.76543, z1 = 1413.746352;Jacaranda (Engineering) 3333 Mail Code Phone: 818.677.6448E-mail: [email protected] 8348 Fax: 818.677.7062double x2 = 23.45321, y2 = -8.7, z2 = 3.745;double x3 = 1.23e-16, y3 = -5.3245e22, z3 = 938457483e-3;cout << "Example of output from different formats.\n";cout << "\nDefault output:\n";cout << "\nx1 = " << x1 << ", y1 = " << y1 << ", z1 = " << z1;cout << "\nx2 = " << x2 << ", y2 = " << y2 << ", z2 = " << z2;cout << "\nx3 = " << x3 << ", y3 = " << y3 << ", z3 = " << z3;cout << "\n\nDefault output except using setw(w):\n";cout << "\nx1 = " << setw(9) << x1 << ", y1 = " << setw(12) << y1 << ", z1 = " << setw(7) << z1;cout << "\nx2 = " << setw(9) << x2 << ", y2 = " << setw(12) << y2 << ", z2 = " << setw(7) << z2;cout << "\nx3 = " << setw(9) << x3 << ", y3 = " << setw(12) << y3 << ", z3 = " << setw(7) << z3;cout << "\n\nDefault output except using setprecision(7):\n" << setprecision(7);cout << "\nx1 = " << x1 << ", y1 = " << y1 << ", z1 = " << z1;cout << "\nx2 = " << x2 << ", y2 = " << y2 << ", z2 = " << z2;cout << "\nx3 = " << x3 << ", y3 = " << y3 << ", z3 = " << z3;cout << "\n\nOutput using setw(w) with setprecision(7) still in effect:\n";cout << "\nx1 = " << setw(9) << x1 << ", y1 = " << setw(12) << y1 << ", z1 = " << setw(7) << z1;cout << "\nx2 = " << setw(9) << x2 << ", y2 = " << setw(12) << y2 << ", z2 = " << setw(7) << z2;cout << "\nx3 = " << setw(9) << x3 << ", y3 = " << setw(12) << y3 << ", z3 = " << setw(7) << z3;cout << "\n\nSame as previous except \"fixed\" output specified:\n" << fixed;cout << "\nx1 = " << setw(9) << x1 << ", y1 = " << setw(12) << y1 << ", z1 = " << setw(7) << z1;cout << "\nx2 = " << setw(9) << x2 << ", y2 = " << setw(12) << y2 << ", z2 = " << setw(7) << z2;cout << "\nx3 = " << setw(9) << x3 << ", y3 = " << setw(12) << y3 << ", z3 = " << setw(7) << z3;cout << endl << endl; // create blank lines before "Press any key"return EXIT_SUCCESS;}Do not copy the code, but copy the output from this code to the submission file. Write your name,lab day and exercise number at the top of the submission file. You may want to print the code and the results as a study guide.Task two: Write your own formats – Revise the code in task one so that the results are printed outonly one time, using a revised format as shown below.No. x value y value z value 1 123.46 -98.77 1413.75 2 23.45 -8.70 3.75 3 0.00 -0.05 938457.48In the revised format, the data form a table with labels at the top and the data set numbers (1, 2, 3) in a column at the left. The individual variable identifiers, used in the listing above, are not Jacaranda (Engineering) 3333 Mail Code Phone: 818.677.6448E-mail: [email protected] 8348 Fax: 818.677.7062used in this output. Note that the output format below calls for two decimal places on each number that is printed out. In addition, each number occupies ten spaces. Before running the program for this task, change the definition of y3 so that it reads y3 = -5.3245e-2. Copy the code you write for this task and the screen output to the submission file.Task three: Input and output files – In this task you will have to copy and paste two files from these instructions into your Visual C++ environment: a program file and a data file. The program file is shown first followed by the data file. After you copy and paste the code into the program filethat is part of your project, edit the initial comments to enter your name and today’s date.The program reads data from an input data file on x, y, and z coordinates and a corresponding electronic temperature measurement in millivolts. It then uses a correlation equation to convert the electronic temperature measurement to an actual temperature. It also computes the radial coordinate. The input data as well as the computed temperature and radial coordinate are writtento an output data file./* Programmer: PutYour NameHere Date: Comp 106 Programming exercise four, task two Microsoft Visual C++ .Net with Windows XP operating system Example of


View Full Document

CSUN COMP 106 - Fourth Programming Exercise

Download Fourth Programming Exercise
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 Fourth Programming Exercise 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 Fourth Programming Exercise 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?