Lab 2 - CMPS 1043, Computer Science I Introduction to File Input/Output (I/O) Projects and Solutions (C++)



Similar documents
Appendix K Introduction to Microsoft Visual C++ 6.0

Appendix M: Introduction to Microsoft Visual C Express Edition

Creating a Simple Visual C++ Program

Introduction to the use of the environment of Microsoft Visual Studio 2008

Visual Studio 2008 Express Editions

Visual C Tutorial

MS Visual C++ Introduction. Quick Introduction. A1 Visual C++

Microsoft Visual Studio 2010 Instructions For C Programs

Working with SQL Server Integration Services

How to Mail Merge PDF Documents

Lab: Data Backup and Recovery in Windows XP

Lab - Data Backup and Recovery in Windows XP

Create Signature for the Scott County Family Y

Importing Contacts to Outlook

Microsoft Word Mail Merge

Microsoft Word 2013: Mail Merge

What is a Mail Merge?

DEPLOYING A VISUAL BASIC.NET APPLICATION

Junk Settings. Options

Notepad++ The COMPSCI 101 Text Editor for Windows. What is a text editor? Install Python 3

5.4.8 Optional Lab: Managing System Files with Built-in Utilities in Windows 7

Learn how to create web enabled (browser) forms in InfoPath 2013 and publish them in SharePoint InfoPath 2013 Web Enabled (Browser) forms

Organizing and Managing

Legal Notes. Regarding Trademarks KYOCERA Document Solutions Inc.

Maximizing the Use of Slide Masters to Make Global Changes in PowerPoint

ECDL. European Computer Driving Licence. Database Software BCS ITQ Level 1. Syllabus Version 1.0

Optional Lab: Data Backup and Recovery in Windows 7

ProjectWise Explorer V8i User Manual for Subconsultants & Team Members

NSCC SUMMER LEARNING SESSIONS MICROSOFT OFFICE SESSION

Composite.Community.Newsletter - User Guide

Ubuntu. Ubuntu. C++ Overview. Ubuntu. History of C++ Major Features of C++

Tool Tip. SyAM Management Utilities and Non-Admin Domain Users

Basics of Microsoft Outlook/ . Microsoft Outlook

Check out our website!

Deitel Dive-Into Series: Dive Into Microsoft Visual C++ 6

1. Set Daylight Savings Time Create Migrator Account Assign Migrator Account to Administrator group... 4

Creating Basic HTML Forms in Microsoft FrontPage

Instructions for Configuring a SAS Metadata Server for Use with JMP Clinical

Using and the Internet

Lab - Data Backup and Recovery in Windows 7

To successfully initialize Microsoft Outlook (Outlook) the first time, settings need to be verified.

MS WORD 2007 (PC) Macros and Track Changes Please note the latest Macintosh version of MS Word does not have Macros.

Managing Contacts in Outlook

MICROSOFT OUTLOOK 2011 READ, SEARCH AND PRINT S

How To Install And Configure Windows Server 2003 On A Student Computer

Pharmacy Affairs Branch. Website Database Downloads PUBLIC ACCESS GUIDE

User Guide. emoney for Outlook

Erado Archiving & Setup Instruction Microsoft Exchange 2007 Push Journaling

PaperStream Connect. Setup Guide. Version Copyright Fujitsu

You must have at least Editor access to your own mail database to run archiving.

OUTLOOK 2007 USER GUIDE

How to Compile, Link, and Execute C or C++ Codes Using Microsoft Visual C++

WebSphere Business Monitor V6.2 Business space dashboards

Clean Up Rules Quick Steps Search Tools Change Views Export Data Convert to tasks Contact Groups. Outlook Functions

Lab 1 Introduction to Microsoft Project

Create, Link, or Edit a GPO with Active Directory Users and Computers

Installing Windows Server Update Services (WSUS) on Windows Server 2012 R2 Essentials

Setting Up ALERE with Client/Server Data

Administrator s Plus. Backup Process. A Get Started Guide

etoken Enterprise For: SSL SSL with etoken

PC Agent Quick Start. Open the Agent. Autonomy Connected Backup. Version 8.8. Revision 0

Printer Sharing of the PT-9500pc in a Windows Environment

Before you can use the Duke Ambient environment to start working on your projects or

In this lab you will explore the Windows XP Firewall and configure some advanced settings.

