CS 107 Introduction to Computing and Programming Fall 2013 Homework Assignment 7 - First Draft Atomic Weights of Compounds with Pointers to Structures

Size: px
Start display at page:

Download "CS 107 Introduction to Computing and Programming Fall 2013 Homework Assignment 7 - First Draft Atomic Weights of Compounds with Pointers to Structures"

Transcription

1 CS 107 Introduction to Computing and Programming Fall 2013 Homework Assignment 7 - First Draft Atomic Weights of Compounds with Pointers to Structures Due: Monday December 2nd by 8:00 a.m., via Blackboard. Optional hard copy may be turned in during lab. Overall Assignment This assignment will read in the same chemical element data that was used in the last assignment, except this time the data will be stored in an array of structs instead of four separate arrays. We will then set up two additional data structures for accessing the data, ( an array of pointers to structs and a simple linked list ), so that we can "sort" the data by different criteria without having to actually move any data around. Background: Atomic Weights of Chemical Compounds ( Copied from HW 6, except where noted. ) If we had available to us the following element information 1 : Name Atomic Symbol Atomic Number Atomic Weight Carbon C Chlorine Cl Fluorine F Hydrogen H Oxygen O Nitrogen N Sodium Na Then we could calculate the total atomic weights of the following compounds by simply adding up the weights of their component elements 2 : Formula Common Name Atomic Weight H Hydrogen Cl Chlorine HF Hydrogen Fluoride HCl Hydrochloric Acid NaCl Salt H 2 O Water C 6 H 12 O 6 Sugar C 8 H 10 N 4 O 2 Caffeine NaHCO 3 Baking Soda CHCl 3 Chloroform CH 3 CH 2 OH Ethanol Our challenges in this program will be to: 1. Read in the data that we need regarding elemental atomic weights from a data file, and store them in an array of structs appropriate for our use, and 2. Creating two additional data structures for accessing the data, an array of pointers to structs and a linked list, to sort the list by different criteria. 1 Source: 2 See and related pages for other examples

2 Command Line Arguments ( Same as HW6 ) For this assignment your program must accept two [ optional ] command line arguments, the name of the data file from which to read in the elemental data, and the number of elements to print. [ optional ] means that the user can either provide the arguments or not, as they choose. Your program must accept them and use them if they are given. ( However the user may not omit the first argument without also omitting the second. ) Your program should check the number of arguments given, which should be from 1to 3, ( including the program name, argv[ 0 ]. ) If any other number of arguments are given, then your program should print out a usage message and then exit. If a name is given on the command line, your program should attempt to open the file for reading. If the filename is not given, or if your program cannot open it for reading, then the program should prompt the user to enter one, repeating until the user enters the name of a file that can be opened. If the number of elements to print is omitted, ( or is unreasonable ), then your program should print all the elements when printing. Data Structures Required For this assignment four major data structures will be required: 1. The first will be a struct for holding data for a single element: struct Element { char name[ 20 ]; char symbol[ 3 ]; int atomicnumber; double atomicweight; }; 2. The second will be an array of struct Elements. 3. The third will be an array of struct Element *s, i.e. pointers to struct Elements. 4. The fourth will be a linked list, in which each node contains a pointer to a struct Element and a pointer to the next node in the list: struct Node { struct Element *element; struct Node *next; }; Data File Processing ( Modified from HW6 ) The data file that will be provided for this assignment starts out with a single integer on a line by itself, indicating how many additional lines of data ( i.e. how many elements ), are in the data file. Your program should read in that number using fscanf. ( An additional call to fgets will be required, to clear the newline character at the end of the first line. )

3 The remaining lines of the file will begin with an element name, which is always a single word with 15 or fewer characters, followed by a chemical symbol, which is always a single word of one or two characters, followed by an int for the atomic number, followed by a double for the atomic weight, followed by other information that does not concern us, but which we must read out of the input file nonetheless. For example: Chlorine Cl Scheele 1774 In order to read in the data from the data file, perform the following steps: 1. Use fscanf to read in the number of elements from the first line. Let's call this value nelements. 2. Create an array of nelements structs of type Element. Let's call this array elements. 3. For each of the next nelements lines: a. Use fgets to read in the entire line into a character array. 200 Characters should be plenty. b. Use sscanf to scan the four fields you need from the beginning of each line into the appropriate fields of the next Element in the array, using the correct format specifiers for each data type. Your program should verify that each call to fscanf, fgets, and sscanf work properly, and exit if any errors are encounted. Part I - Printing the Elemental Data in the Original Order ( Alphabetical by Name ) After the elemental data is read in from the data file, the first step will be to print out the data in the array of structs, in the order in which it was read in from the file, ( which will be alphabetical by name. ) Note that the second command line argument ( argv[ 2 ] ) should be the number of elements to print, which will need to be converted from a character string to an integer using atoi. If this argument is not given, or if it does not convert to a reasonable value, then print the entire list of elements Part II - Printing the Elemental Data in Alphabetical Order by Atomic Symbol Using Pointers 1. The next step will be to create an array of size nelements, where each item in the array is of type "struct Element *", i.e. pointers to struct Elements. Let's call this array elementptrs. 2. Set up the elementptrs array so that each pointer points to the corresponding struct in the elements array. I.e. elementptrs[ i ] should hold the address of elements[ i ], for all i from 0 to nelements - 1. Next we need to sort the array of pointers according to the alphabetical order of the element symbols in the structs that the pointers point to, using a simple Selection Sort. ( The Selection Sort is not very efficient for large numbers of data items, but it is adequate for our needs, and it is simple and easy to code and understand. ) The basic idea behind the selection sort is to start by putting the smallest value in the first position, and then the next smallest in the second position, and so on until all but one of the positions has been filled, at which point the last remaining data item must belong in the last position. For this program we will write three functions to perform the sorting, as follows: int findmin( struct Element * array[ ], int start, int nelements ); Finds the "minimum" valued array index, searching from start to the end of the array.

