Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS221 File Output Using Special Formats. What is a File? A file is a collection of information The type of information in the file can differ image, sound,

Similar presentations


Presentation on theme: "CS221 File Output Using Special Formats. What is a File? A file is a collection of information The type of information in the file can differ image, sound,"— Presentation transcript:

1 CS221 File Output Using Special Formats

2 What is a File? A file is a collection of information The type of information in the file can differ image, sound, video, text, web page, etc… Files are created, modified, and read by programs File extensions help the user AND the computer determine what type of information is in the file and what program is most suitable to use that file jpg, mp3, mpeg, txt, html, doc, xls, ppt, …

3 File Formats You can write a C++ program which can read and write files using file streams It is possible for your C++ program to read and write files which have special formats IF the programmer is aware of the format… Thus, if you know the format of an HTML file, you can write a C++ program which will read OR create/write a web page!

4 HTML and CSV These are special file formats which are based on plain text HTML is the format of Web Pages CSV is a format which can be used by MS Excel We will learn how to make our C++ programs create files using these formats

5 MS Excel in Brief Microsoft Excel is a Spreadsheet Program The spreadsheet consists of a grid of rows and columns rows are numbered, columns are lettered When a row and column meet, there is a cell cells are identified by their row and column A1, E5, C13, etc… Cells can contain data (text or numeric) or formulas which act upon that data

6 MS Excel in Brief Useful engineering aspects of Excel store and organize a moderate amount of data make calculations on that data make graphs to analyze data

7 Graphing in Excel Store data in columns with labels at the top Select (click+drag) the data series you want to graph Click the graph wizard button follow simple directions to creat the graph you can make your graph “fancy” axis labels, graph label, key, etc…

8

9

10 CSV Files CSV stands for “comma separated value” CSV is a special file format Microsoft Excel can recognize and open CSV files Your C++ program can use a file output stream to create CSV files

11 CSV Files In a CSV file, Excel will read the text in the following way… each comma encountered in the file will move Excel to the next cell in the current row each new line character (endl) encountered in the file will move Excel to the next row

12 CSV Files Example

13 Using File Output with CSV You can output from your C++ code to a csv file, then open that output file up in Excel and graph, calculate, etc… (as long as the format is correct) Code to produce the preceding example ofstream fileOut; fileOut.open(“test.csv”); fileOut << “Time,Velocity,Acceleration” <<endl; fileOut << 1 << “,” << 2 << “,” << 3 << endl; fileOut << 4 << “,” << 5 << “,” << 6 << endl; fileOut << 7 << “,” << 8 << “,” << 9 << endl; fileOut << “,,” << 10 << endl;

14 Web Browsers in Brief Web Browsers are Special Programs which interpret Web Pages and display the results graphically Explorer, FireFox, etc… Web Browsers give users the ability to access information which is stored in remote places and see it on their computer quickly and efficiently

15 Web Browsers in Brief Useful engineering aspects of Web Browsers make data available to colleagues/the public present data to non-engineers in a familiar format

16 HTML Files HTML stands for “HyperText Markup Language” HTML is a special file format Web Browsers can recognize and open HTML files Your C++ program can use a file output stream to create HTML files

17 HTML Files In an HTML file, the browser will read the text and produce a web page by interpreting “tags” each HTML tag tells the browser to do something different with the data it is reading we will learn a VERY SMALL set of HTML tags for a complete list of HTML tags, see this link http://www.w3schools.com/tags/

18 More About Tags Each HTML tag is enclosed in angle braces Many HTML tags must be accompanied by a closing/ending tag, which looks the same as its opening/beginning tag, but is marked by a slash Think of a tag set as a set of bookends, anything between the opening and closing tag is described by the tag set.

19 Some Important Tags - marks the beginning and end of the HTML file - tells the browser what to display as the page’s title - marks the beginning and end of the web page’s body (where the contents to be displayed are located

20 Some More Tags - tells the browser that this text is a heading (can also have h2 through h6 for smaller sized headings) - tells the browser that this area of text is to be bold, underlined, and/or italic respectively - begin a new paragraph in the text

21 TableTags - tells the browser to begin a table (if border is 1, show the border, if border is 0 don’t show it) - start a new row in the table - start a new data entry (cell) in the table

22 HTML Files Example

23 Using File Output with HTML You can output from your C++ code to an html file, then open that output file up in a standard web browser as long as the format is correct.

24 Using File Output with HTML ofstream fileOut; //declare output file stream fileOut.open(“test.html”); //open file, NOTE extension fileOut ” <<endl; //begin html page //output title tag fileOut Testing Results ” << endl; //output heading fileOut Results of Test Run 1 ” << endl; fileOut ” << endl; //begin page body //first paragraph fileOut These are the test results from “; fileOut Test Run 1. ” << endl; //continued on next slide…

25 Code Continued… //begin a table with visible border fileOut ” << endl; //output first table row (table header) fileOut ” Min” Max” Reading”<<endl; //output subsequent table rows with data in them fileOut ” 0” 20” 15”<<endl; fileOut ” 0” 20” 10”<<endl; fileOut ” << endl; //end the table fileOut ” << endl; //end page body fileOut ” << endl; //end html page


Download ppt "CS221 File Output Using Special Formats. What is a File? A file is a collection of information The type of information in the file can differ image, sound,"

Similar presentations


Ads by Google