Assignment 5 Files, Linked Lists, and Binary Search Trees

Similar documents
Honors Introduction to C (COP 3223H) Program 5 Pizza Shack Inventory and Finances

Introduction to Computer Science Midterm 3 Fall, Points

King Abdulaziz University Faculty of Computing and Information Technology Computer Science Department

King Abdulaziz University Faculty of Computing and Information Technology Computer Science Department

Computer Science Foundation Exam

Ex 0bb inventory Test black box

The assignment is due by 1:30pm on Tuesday 5 th April, 2016.

ECE264 Fall 2013 Exam 3, November 20, 2013

EECE.2160: ECE Application Programming

CS 580 FINAL EXAM. Fall April 29, 2014

Midterm Examination # 2 Wednesday, March 19, Duration of examination: 75 minutes STUDENT NAME: STUDENT ID NUMBER:

CS261: HOMEWORK 2 Due 04/13/2012, at 2pm

Sample Examination. Family Name:... Other Names:... Signature:... Student Number:...

General Instructions. You can use QtSpim simulator to work on these assignments.

COP 3502 (Computer Science I) Final Exam 12/10/2015. Last Name:, First Name:

1. Introduction. 2. Deliverables

This exam is worth 24 points, or 24% of your total course grade. The exam contains six

by Pearson Education, Inc. All Rights Reserved. 2

CS 2316 Homework 9b GT Thrift Shop Due: Wednesday, April 20 th, before 11:55 PM Out of 100 points. Premise

Midterm Exam Answers Instructor: Randy Shepherd CSCI-UA.0201 Spring 2017

9/10/10. Arithmetic Operators. Today. Assigning floats to ints. Arithmetic Operators & Expressions. What do you think is the output?

Lecture Notes on Priority Queues

Problem A - Complete the sequence

ECE 264 Exam 2. 6:30-7:30PM, March 9, You must sign here. Otherwise you will receive a 1-point penalty.

Problem 1: Hello World!

Midterm Examination # 2 Wednesday, March 18, Duration of examination: 75 minutes STUDENT NAME: STUDENT ID NUMBER:

Fundamental Concepts: array of structures, string objects, searching and sorting. Static Inventory Maintenance Program

Q1: Multiple choice / 20 Q2: C input/output; operators / 40 Q3: Conditional statements / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

Data Structure using C++ Lecture 04. Data Structures and algorithm analysis in C++ Chapter , 3.2, 3.2.1

Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators

Q1: Functions / 33 Q2: Arrays / 47 Q3: Multiple choice / 20 TOTAL SCORE / 100 Q4: EXTRA CREDIT / 10

Computer Science Foundation Exam

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Midterm II Exam Principles of Imperative Computation Frank Pfenning. March 31, 2011

Name CPTR246 Spring '17 (100 total points) Exam 3

NET/JRF-COMPUTER SCIENCE & APPLICATIONS. Time: 01 : 00 Hour Date : M.M. : 50

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

CMSC 313 Fall2009 Midterm Exam 1 Section 01 October 12, 2009

: Principles of Imperative Computation Victor Adamchik. Practice Exam - I

CS 3204 Operating Systems Programming Project #2 Job / CPU Scheduling Dr. Sallie Henry Spring 2001 Due on February 27, 2001.

The Program Specification:

gcc o driver std=c99 -Wall driver.c bigmesa.c

Programming Assignment Multi-Threading and Debugging 2

Assignment 4 - AVL Binary Search Trees

Foundation Exam - Sample Problems for New Topics

Computer 2 App1. App3 API Library. App3. API Library. Local Clipboard

C: How to Program. Week /Mar/05

Exam Principles of Imperative Computation, Summer 2011 William Lovas. June 24, 2011

CSE 333 Midterm Exam 2/14/14

Computer Science Foundation Exam

Midterm I Exam Principles of Imperative Computation Frank Pfenning. February 17, 2011

ECE 122. Engineering Problem Solving Using Java

Biostatistics 615/815 - Lecture 2 Introduction to C++ Programming

The type of all data used in a C (or C++) program must be specified

World Inside a Computer is Binary