4 void swap( struct Element * array[ ], int first, int second ); Exchanges the pointers in array positions first and second. void sort( struct Element * array[ ], int nelements ); Conducts a selection sort on the array of pointers, using the following algorithm: for i from 0 to nelements - 2 // i is the position to be "filled" next find the minimum of elements from position i + 1 to the end of the array if the minimum element found is "less than" element i swap element i with the minimum element found In order to determine if one element is "less than" another, use the strcmp( ) function to compare the chemical symbols in the structs pointed to by the two pointers. ( elementptrs[ i ]->symbol versus elementptrs[ min ]->symbol ) This function must use the findmin( ) function to find the minimum following element, and the swap( ) function to swap the pointers. Once the array of pointers has been sorted, print out the element information using the array of pointers, up to the limit specified on the command line, or nelements if there is no such reasonable limit given. Part III - Printing the Elemental Data in Atomic Number Order Using a Linked List For the third sorting order, we are going to build a simple linked list. While it is possible to sort a linked list, for this assignment we will make our life easier by simply building the list in sorted order to begin with. We will also take advantage of our knowledge that the atomic numbers go from 1 to nelements without gaps or duplications. For this part of the assignment we will need the following functions: struct Element * findatomicnumber( struct Element elements[ ], int nelements, int target ); Returns a pointer to the struct Element in the array elements[ ] whose atomic number is equal to target, or NULL if no such struct could be found. ( In the event that the array contained two such structs, then the first one found should be returned. This condition should not occur with the data file provided for this assignment. ) struct Node *makenode( struct Element * elementptr ); Creates a Node containing a pointer to a struct Element using malloc( ), and returns a pointer to it, or returns NULL if malloc( ) fails or if any other error is encountered. struct Node *insertnode( struct Node * head, struct Node * newnode); Inserts the new Node at the head of the list, and returns a pointer to the new head of the list.

5 The general algorithm for creating this linked list will be as follows: Start with a struct Node pointer named "head", and set it equal to NULL. for i = nelements to 1 // Insert nodes in reverse order so it will be forwards later Find the struct in the elements array that has atomic number i. ( findatomicnumber ) Create a new struct Node, and assign it to a pointer "newnode". ( makenode ) Add the new node to the head of the list. ( insertnode ) Once the linked list has been created, print out the element information using the linked list, up to the limit specified on the command line, or nelements if there is no such reasonable limit given. Parsing the User's Input This is exactly the same as HW6, except you will now get the data you need to calculate the molecular weights from the elements array of Element structures instead of having to access 4 separate arrays. See the HW6 assignment for details of the chemtok( ) function. Sample Output ( Subset of samples from HW 6 ) For each compound that the user enters, your program should report the elements present in the compound, the quantity of each element, and the total atomic weight of the compound. For example: Your compound, H2O, contains: 2 Hydrogen, atomic number 1, atomic weight Oxygen, atomic number 8, atomic weight 15,9994 for a total atomic weight of Your compound, CH3CH2OH, contains: 1 Carbon, atomic number 6, atomic weight Hydrogen, atomic number 1, atomic weight Carbon, atomic number 6, atomic weight Hydrogen, atomic number 1, atomic weight Oxygen, atomic number 8, atomic weight 15, Hydrogen, atomic number 1, atomic weight for a total atomic weight of Your compound, CH3CH2OH, contains: 2 Carbon, atomic number 6, atomic weight Hydrogen, atomic number 1, atomic weight Oxygen, atomic number 8, atomic weight 15,9994 for a total atomic weight of

6 Incremental Development It is highly recommended that you NOT try to write the whole program at once. First verify that you can read in and print out the element information using the array of structs. Then create the array of pointers, and print out the list using those pointers. ( Without sorting. ) Then sort the array of pointers, and print out the sorted array. Then work on the linked-list implementation. Note that the use of chemtok and calculation of molecular weights is a relatively minor part of this assignment, since you presumably completed that part for HW6. However you will need to modify your code from HW6 to calculate the molecular weights using the array of structs instead of 4 separate arrays. What to Hand In: Your code, including documentation, should be handed in electronically on Blackboard. All files should be zipped together into a single file, whose name is comprised of your ACCC netid followed by the course number followed by the letters "HW", followed by the assignment number. ( E.g. jbell107hw1.zip ) The zip file should be handed in via Blackboard. ( Your TA may provide alternative submission instructions. ) The intended audience for the documentation file is a general end user, who might want to use this program to perform some work. They do not get to see the inner workings of the code, and have not read the homework assignment. You can assume, however, that they are familiar with the problem domain ( e.g. elements, chemical formulas, and molecular weights. ) A secondary purpose of the documentation file is to make it as easy as possible for the grader to understand your program. If there is anything special the grader should know about your program, be sure to document it in the documentation file. In particular, if you do any of the optional enhancements, then you need to document what they are and anything special the TA needs to do to run your program and understand the results. If there are problems that you know your program cannot handle, it is best to document them as well, rather than have the TA wonder what is wrong with your program. Make sure that your name appears at the beginning of each of your files. Your program should also print this information when it runs. Optional Enhancements: It is course policy that students may go above and beyond what is called for in the base assignment if they wish. These optional enhancements will not raise any student s score above 100 for any given assignment, but they may make up for points lost due to other reasons. Parsing more complex user input, such as compounds containing parentheses: CH3(CH2)6CH3 Sorting the pointer array using a more advanced sorting algorithm, such as insertion, bubble, shaker, merge, or quicksort. See the following section for more information. ( Sorting using the C Library built-in sort routine is only valid as a second sort, in addition to the insertion sort, and then only if you write your own comparator function. ) Printing the linked list in reverse order, using recursion. Building another linked list to sort the elements by molecular weight, by adding the nodes to the linked list in the order in which they were read from the file. This means that for each node it will first be necessary to find the position in the list where the new node belongs. Other enhancements that you think of Check with TA for acceptability. Note: Optional enhancements that you already mastered in one HW should not receive a lot of credit if you just repeat them again for later HW.

