Chapter 10: Records (structs)

Slides:



Advertisements
Similar presentations
Database vocabulary. Data Information entered in a database.
Advertisements

Chapter 10: Applications of Arrays and the class vector
Student Data Score First Name Last Name ID GPA DOB Phone... How to store student data in our programs? 1.
Repetition Control Structures School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 9, Friday 3/07/2003)
Chapter 11: Classes and Objects
3.1 Data and Information –The rapid development of technology exposes us to a lot of facts and figures every day. –Some of these facts are not very meaningful.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 10: Records ( structs )
Flow Master  Flow Master is used to design and analyze single pipe.  It is very flexible as no unit conversion is needed.  Data can be entered with.
Programming with Microsoft Visual Basic 2005, Third Edition
Algorithms. Software Development Method 1.Specify the problem requirements 2.Analyze the problem 3.Design the algorithm to solve the problem 4.Implement.
CS 112 Intro to Computer Science II Sami Rollins Fall 2006.
Chapter 6: User-Defined Functions I
An Introduction to Programming with C++ Fifth Edition
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 11: Records (structs)
Arrays.
Chapter 6: User-Defined Functions I
JavaScript with Input & Output Step 1: Use tags JavaScript Template.
Overview of Transaction Processing and Enterprise Resource Planning Systems Chapter 2.
Chapter 5: Control Structures II (Repetition)
Page 1 Returns Receivings By MIS Department. Page 2 The Returns Process When a store or customer wants to return goods, they are supposed to contact the.
ACCESS. » Access is a database management system. » This system lets you create and process data. » A database is a collection of data that is organized.
Chapter 10: Records (structs)
12-1 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout John.
Loop Exercise 1 Suppose that you want to take out a loan for $10,000, with 18% APR, and you're willing to make payments of $1,200/month. How long will.
Looping While-continue.
Chapter 10 Applications of Arrays and Strings. Chapter Objectives Learn how to implement the sequential search algorithm Explore how to sort an array.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 11: Records ( struct s)
Chapter Ten Structures and Sequential Access Files Programming with Microsoft Visual Basic th Edition.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 10: Records ( struct s)
Array Processing.
Chapter 10: Records (structs)
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Objectives: In this chapter, you will: Know the different between struct and array.
More While Loop Examples CS303E: Elements of Computers and Programming.
Chapter 6: Arrays: Lists and Tables
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter Six The Do Loop and List Boxes.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 3: Input/Output.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 10: Applications of Arrays (Searching and Sorting) and the vector Type.
Pseudocode Algorithms Using Sequence, Selection, and Repetition
CS 100 Introduction to Computing Seminar
1 Guide to Oracle10G CHAPTER 7: Creating Database Reports 7.
Structures (aka records, structs) Textbook Chapter 11 sections:
File Handling in QBASIC
Find the amount after 7 years if $100 is invested at an interest rate of 13% per year if it is a. compounded annually b. compounded quarterly.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 11: Records ( struct s)
An Introduction to Programming with C++ Sixth Edition Chapter 13 Strings.
An Introduction to Programming with C++ Sixth Edition Chapter 12 Two-Dimensional Arrays.
Chapter 2: Input, Processing, and Output Starting Out with Programming Logic & Design by Tony Gaddis (with instructor modifications) 1-1.
General Condition Loop A general condition loop just loops while some condition remains true. Note that the body of the loop should (eventually) change.
CIS 115 All Exercises Devry University (Devry) For more course tutorials visit CIS 115 All Exercises Devry University.
Problem solving Chapter 3
CIS 115 All Exercises Devry University (Devry) FOR MORE CLASSES VISIT CIS 115 All Exercises Devry University.
CIS 115 ALL EXERCISES DEVRY UNIVERSITY (DEVRY)  CIS 115 All Exercises Devry University CIS 115 ALL ILABS DEVRY UNIVERSITY (DEVRY)  CIS 115 All iLabs.
CSC111 Quick Revision.
Chapter 6: User-Defined Functions I
Exercise : Write a program that print the final price of purchase at a store where everything costs exactly one dollar. Ask for the number of items purchased.
MT262A Review.
Databases.
Chapter 5: Control Structure
User-Defined Functions
CIS115 Education for Service-- snaptutorial.com
CIS 115Competitive Success/tutorialrank.com
CIS 115 Education for Service-- tutorialrank.com.
CIS 115 Teaching Effectively-- snaptutorial.com
For Monday Read WebCT quiz 18.
Overview of Transaction Processing and Enterprise Resource Planning Systems Chapter 2.
Structured Program Design
For Wednesday No new reading No quiz.
Example Using Functions
Objectives In this chapter, you will: - Learn about records (structs) - Examine operations on a struct - Manipulate data using a struct - Learn about the.
Presentation transcript:

Chapter 10: Records (structs) C++ Programming: Program Design Including Data Structures, Second Edition Chapter 10: Records (structs)

Programming Example A company has six salespeople Every month they go on road trips to sell the company’s product At the end of each month, the total sales for each salesperson, salesperson’s ID, and the month, are recorded in a file At the end of each year, the manager of the company asks for a report C++ Programming: Program Design Including Data Structures, Second Edition

Output Format ----------- Annual Sales Report ------------- ID QT1 QT2 QT3 QT4 Total _______________________________________________________________ 12345 1892.00 0.00 494.00 322.00 2708.00 32214 343.00 892.00 9023.00 0.00 10258.00 23422 1395.00 1901.00 0.00 0.00 3296.00 57373 893.00 892.00 8834.00 0.00 10619.00 35864 2882.00 1221.00 0.00 1223.00 5326.00 54654 893.00 0.00 392.00 3420.00 4705.00 Total 8298.00 4906.00 18743.00 4965.00 Max Sale by SalesPerson: ID = 57373, Amount = $10619.00 Max Sale by Quarter: Quarter = 3, Amount = $18743.00 QT1 stands for quarter 1 (months 1 to 3), QT2 for quarter 2 (months 4 to 6), QT3 for quarter 3 (months 7 to 9) and QT4 for quarter 4 (months 10 to 12) C++ Programming: Program Design Including Data Structures, Second Edition

Programming Example The salespeople IDs are stored in one file; sales data are stored in another file The sales data is in the following form: salesPersonID month saleAmount . Sales data are not ordered C++ Programming: Program Design Including Data Structures, Second Edition

Input/Output Input: file containing each salesperson’s ID, and a second file containing the sales data Output: file containing annual sales report in the above format C++ Programming: Program Design Including Data Structures, Second Edition

Problem Analysis Main components for each sales person: ID Quarterly sales amount Total annual sales amount Because the components are of different types, group them in a struct C++ Programming: Program Design Including Data Structures, Second Edition

Program Analysis (continued) There are six people, so an array of 6 components is used Because the program requires the company’s total sales for each quarter We need an array of four components to store the data C++ Programming: Program Design Including Data Structures, Second Edition

Program Analysis (continued) Read the salespeople IDs into the array salesPersonList Initialize the quarterly sales and total sales for each salesperson to 0 C++ Programming: Program Design Including Data Structures, Second Edition

Program Analysis (continued) For each entry in the file containing the sales data Read ID, month, sale amount for the month Search salesPersonList to locate the component corresponding to this salesperson Determine the quarter corresponding to the month Update the sales for the quarter by adding the sale amount for the month C++ Programming: Program Design Including Data Structures, Second Edition

Program Analysis (continued) Once the sales data file is processed Calculate the total sale by salesman Calculate the total sale by quarter Print the report C++ Programming: Program Design Including Data Structures, Second Edition

Algorithm Design Translates into the following algorithm Initialize the array sales Process the sales data Calculate the total sale by salesman Calculate the total sale by quarter Print the report Calculate and print maximum sale by salesman Calculate and print maximum sale by quarter C++ Programming: Program Design Including Data Structures, Second Edition

Main Algorithm Declare the variables Prompt user to enter name of file containing the salesperson’s ID data Read the name of the input file Open the input file If input file does not exist, exit Initialize the array salesPersonList by calling the function initialize C++ Programming: Program Design Including Data Structures, Second Edition

Main Algorithm (continued) Close input file containing salesperson’s ID Prompt user to enter name of file containing sales data Read the name of the input file Open the input file If input file does not exist, exit Prompt user to enter name of output file Read the name of the output file C++ Programming: Program Design Including Data Structures, Second Edition

Main Algorithm (continued) Open the output file Output data to two decimal places Process sales data Call the function getData C++ Programming: Program Design Including Data Structures, Second Edition

Main Algorithm (continued) Calculate the total sale by quarter by calling the function saleByQuarter Calculate the total sale by salesman by calling the function totalSaleByPerson Print the report in the tabular form. Call the function printReport Find and print the salesperson who produces the maximum sales for the year by calling the function maxSaleByPerson C++ Programming: Program Design Including Data Structures, Second Edition

Main Algorithm (continued) Find and print the quarter producing the maximum sale for the year by calling the function maxSaleByQuarter Close files C++ Programming: Program Design Including Data Structures, Second Edition