Lecture (07) Arrays. By: Dr. Ahmed ElShafee. Dr. Ahmed ElShafee, ACU : Fall 2015, Programming I

Chapter 2 - Introduction to C Programming

COP Programming Assignment #7

EL2310 Scientific Programming

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Programming Assignment #4

Chapter 1 & 2 Introduction to C Language

DEPARTMENT OF MATHS, MJ COLLEGE

Programming Using C Homework 5

Project#3 [40 points] COP 2220 Fall 2017

2SKILL. Variables Lesson 6. Remembering numbers (and other stuff)...

CS 237 Meeting 19 10/24/12

AGENDA Binary Operations CS 3330 Samira Khan

Think Like a Programmer

Recursion. So, just as you are allowed to call function B from within function A, you are ALSO allowed to call function A from within function A!

Data Structure and Algorithm Homework #3 Due: 2:20pm, Tuesday, April 9, 2013 TA === Homework submission instructions ===

Computer Science Foundation Exam

Here's how you declare a function that returns a pointer to a character:

This is CS50. Harvard University Fall Quiz 0 Answer Key

Use a calculator and c = 2 π r to calculate the circumference of a circle with a radius of 1.0.

BASIC ELEMENTS OF A COMPUTER PROGRAM

ECE264 Spring 2013 Final Exam, April 30, 2013

Differentiate Between Keywords and Identifiers

Carleton University Department of Systems and Computer Engineering SYSC Foundations of Imperative Programming - Winter Lab 8 - Structures

Assignment 2: Temperature Class

CSC 307 DATA STRUCTURES AND ALGORITHM ANALYSIS IN C++ SPRING 2011

ScrimmageSim Business Simulation Ordering Exercise Instructions

CSE 333 Midterm Exam 7/29/13

CSI33 Data Structures

Lab 03 - x86-64: atoi

CIS 2107 Computer Systems and Low-Level Programming Fall 2011 Midterm

EECE.2160: ECE Application Programming Fall 2017

SUMMER REVIEW PACKET 2 FOR STUDENTS ENTERING ALGEBRA 1

CSE 142, Winter 2007 Final Exam. Name:

EECE.2160: ECE Application Programming Fall 2017 Exam 3 December 16, 2017

INFO1x05 Tutorial 6. Exercise 1: Heaps and Priority Queues

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

Answer all questions. Write your answers only in the space provided. Full marks = 50

CS 1044 Program 6 Summer I dimension ??????

Arithmetic Operators. Portability: Printing Numbers

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal

CS16 Final Exam E03, 10S, Phill Conrad, UC Santa Barbara Wednesday, 06/09/2010

EE 472 Embedded Systems. Name solutions. Instructions:

Decision Logic: if, if else, switch, Boolean conditions and variables

1. Overview This project will help you understand address spaces and virtual memory management.

Transcription:

Assignment 5 Files, Linked Lists, and Binary Search Trees Technical details We advise you to look carefully at the example input and output files that we supply. Many questions will be answered by simply reviewing these files and the instructions. Carefully read the next sections and follow the directions meticulously. Strictly follow the input/output instructions! As in the previous assignments, keep in mind that the code you submit is tested by automated tools. Failing to produce the exact same output as our published executable will negatively impact your grade. Introduction You were just hired for your first job as the programmer for a large logistics company. The only problem is that the company s entire inventory system just crashed! The only information left are the following files: 1. An old inventory file which is one year old. 2. A file for every customer of the company, detailing all purchases from the past year. 3. A file containing the minimal number of items that must be in stock for each product. Your mission is to recreate the inventory and restore order in the company. Part 1 Reading the old inventory file and recreating the old inventory using a binary search tree. This will be done by implementing the function: product_tree *read_initial_stock_file(file *initial_stock_file); The initial inventory file contains the ID and name of the product and the quantity of this product in stock one year ago. For every product there will be exactly one line in the file: - Product ID: 9 digits exactly. Can begin with a 0. - One space character ( ). - Product name: 10 chars exactly. - Quantity: a number between 0-9999. An example of such a file is included in the assignment web site: InitialInventory.txt.