7 Sorting Algorithms: The selection sort is only one of many different sorting algorithms. It is not the most efficient, particularly when a large number of data items must be sorted, but it has the advantage of being simple and easy to understand and to code. The following links provide more information about the selection sort algorithm as well as some other popular sorting algorithms. ( Note: direct copying of the code samples from these pages is a really BAD idea, partially because it is against the rules, but also because many of the code samples are much more complex than what we need, and are beyond the scope of this course. If you want to pursue these, you should study the algorithms to understand how they work, and then write your own code to implement the ideas. ) General discussion and comparison of sorting algorithms: o Selection sort: o Insertion sort: o Bubble sort: o Cocktail sort, a.k.a. Shaker sort: o Gnome sort: o Merge sort: o Quicksort: Note that it is also possible to combine some of these sorting techniques. For example, the data could be broken down into small groups, each of which is individually sorted, and then the sorted group combined using merge sort. Quick sort is another divide-and-conquer strategy that often uses a simpler sort algorithm once the data set size to be sorted falls below some threshold.

CS 361 Computer Systems Fall 2017 Homework Assignment 1 Linking - From Source Code to Executable Binary

CS 361 Computer Systems Fall 2017 Homework Assignment 1 Linking - From Source Code to Executable Binary CS 361 Computer Systems Fall 2017 Homework Assignment 1 Linking - From Source Code to Executable Binary Due: Thursday 14 Sept. Electronic copy due at 9:00 A.M., optional paper copy may be delivered to

More information

CS 450 Introduction to Networking Spring 2014 Homework Assignment 1 File Transfer and Data Bandwidth Analysis Tool

CS 450 Introduction to Networking Spring 2014 Homework Assignment 1 File Transfer and Data Bandwidth Analysis Tool CS 450 Introduction to Networking Spring 2014 Homework Assignment 1 File Transfer and Data Bandwidth Analysis Tool Due: Monday 17 February. Electronic copy due at 10:30 A.M., Optional paper copy may be

More information

CS 109 C/C ++ Programming for Engineers w. MatLab Summer 2012 Homework Assignment 4 Functions Involving Barycentric Coordinates and Files

CS 109 C/C ++ Programming for Engineers w. MatLab Summer 2012 Homework Assignment 4 Functions Involving Barycentric Coordinates and Files CS 109 C/C ++ Programming for Engineers w. MatLab Summer 2012 Homework Assignment 4 Functions Involving Barycentric Coordinates and Files Due: Wednesday July 11th by 8:00 a.m., via Blackboard. Optional

More information

CS 61B Summer 2005 (Porter) Midterm 2 July 21, SOLUTIONS. Do not open until told to begin

CS 61B Summer 2005 (Porter) Midterm 2 July 21, SOLUTIONS. Do not open until told to begin CS 61B Summer 2005 (Porter) Midterm 2 July 21, 2005 - SOLUTIONS Do not open until told to begin This exam is CLOSED BOOK, but you may use 1 letter-sized page of notes that you have created. Problem 0:

More information

CS 385 Operating Systems Fall 2011 Homework Assignment 5 Process Synchronization and Communications

CS 385 Operating Systems Fall 2011 Homework Assignment 5 Process Synchronization and Communications CS 385 Operating Systems Fall 2011 Homework Assignment 5 Process Synchronization and Communications Due: Friday December 2 at 8:00 P.M. via Blackboard Overall Assignment Man Pages For this assignment,

More information

CS 361 Computer Systems Fall 2017 Homework Assignment 4 - Inter-Process Communications & I/O

CS 361 Computer Systems Fall 2017 Homework Assignment 4 - Inter-Process Communications & I/O CS 361 Computer Systems Fall 2017 Homework Assignment 4 - Inter-Process Communications & I/O Overall Assignment For this assignment, you are to write three programs that will work together using inter-process

More information

Computer Science 50: Introduction to Computer Science I Harvard College Fall Quiz 0 Solutions. Answers other than the below may be possible.

Computer Science 50: Introduction to Computer Science I Harvard College Fall Quiz 0 Solutions. Answers other than the below may be possible. Quiz 0 Solutions Answers other than the below may be possible. Short Answers. 0. :-) 1. 10111111 + 00000001 11000000 2. For efficiency, characters printed to stdout are buffered until a newline is printed

More information

CS 385 Operating Systems Fall 2011 Homework Assignment 4 Simulation of a Memory Paging System

CS 385 Operating Systems Fall 2011 Homework Assignment 4 Simulation of a Memory Paging System CS 385 Operating Systems Fall 2011 Homework Assignment 4 Simulation of a Memory Paging System Due: Tuesday November 15th. Electronic copy due at 2:30, optional paper copy at the beginning of class. Overall

More information

Homework #1 From C to Binary

Homework #1 From C to Binary Homework #1 From C to Binary Updated 2017-08-11: Clarify PI constant and use of floats. Updated 2017-08-21: Slightly reformat Q3 to be consistent with HW2 (no content changes). Updated 2017-09-01: Minor

More information

CS 342 Software Design Spring 2018 Term Project Part II Development of Question, Answer, and Exam Classes

CS 342 Software Design Spring 2018 Term Project Part II Development of Question, Answer, and Exam Classes CS 342 Software Design Spring 2018 Term Project Part II Development of Question, Answer, and Exam Classes Due: Wednesday 21 February. Electronic copy due at 3:30 P.M. Optional paper copy may be handed

More information

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

CS261: HOMEWORK 2 Due 04/13/2012, at 2pm CS261: HOMEWORK 2 Due 04/13/2012, at 2pm Submit six *.c files via the TEACH website: https://secure.engr.oregonstate.edu:8000/teach.php?type=want_auth 1. Introduction The purpose of HW2 is to help you