Presentations and PowerPoint

Pdf - print version. Lab Objectives: When you are finished with this lab you should be able to:

Personal Geodatabase 101

Database Program Instructions

Transitioning from TurningPoint 5 to TurningPoint Cloud - NO LMS 1

Microsoft PowerPoint 2010 Computer Jeopardy Tutorial

CITY OF BURLINGTON PUBLIC SCHOOLS MICROSOFT EXCHANGE 2010 OUTLOOK WEB APP USERS GUIDE

Filtering with Microsoft Outlook

Microsoft Access to Microsoft Word Performing a Mail Merge from an Access Query

HOW TO USE OIT VIA THE WEB

BID2WIN Workshop. Advanced Report Writing

Moving the Web Security Log Database

Programming with the Dev C++ IDE

Word 2010: Mail Merge to with Attachments

SQL Server 2005: Report Builder

Lab - Configure a Windows XP Firewall

WebSphere Business Monitor V6.2 KPI history and prediction lab

Creating Personal Web Sites Using SharePoint Designer 2007

WebSphere Business Monitor V7.0 Business space dashboards

Planning and Managing Projects with Microsoft Project Professional 2013

Test Automation Integration with Test Management QAComplete

4 Other useful features on the course web page. 5 Accessing SAS

Wavecrest Certificate

Nexsure Training Manual - Admin. Chapter 11

HOW TO BURN A CD/DVD IN WINDOWS XP. Data Projects

Install the Production Treasury Root Certificate (Vista / Win 7)

Microsoft Word Quick Reference Guide. Union Institute & University

Filtering Spam Using Outlook s Rule

Avery Wizard: Using the wizard with Microsoft Word. This is a simple step-by-step guide showing how to use the Avery wizard in word

Microsoft Office Access 2007 Basics

Advanced Outlook Tutorials

Basics. a. Click the arrow to the right of the Options button, and then click Bcc.

Microsoft Office. Mail Merge in Microsoft Word

Microsoft Office 2010

Transcription:

Lab 2 - CMPS 1043, Computer Science I Introduction to File Input/Output (I/O) Projects and Solutions (C++) (Revised from http://msdn.microsoft.com/en-us/library/bb384842.aspx) * Keep this information to reference when completing your projects. * In Visual Studio, you organize your work in projects and solutions. A solution can contain more than one project. For more information, see Introduction to Solutions, Projects, and Items. To create a new project 1. From the File menu, point to New, and then click Project. 2. In the Project Types area, click Visual C++. Then, in the Visual Studio installed templates pane, click Win32 Console Application. 3. Type a name for the project. In this example, we'll use HelloFilesYourName. When you create a new project, Visual Studio puts the project in a solution. Accept the default name for the solution, which is the same name as the project. You can accept the default location, type a different location, or browse to a directory where you want to save the project. Press OK to start the Win32 Application Wizard. 4. On the Overview page of the Win32 Application Wizard dialog box, click Next. 5. On the Application Settings page under Application type, select Console Application. Under Additional options select the Empty Project setting and click Finish. You now have a project without source code files. To add a new source file (program) 1. From the Project menu, click Add New Item. Alternatively, to use Solution Explorer to add a new file to the project, right-click the Source Files folder in Solution Explorer and point to Add. Then click New Item. In the Visual C++ area, select Code. Then click C++ File (.cpp). 2. Type the Name of the file to be added (for example, type HelloFilesYourName) and click Add. The source file HelloFilesYourName.cpp will be added to the project. 3. In the HelloFiles.cpp editing window, type the code below for the HelloFilesYourName program. In this example, HelloFilesYourName.cpp will be the main function. Note: Punctuation, Spacing and

Indention are important!! Blank lines are used for readability, but do not affect the execution of the program. #include <iostream> #include <fstream> using namespace std; int main( ) { int birth_date; ifstream infile; ofstream outfile; infile.open( input.txt ); outfile.open( output.txt ); infile >> birth_date; // You may put other statements here } outfile << your name here \n ; outfile << birth_date; infile.close(); outfile.close(); return 0 ; 4. To compile the program, on the Build menu, click Build Solution. You should see output from the build in the Output window indicating that the project compiled without errors. If not, correct the errors indicated in the Output window. To add a text file for input or output 1. From the Project menu, click Add New Item. In the Visual C++ area, select Utility. Then click Text File (.txt). 2. Type the Name of the file to be added (for example, type input if the file is to contain data to be read by the program or type output if the file will have execution results written to it) and click Add. The empty text file (input.txt or output.txt) will be added to the project. (Observe that they have been listed in the folders list on the left of the screen.) NOTE: For this project you will add both an input and an output file. To execute the program CTRL + F5 will compile and execute your program. Because all output was to a file, you will NOT see the Display Window with results on the screen. Observe the Output Window at the bottom of the screen. If no error messages appear, your program probably executed properly.

To View Your Results Click on output.txt either in the left-most window or its tab, if displayed. Your results will be displayed in the main window. Printing your Program Code With your program code displayed on the screen, click the Windows icon in the upper left corner of the screen, select Print. If you are using a color printer, your printout will be in color as on the screen. If not, it will be B/W. Color is NOT necessary for work turned in to your instructors. Lab printers are not color. Printing your Input and Output files With your file code displayed on the screen, click the Windows icon in the upper left corner of the screen, select Print. Do this for each file that you want to print. Documentation Good programming practice insists that all program files must contain documentation. That is, comments from the programmer providing basic information about the program. Documentation lines begin with the // symbols. All programs should have at least the following documentation at the beginning of EVERY program. Your instructor may require additional documentation be included. // Your Last Name, Your First Name // Computer Science 1 - Instructor name // Project # - Project Name // Date // Additional information as required by your instructor In addition, the body of your program should also be documented. This includes adding comments for all components of your program. For more examples of appropriate documentation, see the sample programs in your textbook. Your lab assignment is fully documented. You are to include all the comments as you complete the assignment. *Important Notes: Sometimes you will want to type a program in Word or Notepad then copy into the Visual Studio programming window. If you do this, you MUST check it very carefully because there WILL BE errors in the copy. For example, quotes ( ) must be deleted and retyped after the copy; they will not be the correct version of quotes for C++. Word automatically capitalized some words. This will cause errors in C++ so you will have to retype some words, removing the capital letter at the first of the word or line. There are probably others. * *Learn to recognize the colors in the Visual Studio editor; it will help you spot errors. For example, comments are always in green or should be. Also, literals (words in legal quotes) will be or should be in red. Commands are in black; reserved words in blue.

LAB 2 Assignment Modify the program that you began in class to include the additional code below, including all the documentation (comments). Create an input file containing your year of birth on the first line and the values 2.5 and 3.7 on the second line (as shown in the sample output below). Execute the program, correcting errors as necessary. Print off the program code, the input file and the output file. Staple them together in this order and turn in no later than the first class meeting next week (week of February 7). // Type your name here // Computer Science I Instructor Name (Halverson or Donovan) // Project 2 Lab 2 // January??, 2011 // This is a sample program for the purpose of learning how to enter, compile, // and execute (run) a program with input and output files using the // Microsoft C++ 8.0 programming environment. // It is in the format that each program submitted for grading should follow. // #include <iostream> #include <fstream> using namespace std; int main( ) { // Declarations int birth_date; // declare integer variable for your year of birth float A, B, Sum, Product; // declare real variables for arithmetic ifstream infile; // declare an input file ofstream outfile; // declare an output file infile.open( input.txt ); outfile.open( output.txt ); // open input.txt for reading // open output.txt for writing // Program Code for reading your year of birth infile >> birth_date; // read a value for date of birth from input.txt // Program Code for performing some arithmetic operations infile >> A >> B; // read values for A & B from input.txt Sum = A + B; // Add A & B, storing result in Sum Product = A * B; // Multiply A & B, storing result in Product // Program Code to output results to the output file outfile << your name here \n ; // write your name to out.txt outfile << birth_date << endl; // write birth date to out.txt outfile << A and B have the values << A << << B << endl; outfile << The sum is << Sum << endl; outfile << The Product is << Product << endl; // Commands to close files infile.close(); outfile.close(); return 0 ; } // always close each file so that the I/O buffer will be // written (otherwise, you may not get all of your // results written to the output file)

Sample input & output files ****************************************************************************** Input File 1985 2.5 3.7 ******************************************************************************* Output File Yournamehere 1985 A and B have the values 2 3 The sum is 6.2 The product is 9.25