Each product will be stored in memory as a node of a binary search tree. Every node in the tree will be as follows: typedef struct product_tree { char *id; //Product ID number. This is the key of the search tree. char *product_name; //Name of the product. int current_quantity; //How many items are there in stock, currently. double current_average_rating; //The current average rating of the //product. Each customer's rating is //given the same weight. This is //initially 0. sales_info *sales; //This is initially empty. struct product_tree *left, *right; } product_tree; The product tree will be sorted by the product s ID number. This means that for every node in the tree, all products in the left subtree must have lower IDs than the node, and all products in the right subtree must have greater IDs than the node! The initial inventory file will be read line by line, adding a node to the product tree for every line. The current_average_rating will be given 0, and sales will remain empty for now. After reading the initial inventory, you will procede to reading all the customer files. This will be done by implementing the function: void read_customer_sales(file *customer_file, product_tree *root_product); Every customer file will be of the following structure: - The first line will contain the ID of the customer: 9 digits exactly. Can begin with a 0. - All other lines will represent purchases: Product ID (9 digits exactly), one space character ( ), number of items purchased (integer between 1-9999), one space character ( ), rating of the product (integer between 1-100). You can assume that a customer will appear at most once per product. An example of such a file is included in the assignment web site, Customer1.txt. Each purchase will be stored in memory as a node in a linked list, named sales. This list is defined as follows: typedef struct sales_info { char *customer_id; //ID number of the customer. int rating; //Rating that the customer gave the product. Number //between 1 and 100. int quantity; //How many items did the customer buy. struct sales_info *next; } sales_info;

When you read a purchase line from the customer file, you must insert the sales_info node (that has the customer_id, rating, and quantity) into the end of the sales list of the relevant product. When inserting a sales_info node, you must do two additional things: 1. Update the field current_quantity in the product_tree node. This is done by subtracting the quantity of the sale from current_quantity. 2. Update the field current_average_rating in the product_tree node. This is done by computing the average rating given by the customers that bought the product. For example, if a product has two sales with ratings 40 and 71, its current_average_rating will be (40+71)/2=55.5. If another sale is added, the current_average_rating is re-computed. When you are finished reading all customer files, you are expected to have the product tree, where the sales list for every product contains all sales made by all customers, and the current_quantity and current_average_rating of all the products are updated.

Part 2 Now that you have the current inventory, you must generate some reports for your boss. The first report will be concerning the products. You will implement the following function: void create_product_report(product_tree *root_product, char *product_report_file_name); This function will create a file named product_report_file_name, which will contain the following: 1. The first part of the report will be a list of the products, ordered by their IDs from low to high. Every product will be in a separate line, with the following structure: Product ID (9 digits exactly), one space character ( ), current_quantity (integer 0-9999), one space character ( ), current_average_rating (double 1-100, one digit after the decimal point; examples: 97.4, 100.0). 2. An empty line. 3. The second part of the report will be a list of the products, ordered by the popularity from lowest to highest. The line structure here is the same as in the first part. An example of such a report is included in the assignment web site, ProductReport.txt. The seconed report will be concerning orders that need to be done to match a certain minimum inventory. You will implement the following function: void create_order_report(product_tree *root_product, FILE *minimal_stock_file, Char *order_report_file_name); For this report you will need to read the minimal_stock_file. Every line in this file represents a product and has the following structure: - Product ID: 9 digits exactly. - Minimal quantity that must be in stock: Integer 1-9999.

This report must have one line for each product for which the current stock is lower than the minimal quantity that must be in stock (taken from minimal_stock_file). There will be one line per product with the following structure: - Product ID: 9 digits exactly. - The quantity we need to order so that we have the minimal quantity in stock. For example, if product no. 123456789 has a current stock of 15, and its minimal quantity is 105, then we would output the line: 123456789 90 An example of such a report is included in the assignment web site: OrderReport.txt. Some (important) clarifications: 1. You may assume the input is correct! For example, IDs of products and customers, as well as average ratings of products, will be unique, and quantities will never drop below zero. 2. You are provided with a skeleton file for the code (assignment5.c). You must use (and submit) this file! 3. You should not change any of the functions given to you. Changing them will result in a 0 grade! 4. You should not change the main function. All you need to do is implement the additional functions (according to the declared prototypes). You can of course add more functions, but think carefully before you do.