More information

CS 342 Software Design Fall 2018 Term Project Part II Addition of Artifacts and Data File Processing

CS 342 Software Design Fall 2018 Term Project Part II Addition of Artifacts and Data File Processing CS 342 Software Design Fall 2018 Term Project Part II Addition of Artifacts and Data File Processing Due: Wednesday 3 Oct. Electronic copy due at 12:30 P.M. Optional paper copy may be handed in during

More information

Exercise 1.1 Hello world

Exercise 1.1 Hello world Exercise 1.1 Hello world The goal of this exercise is to verify that computer and compiler setup are functioning correctly. To verify that your setup runs fine, compile and run the hello world example

More information

CS61C Machine Structures. Lecture 3 Introduction to the C Programming Language. 1/23/2006 John Wawrzynek. www-inst.eecs.berkeley.

CS61C Machine Structures. Lecture 3 Introduction to the C Programming Language. 1/23/2006 John Wawrzynek. www-inst.eecs.berkeley. CS61C Machine Structures Lecture 3 Introduction to the C Programming Language 1/23/2006 John Wawrzynek (www.cs.berkeley.edu/~johnw) www-inst.eecs.berkeley.edu/~cs61c/ CS 61C L03 Introduction to C (1) Administrivia

More information

STUDENT LESSON A12 Iterations

STUDENT LESSON A12 Iterations STUDENT LESSON A12 Iterations Java Curriculum for AP Computer Science, Student Lesson A12 1 STUDENT LESSON A12 Iterations INTRODUCTION: Solving problems on a computer very often requires a repetition of

More information

Strings(2) CS 201 String. String Constants. Characters. Strings(1) Initializing and Declaring String. Debzani Deb

Strings(2) CS 201 String. String Constants. Characters. Strings(1) Initializing and Declaring String. Debzani Deb CS 201 String Debzani Deb Strings(2) Two interpretations of String Arrays whose elements are characters. Pointer pointing to characters. Strings are always terminated with a NULL characters( \0 ). C needs

More information

CS 142 Style Guide Grading and Details

CS 142 Style Guide Grading and Details CS 142 Style Guide Grading and Details In the English language, there are many different ways to convey a message or idea: some ways are acceptable, whereas others are not. Similarly, there are acceptable

More information

CSE 303 Midterm Exam

CSE 303 Midterm Exam CSE 303 Midterm Exam October 29, 2008 Name Sample Solution The exam is closed book, except that you may have a single page of hand written notes for reference. If you don t remember the details of how

More information

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

Data Structure and Algorithm Homework #3 Due: 2:20pm, Tuesday, April 9, 2013 TA   === Homework submission instructions === Data Structure and Algorithm Homework #3 Due: 2:20pm, Tuesday, April 9, 2013 TA email: dsa1@csientuedutw === Homework submission instructions === For Problem 1, submit your source code, a Makefile to compile

More information

Note: The buy help from the TA for points will apply on this exam as well, so please read that carefully.

Note: The buy help from the TA for points will apply on this exam as well, so please read that carefully. CS 215 Spring 2018 Lab Exam 1 Review Material: - All material for the course up through the Arrays I slides - Nothing from the slides on Functions, Array Arguments, or Implementing Functions Format: -

More information

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 The data of the problem is of 2GB and the hard disk is of 1GB capacity, to solve this problem we should Use better data structures

More information

LAB 5 (June 15/20, 2017) Pointers and arrays Due: June 24 (Sat) 11:59 pm.

LAB 5 (June 15/20, 2017) Pointers and arrays Due: June 24 (Sat) 11:59 pm. LAB 5 (June 15/20, 2017) Pointers and arrays Due: June 24 (Sat) 11:59 pm. Following the lectures on pointers, this lab contains three major parts: Part I: Pointers and passing address of scalar variables.

More information

CS113: Lecture 7. Topics: The C Preprocessor. I/O, Streams, Files

CS113: Lecture 7. Topics: The C Preprocessor. I/O, Streams, Files CS113: Lecture 7 Topics: The C Preprocessor I/O, Streams, Files 1 Remember the name: Pre-processor Most commonly used features: #include, #define. Think of the preprocessor as processing the file so as

More information

COP 3223 Final Review

COP 3223 Final Review COP 3223 Final Review Jennifer Brown December 2, 2018 1 Introduction 1.1 Variables I. How can we store data in a program? A. Which of these are valid names for variables? i. 9length ii. hello iii. IamASuperCoolName

More information

Lesson #8. Structures Linked Lists Command Line Arguments

Lesson #8. Structures Linked Lists Command Line Arguments Lesson #8 Structures Linked Lists Command Line Arguments Introduction to Structures Suppose we want to represent an atomic element. It contains multiple features that are of different types. So a single

More information

ECE264 Fall 2013 Exam 1, September 24, 2013

ECE264 Fall 2013 Exam 1, September 24, 2013 ECE264 Fall 2013 Exam 1, September 24, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing it.

More information

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

Here's how you declare a function that returns a pointer to a character: 23 of 40 3/28/2013 10:35 PM Violets are blue Roses are red C has been around, But it is new to you! ANALYSIS: Lines 32 and 33 in main() prompt the user for the desired sort order. The value entered is

More information

More on Arrays CS 16: Solving Problems with Computers I Lecture #13

More on Arrays CS 16: Solving Problems with Computers I Lecture #13 More on Arrays CS 16: Solving Problems with Computers I Lecture #13 Ziad Matni Dept. of Computer Science, UCSB Announcements Homework #12 due today No homework assigned today!! Lab #7 is due on Monday,

More information

QUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below:

QUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below: QUIZ 1. Explain the meaning of the angle brackets in the declaration of v below: This is a template, used for generic programming! QUIZ 2. Why is the vector class called a container? 3. Explain how the

More information

MPATE-GE 2618: C Programming for Music Technology. Unit 4.2

MPATE-GE 2618: C Programming for Music Technology. Unit 4.2 MPATE-GE 2618: C Programming for Music Technology Unit 4.2 Quiz 1 results (out of 25) Mean: 19.9, (standard deviation = 3.9) Equivalent to 79.1% (SD = 15.6) Median: 21.5 High score: 24 Low score: 13 Pointer

More information

CS 1713 Introduction to Programming II

CS 1713 Introduction to Programming II CS 1713 Introduction to Programming II Spring 2014 Midterm 2 -- April 24, 2014 You have 75 min. Good luck. You can use the 2-page C reference card posted in the class web page. Name: Score:./100 Background

More information

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

This exam is worth 24 points, or 24% of your total course grade. The exam contains six CS 60B Final December 14, 1992 Your name login c60b{ Discussion section number TA's name This exam is worth 24 points, or 24% of your total course grade. The exam contains six questions. This booklet contains

More information

CS 342 Software Design Spring 2018 Term Project Part III Saving and Restoring Exams and Exam Components

CS 342 Software Design Spring 2018 Term Project Part III Saving and Restoring Exams and Exam Components CS 342 Software Design Spring 2018 Term Project Part III Saving and Restoring Exams and Exam Components Due: Wednesday 13 March. Electronic copy due at 3:30 P.M. Optional paper copy may be handed in during

More information

COP 3223 Final Review

COP 3223 Final Review COP 3223 Final Review Jennifer Brown December 2, 2018 1 Introduction 1.1 Variables I. How can we store data in a program? Initializing variables with data types A. Which of these are valid names for variables?

More information

CS 220: Introduction to Parallel Computing. Input/Output. Lecture 7

CS 220: Introduction to Parallel Computing. Input/Output. Lecture 7 CS 220: Introduction to Parallel Computing Input/Output Lecture 7 Input/Output Most useful programs will provide some type of input or output Thus far, we ve prompted the user to enter their input directly

More information

Computer Science Foundation Exam

Computer Science Foundation Exam Computer Science Foundation Exam December 18, 015 Section I B COMPUTER SCIENCE NO books, notes, or calculators may be used, and you must work entirely on your own. SOLUTION Question # Max Pts Category

More information

Lecture 19 CSE August You taught me Language, and my profit on t is I know how to curse. William Shakspere, The Tempest, I, ii.

Lecture 19 CSE August You taught me Language, and my profit on t is I know how to curse. William Shakspere, The Tempest, I, ii. Lecture 19 CSE 110 5 August 1992 You taught me Language, and my profit on t is I know how to curse. William Shakspere, The Tempest, I, ii. 1 Left-Over Language Features Today was the day we saw the last

More information

Memory Corruption 101 From Primitives to Exploit

Memory Corruption 101 From Primitives to Exploit Memory Corruption 101 From Primitives to Exploit Created by Nick Walker @ MWR Infosecurity / @tel0seh What is it? A result of Undefined Behaviour Undefined Behaviour A result of executing computer code

More information

by Pearson Education, Inc. All Rights Reserved.

by Pearson Education, Inc. All Rights Reserved. Let s improve the bubble sort program of Fig. 6.15 to use two functions bubblesort and swap. Function bubblesort sorts the array. It calls function swap (line 51) to exchange the array elements array[j]

More information

C++ for Java Programmers

C++ for Java Programmers Basics all Finished! Everything we have covered so far: Lecture 5 Operators Variables Arrays Null Terminated Strings Structs Functions 1 2 45 mins of pure fun Introduction Today: Pointers Pointers Even

More information

CS 1713 Introduction to Programming II

CS 1713 Introduction to Programming II CS 1713 Introduction to Programming II Spring 2014 Midterm 2 -- April 24, 2014 You have 75 min. Good luck. You can use the 2-page C reference card posted in the class web page. Name: Score:./100 Background

More information

CS 470 Operating Systems Spring 2013 Shell Project

CS 470 Operating Systems Spring 2013 Shell Project CS 470 Operating Systems Spring 2013 Shell Project 40 points Out: January 11, 2013 Due: January 25, 2012 (Friday) The purpose of this project is provide experience with process manipulation and signal

More information

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

gcc o driver std=c99 -Wall driver.c everynth.c C Programming The Basics This assignment consists of two parts. The first part focuses on implementing logical decisions and integer computations in C, using a C function, and also introduces some examples

More information

CS 315 Data Structures mid-term 2

CS 315 Data Structures mid-term 2 CS 315 Data Structures mid-term 2 1) Shown below is an AVL tree T. Nov 14, 2012 Solutions to OPEN BOOK section. (a) Suggest a key whose insertion does not require any rotation. 18 (b) Suggest a key, if

More information

Arrays and functions Multidimensional arrays Sorting and algorithm efficiency

Arrays and functions Multidimensional arrays Sorting and algorithm efficiency Introduction Fundamentals Declaring arrays Indexing arrays Initializing arrays Arrays and functions Multidimensional arrays Sorting and algorithm efficiency An array is a sequence of values of the same

More information

Sorting Algorithms. + Analysis of the Sorting Algorithms

Sorting Algorithms. + Analysis of the Sorting Algorithms Sorting Algorithms + Analysis of the Sorting Algorithms Insertion Sort What if first k elements of array are already sorted? 4, 7, 12, 5, 19, 16 We can shift the tail of the sorted elements list down and

More information

CS16 Midterm Exam 2 E02, 09F, Phill Conrad, UC Santa Barbara Wednesday, 11/18/2009

CS16 Midterm Exam 2 E02, 09F, Phill Conrad, UC Santa Barbara Wednesday, 11/18/2009 CS16 Midterm Exam 2 E02, 09F, Phill Conrad, UC Santa Barbara Wednesday, 11/18/2009 Name: Umail Address: @ umail.ucsb.edu Circle Lab section: 8AM 10AM 11AM noon Link to Printer Friendly PDF Version Answer

More information

QUIZ How do we implement run-time constants and. compile-time constants inside classes?

QUIZ How do we implement run-time constants and. compile-time constants inside classes? QUIZ How do we implement run-time constants and compile-time constants inside classes? Compile-time constants in classes The static keyword inside a class means there s only one instance, regardless of

More information

Programming for Engineers Arrays

Programming for Engineers Arrays Programming for Engineers Arrays ICEN 200 Spring 2018 Prof. Dola Saha 1 Array Ø Arrays are data structures consisting of related data items of the same type. Ø A group of contiguous memory locations that

More information

COMP 321: Introduction to Computer Systems

COMP 321: Introduction to Computer Systems Assigned: 1/18/18, Due: 2/1/18, 11:55 PM Important: This project must be done individually. Be sure to carefully read the course policies for assignments (including the honor code policy) on the assignments

More information

CSE 2320 Section 002, Fall 2015 Exam 2 Time: 80 mins

CSE 2320 Section 002, Fall 2015 Exam 2 Time: 80 mins CSE 2320 Section 002, Fall 201 Exam 2 Time: 80 mins Name:. Student ID:. Total exam points: 100. Question Points Out of 1 24 2 10 3 10 4 18 6 1 16 Total 100 If you have the smallest doubt about what a question

More information

Week 5, continued. This is CS50. Harvard University. Fall Cheng Gong

Week 5, continued. This is CS50. Harvard University. Fall Cheng Gong This is CS50. Harvard University. Fall 2014. Cheng Gong Table of Contents News... 1 Buffer Overflow... 1 Malloc... 6 Linked Lists... 7 Searching... 13 Inserting... 16 Removing... 19 News Good news everyone!

More information

ENGR 3950U / CSCI 3020U (Operating Systems) Simulated UNIX File System Project Instructor: Dr. Kamran Sartipi

ENGR 3950U / CSCI 3020U (Operating Systems) Simulated UNIX File System Project Instructor: Dr. Kamran Sartipi ENGR 3950U / CSCI 3020U (Operating Systems) Simulated UNIX File System Project Instructor: Dr. Kamran Sartipi Your project is to implement a simple file system using C language. The final version of your

More information

8*4 + 4 = 36 each int is 4 bytes

8*4 + 4 = 36 each int is 4 bytes CS 61CL (Clancy) Solutions and grading standards for exam 1 Spring 2009 169 students took the exam. The average score was 43.6; the median was 46. Scores ranged from 1 to 59. There were 89 scores between

More information

Solved by: Syed Zain Ali Bukhari (BSCS)

Solved by: Syed Zain Ali Bukhari (BSCS) Solved by: Syed Zain Ali Bukhari (BSCS) 1. If there are N internal nodes in a binary tree then what will be the no. of external nodes in this binary tree? N -1 N N +1 (Page 303) N +2 2.If there are N elements

More information

Student Name: (in Capital Letters) CSE Introduction to Programming for Engineers and Scientists. Final Exam

Student Name: (in Capital Letters) CSE Introduction to Programming for Engineers and Scientists. Final Exam Student Name: (in Capital Letters) CSE 1311 Introduction to Programming for Engineers and Scientists Final Exam Fall 2013 1 1. If count is a properly defined integer variable, the following piece of code:

More information

CS 322 Operating Systems Programming Assignment 2 Using malloc and free Due: February 15, 11:30 PM

CS 322 Operating Systems Programming Assignment 2 Using malloc and free Due: February 15, 11:30 PM CS 322 Operating Systems Programming Assignment 2 Using malloc and free Due: February 15, 11:30 PM Goals To get more experience programming in C To learn how to use malloc and free To lean how to use valgrind

More information

EECE.2160: ECE Application Programming

EECE.2160: ECE Application Programming Fall 2017 Programming Assignment #10: Doubly-Linked Lists Due Monday, 12/18/17, 11:59:59 PM (Extra credit ( 5 pts on final average), no late submissions or resubmissions) 1. Introduction This assignment

More information

QUIZ. 0] Define arrays 1] Define records 2] How are arrays and records: (a) similar? (b) different?

QUIZ. 0] Define arrays 1] Define records 2] How are arrays and records: (a) similar? (b) different? QUIZ 0] Define arrays 1] Define records 2] How are arrays and records: (a) similar? (b) different? 1 QUIZ 3] What are the 4 fundamental types of algorithms used to manipulate arrays? 4] What control structure

More information

15 FUNCTIONS IN C 15.1 INTRODUCTION

15 FUNCTIONS IN C 15.1 INTRODUCTION 15 FUNCTIONS IN C 15.1 INTRODUCTION In the earlier lessons we have already seen that C supports the use of library functions, which are used to carry out a number of commonly used operations or calculations.

More information

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9 Fundamental of C Programming Unit I: Q1. What will be the value of the following expression? (2017) A + 9 Q2. Write down the C statement to calculate percentage where three subjects English, hindi, maths

More information

ECE242 Data Structures and Algorithms Fall 2008

ECE242 Data Structures and Algorithms Fall 2008 ECE242 Data Structures and Algorithms Fall 2008 2 nd Midterm Examination (120 Minutes, closed book) Name: Student ID: Question 1 (10) 2 (20) 3 (25) 4 (10) 5 (15) 6 (20) Score NOTE: Any questions on writing

More information

CSE 143 Final Exam Part 1 - August 18, 2011, 9:40 am

CSE 143 Final Exam Part 1 - August 18, 2011, 9:40 am CSE 143 Final Exam Part 1 - August 18, 2011, 9:40 am Name Student ID # Section TA Name The exam is closed book, closed notes, closed devices, except that you may have a 5x8 card with handwritten notes

More information

Binary Search Tree 1.0. Generated by Doxygen Mon Jun :12:39

Binary Search Tree 1.0. Generated by Doxygen Mon Jun :12:39 Binary Search Tree 1.0 Generated by Doxygen 1.7.1 Mon Jun 6 2011 16:12:39 Contents 1 Binary Search Tree Program 1 1.1 Introduction.......................................... 1 2 Data Structure Index 3

More information

CS 104 (Spring 2014) Final Exam 05/09/2014

CS 104 (Spring 2014) Final Exam 05/09/2014 CS 104 (Spring 2014) Final Exam 05/09/2014 G o o d L u c k Your Name, USC username, and Student ID: This exam has 8 pages and 8 questions. If yours does not, please contact us immediately. Please read

More information

1 P a g e A r y a n C o l l e g e \ B S c _ I T \ C \

1 P a g e A r y a n C o l l e g e \ B S c _ I T \ C \ BSc IT C Programming (2013-2017) Unit I Q1. What do you understand by type conversion? (2013) Q2. Why we need different data types? (2013) Q3 What is the output of the following (2013) main() Printf( %d,

More information

Linked Lists CS 16: Solving Problems with Computers I Lecture #16

Linked Lists CS 16: Solving Problems with Computers I Lecture #16 Linked Lists CS 16: Solving Problems with Computers I Lecture #16 Ziad Matni Dept. of Computer Science, UCSB Material: Everything we ve done Homework, Labs, Lectures, Textbook Tuesday, 12/12 in this classroom

More information

Out: April 19, 2017 Due: April 26, 2017 (Wednesday, Reading/Study Day, no late work accepted after Friday)

Out: April 19, 2017 Due: April 26, 2017 (Wednesday, Reading/Study Day, no late work accepted after Friday) CS 215 Fundamentals of Programming II Spring 2017 Programming Project 7 30 points Out: April 19, 2017 Due: April 26, 2017 (Wednesday, Reading/Study Day, no late work accepted after Friday) This project

More information

QUIZ: What value is stored in a after this

QUIZ: What value is stored in a after this QUIZ: What value is stored in a after this statement is executed? Why? a = 23/7; QUIZ evaluates to 16. Lesson 4 Statements, Expressions, Operators Statement = complete instruction that directs the computer

More information

Unit 3 Fill Series, Functions, Sorting

Unit 3 Fill Series, Functions, Sorting Unit 3 Fill Series, Functions, Sorting Fill enter repetitive values or formulas in an indicated direction Using the Fill command is much faster than using copy and paste you can do entire operation in

More information

put your answers to b and c in human-oriented terms.

put your answers to b and c in human-oriented terms. 2. A. A person object has a social security number, a name, and a phone number. Give a complete C++ implementation of quicksort or mergesort that will sort an array of N pointers to person objects so that

More information

Unit 3 Functions Review, Fill Series, Sorting, Merge & Center

Unit 3 Functions Review, Fill Series, Sorting, Merge & Center Unit 3 Functions Review, Fill Series, Sorting, Merge & Center Function built-in formula that performs simple or complex calculations automatically names a function instead of using operators (+, -, *,

More information

CS 137 Part 8. Merge Sort, Quick Sort, Binary Search. November 20th, 2017

CS 137 Part 8. Merge Sort, Quick Sort, Binary Search. November 20th, 2017 CS 137 Part 8 Merge Sort, Quick Sort, Binary Search November 20th, 2017 This Week We re going to see two more complicated sorting algorithms that will be our first introduction to O(n log n) sorting algorithms.

More information

CS201 Some Important Definitions

CS201 Some Important Definitions CS201 Some Important Definitions For Viva Preparation 1. What is a program? A program is a precise sequence of steps to solve a particular problem. 2. What is a class? We write a C++ program using data

More information

Organization of a file

Organization of a file File Handling 1 Storage seen so far All variables stored in memory Problem: the contents of memory are wiped out when the computer is powered off Example: Consider keeping students records 100 students

More information

Heap Arrays. Steven R. Bagley

Heap Arrays. Steven R. Bagley Heap Arrays Steven R. Bagley Recap Data is stored in variables Can be accessed by the variable name Or in an array, accessed by name and index a[42] = 35; Variables and arrays have a type int, char, double,

More information

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary GATE- 2016-17 Postal Correspondence 1 C-Programming Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key concepts, Analysis

More information

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I- 2 MARKS

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I- 2 MARKS DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I- 2 MARKS 1. Define global declaration? The variables that are used in more

More information

INDIAN SCHOOL MUSCAT COMPUTER SCIENCE(083) CLASS XI

INDIAN SCHOOL MUSCAT COMPUTER SCIENCE(083) CLASS XI INDIAN SCHOOL MUSCAT COMPUTER SCIENCE(083) CLASS XI 2017-2018 Worksheet No. 1 Topic : Getting Started With C++ 1. Write a program to generate the following output: Year Profit% 2011 18 2012 27 2013 32

More information

CpSc 1010, Fall 2014 Lab 10: Command-Line Parameters (Week of 10/27/2014)

CpSc 1010, Fall 2014 Lab 10: Command-Line Parameters (Week of 10/27/2014) CpSc 1010, Fall 2014 Lab 10: Command-Line Parameters (Week of 10/27/2014) Goals Demonstrate proficiency in the use of the switch construct and in processing parameter data passed to a program via the command

More information

ch = argv[i][++j]; /* why does ++j but j++ does not? */

ch = argv[i][++j]; /* why does ++j but j++ does not? */ CMPS 12M Introduction to Data Structures Lab Lab Assignment 4 The purpose of this lab assignment is to get more practice programming in C, including the character functions in the library ctype.h, and

More information

COMP26120 Academic Session: Lab Exercise 6: Recursive Sorting and Searching

COMP26120 Academic Session: Lab Exercise 6: Recursive Sorting and Searching COMP26120 Academic Session: 2018-19 Lab Exercise 6: Recursive Sorting and Searching Duration: 1 lab session For this lab exercise you should do all your work in your COMP26120/ex6 directory. Learning Objectives

More information

CS 215 Fundamentals of Programming II Fall 2017 Project 7. Morse Code. 30 points. Out: November 20, 2017 Due: December 4, 2017 (Monday) a n m

CS 215 Fundamentals of Programming II Fall 2017 Project 7. Morse Code. 30 points. Out: November 20, 2017 Due: December 4, 2017 (Monday) a n m CS 215 Fundamentals of Programming II Fall 2017 Project 7 30 points Out: November 20, 2017 Due: December 4, 2017 (Monday) This project is to build a Morse code tree and use it to encode and decode messages.

More information

UNIT IV-2. The I/O library functions can be classified into two broad categories:

UNIT IV-2. The I/O library functions can be classified into two broad categories: UNIT IV-2 6.0 INTRODUCTION Reading, processing and writing of data are the three essential functions of a computer program. Most programs take some data as input and display the processed data, often known

More information

SAMPLE OF THE STUDY MATERIAL PART OF CHAPTER 6. Sorting Algorithms

SAMPLE OF THE STUDY MATERIAL PART OF CHAPTER 6. Sorting Algorithms SAMPLE OF THE STUDY MATERIAL PART OF CHAPTER 6 6.0 Introduction Sorting algorithms used in computer science are often classified by: Computational complexity (worst, average and best behavior) of element

More information

Ch 6-2. File Input / Output

Ch 6-2. File Input / Output 2014-1 Ch 6-2. File Input / Output March 30, 2014 Advanced Networking Technology Lab. (YU-ANTL) Dept. of Information & Comm. Eng, Graduate School, Yeungnam University, KOREA (Tel : +82-53-810-2497; Fax

More information

IS 709/809: Computational Methods in IS Research. Algorithm Analysis (Sorting)

IS 709/809: Computational Methods in IS Research. Algorithm Analysis (Sorting) IS 709/809: Computational Methods in IS Research Algorithm Analysis (Sorting) Nirmalya Roy Department of Information Systems University of Maryland Baltimore County www.umbc.edu Sorting Problem Given an

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information

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

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved. C How to Program, 6/e 1992-2010 by Pearson Education, Inc. 1992-2010 by Pearson Education, Inc. 1992-2010 by Pearson Education, Inc. This chapter serves as an introduction to the important topic of data

More information

Second Examination Solution

Second Examination Solution University of Illinois at Urbana-Champaign Department of Computer Science Second Examination Solution CS 225 Data Structures and Software Principles Fall 2007 7p-9p, Thursday, November 8 Name: NetID: Lab

More information

CS 455 Final Exam Spring 2018 [Bono] May 8, 2018

CS 455 Final Exam Spring 2018 [Bono] May 8, 2018 Name: USC NetID (e.g., ttrojan): CS 455 Final Exam Spring 2018 [Bono] May 8, 2018 There are 9 problems on the exam, with 74 points total available. There are 12 pages to the exam (6 pages double-sided),

More information

Ch. 12: Operator Overloading

Ch. 12: Operator Overloading Ch. 12: Operator Overloading Operator overloading is just syntactic sugar, i.e. another way to make a function call: shift_left(42, 3); 42

More information

Project 1: Scheme Pretty-Printer

Project 1: Scheme Pretty-Printer Project 1: Scheme Pretty-Printer CSC 4101, Fall 2017 Due: 7 October 2017 For this programming assignment, you will implement a pretty-printer for a subset of Scheme in either C++ or Java. The code should

More information

UNIT III BALANCED SEARCH TREES AND INDEXING

UNIT III BALANCED SEARCH TREES AND INDEXING UNIT III BALANCED SEARCH TREES AND INDEXING OBJECTIVE The implementation of hash tables is frequently called hashing. Hashing is a technique used for performing insertions, deletions and finds in constant

More information

Review of the Lectures 21-26, 30-32

Review of the Lectures 21-26, 30-32 Review of the Lectures 21-26, 30-32 1 The Final Exam Monday 11 December, BSB 337, from 8AM to 10AM 2 Examples of Questions recursion and memoization enumeration trees, binary search trees, Huffman codes

More information

ECE264 Spring 2013 Exam 1, February 14, 2013

ECE264 Spring 2013 Exam 1, February 14, 2013 ECE264 Spring 2013 Exam 1, February 14, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing it.

More information

Recitation 2/18/2012

Recitation 2/18/2012 15-213 Recitation 2/18/2012 Announcements Buflab due tomorrow Cachelab out tomorrow Any questions? Outline Cachelab preview Useful C functions for cachelab Cachelab Part 1: you have to create a cache simulator

More information

CS 610: Intermediate Programming: C/C++ Making Programs General An Introduction to Linked Lists

CS 610: Intermediate Programming: C/C++ Making Programs General An Introduction to Linked Lists ... 1/17 CS 610: Intermediate Programming: C/C++ Making Programs General An Introduction to Linked Lists Alice E. Fischer Spring 2016 ... 2/17 Outline Generic Functions Command Line Arguments Review for

More information

EECE.2160: ECE Application Programming

EECE.2160: ECE Application Programming Summer 2017 Programming Assignment #9: Doubly-Linked Lists Due Monday, 6/26/17, 11:59:59 PM (+15% if submitted by 6/23, +10% if submitted 6/24-6/25, +5% if submitted 6/26) 1. Introduction This assignment

More information

What is sorting? Lecture 36: How can computation sort data in order for you? Why is sorting important? What is sorting? 11/30/10

What is sorting? Lecture 36: How can computation sort data in order for you? Why is sorting important? What is sorting? 11/30/10 // CS Introduction to Computation " UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department Professor Andrea Arpaci-Dusseau Fall Lecture : How can computation sort data in order for you? What is sorting?

More information