Managing dynamic arrays and grade management

Assignment Help Programming Languages
Reference no: EM131270520

Assignment: Object Oriented Programming

1 Managing Dynamic Arrays

Managing dynamically sized arrays can be a pain while dealing with memory on the heap. Memory leaks, dangling pointers, etc can lead to invalid memory accesses/segmentation faults that halt your program abruptly. Your task is to design a DataVector class that encapsulates the implementation of a dynamically sized double array. The interface should be such that the users of your class should not be exposed to the underlying implementation details such as memory allocation (new), release (delete), resize, etc. Your DataVector class must have the following public interface. The di_culty levels are marked as L1, L2 and L3, going from easy to hard.

1. DataVector ( ) ; //L2

This is the default constructor with no parameters. By default, this allocates space for a double array of size 10 and assigns a default value of 0 to each of them.

2. DataVector ( unsignedint i n i t S i z e , double i ni t Va l ue ) ; //L2

This is another constructor of the class that takes in arguments and allocates space for a double array of size initSize and assigns a default value of initValue to each of them.

3. DataVector ( ) ; //L2

This is the destructor that does any cleanup necessary such as releasing all the memory on the heap using the delete operator.

4. void Pr i nt I t e ms ( ) ; //L2

This prints all the items in a single line and successive items are separated by a single space. After the last item there should be a space and a newline character.

5. unsignedint Get Si ze ( ) ; //L1

This should return the current size of the double array.

6. void Res er ve ( unsignedint newSi ze ) ; //L3

This function should increase the size of the array to newSize. Note that you would have to allocate a fresh double array, to which you will have to copy the items from the old double array, and then release the memory for the old double array. If newSize is less than the old size, then you copy just the _rst newSize items from the old array. If newSize is greater than the old size, then you copy all items from the old array.

7. double GetItemAt ( unsignedint i ndex ) ; //L1

This returns the item at the speci_ed index. Assume index is in the range 0 to GetSize() - 1.

8. void SetItemAt ( unsignedint i ndex , double val ) ; //L1

This sets the item at the speci_ed index to val. Assume index is in the range 0 to GetSize() - 1.

9. double GetSum( ) ; //L2

This returns the sum of all items.

Note that you must use new and delete to manage the double array internally. All pointers, counters, etc for the array bookkeeping must be made private in your class.

2 Grade Management

Now you will apply your DataVector class to manage the student grades of CS31. You will implement a GradeManager class that internally uses an array of DataVector objects, that were created dynamically using the new operator, to record the homework grades for a set of students. Again, the idea is to encapsulate the underlying implementation such that the user of GradeManager will not know that DataVector is being used internally. Your GradeManager class must have the following public interface:

1. GradeManager ( unsignedint nStudents , unsignedint nHWs ) ; //L3

This is the only constructor of the class, and it speci_es the number of students nStudents and number of homeworks nHWs for the class. You should use these to dynamically set the array sizes. Also, if nStudents is 100 then the student IDs will range from 0 to 99. Similarly, if nHWs is 10 then the homework IDs will range from 0 to 9.

2. GradeManager ( ) ; //L2

This is the destructor that does any cleanup necessary such as releasing all the memory on the heap using the delete operator.

3. void Pr i nt Gr ades ( ) ; //L2

This prints all the homework grades for all students. Each student's grades are printed on a separate line, and the successive homework grades of each student are separated by a single space. After the last grade on a line, there should be a space and a newline character.

4. unsignedint Ge t Cl as s Si z e ( ) ; //L1

Returns the number of students.

5. unsignedint GetHWCount ( ) ; //L1

Returns the number of homeworks.

6. void SetGrade ( unsignedint sID , unsignedint hwID , double val ) ; //L2

This sets the grade of student sID to val for the homework hwID.

7. double GetGrade ( unsignedint sID , unsignedint hwID) ; //L2

This returns the grade of student sID for the homework hwID.

8. double Get Tot al Scor eFor St udent ( unsignedint sID ) ; //L2

This returns the sum of the respective student's scores on all homeworks.

9. double GetTotal ScoreForStudentWi thDrop2Least ( unsignedint sID ) ; //L3

This returns the sum of the respective student's scores on all homeworks except the least 2 homeworks. Henceforth, this is referred to as the Drop2 policy.

10. unsignedint GetBestStudent ( ) ; //L2

This returns the sID of the student who has the best total score across homeworks with the Drop2 policy.

11. unsignedint GetNumStudentsInRange ( double low , double hi gh ) ; //L3

This returns the number of students whose total homework scores (with Drop2 policy) lie in the range low <= totalscore < high. (Including low and excluding high).

12. double GetCl assAverage ( ) ; //L2

This returns the average of the total homework scores (with Drop2 policy), across all students.

13. double GetClassSTD ( ) ; //L2

This returns the population standard deviation of the total homework scores (with Drop2 policy), across all students. The standard deviation of a set of n total scores t whose average is m, is given by,

You can use the standard library sqrt() function from cmath header to _nd the square root.

3 Dos/Donts/General Advice

1. All your code should be written inside the two classes DataVector and GradeManager.

It is recommended that you do not modify anything outside these classes (main() function especially). But if you really want to write your own test cases in the main() function, then it is your responsibility to revert those changes before submitting on the server.

2. A set of basic tests that call into the public inferface on the 2 classes is given to you in the main() function. These tests might not be complete, and if your output matches the output given at the end of this document, then it does not necessarily mean that you will get full credit on the assignment. We will be designing new test cases for grading purposes, and hence, it is your responsibility to make sure the implementation works as expected. Nevertheless, these tests may give you some ideas on how to use the public interface.

3. It is recommended to start implementing the easy functions _rst. You can also follow the order listed above. This order will help you build the class one step at the time, and some of the earlier functions can be called/reused in later functions if needed.

4. Reusability is one of the main objectives of Object Oriented Programming. So, feel free to reuse any function/code you might have already written.

5. You might run into Segmentation Faults (a.k.a SIGSEGV on unix systems), or Invalid memory access/Bad access or Protection faults, or any kind of memory corruption issues. If you do, then the following checks might help.

_ Check if your indexes to the dynamically allocated arrays are within the legal range. For example, if you allocated a 10 element double array using the syntax new double[10], then make sure your index values to this array are in the range 0 9.

_ Check if you have any dangling pointers. These are pointers that hold addresses to memory that have already been released using the delete operator. It is usually a good practice to set your pointer to NULL after you have called delete on it. For example, delete [ ] pt r ;

_ Check if you are dereferencing a NULL pointer.

Reference no: EM131270520

Questions Cloud

Determine the heat transfer through the turbine casing : The steam is discharged in a dry saturated condition at 20 kPa at a velocity of 60 m/s. Determine the heat transfer through the turbine casing.
The demand for international reserves : 1. Analyze the following statement: "The demand for international reserves tend to increase with the level of world income and trade activity." Your response should be at least 100 words in length.
Determine the outlet temperature : The power delivered by the turbine is 280 kW. The inlet area is 62.5 cm2. Determine the outlet temperature.
Market fail in the presence of an externality : It is possible for an activity to have both positive and negative externality. Identify three activities that result in both positive and negative externality and carefully explain the positive and negative externality that results.
Managing dynamic arrays and grade management : Managing Dynamic Arrays and Grade Management- Managing dynamically sized arrays can be a pain while dealing with memory on heap. Memory leaks, dangling pointers, etc can lead to invalid memory accesses/segmentation faults that halt your program ab..
Determine the condition of the outlet steam : Potential and kinetic energy changes are negligible. Determine the condition of the outlet steam by giving either a temperature or a quality
What is continental drift : What is continental drift? What was Alfred Wegener's hypothesis for continental drift, and why was his idea not accepted? Explain the evidence collected in the last.
Develop a demonstration prototype system : ISY103 - Database Management for Business Individual Project: Database Case Study. Using MySQL, you are required to develop a demonstration prototype system that handles hotel bookings and payments. Use MySQL to create a new database called HMS
What are the fundamental flaws of given thinking : After the deal was signed, many Finnish companies expected that contracts and money would start rolling in by merely calling up McDonnell Douglas.- What are the fundamental flaws of given thinking?

Reviews

Write a Review

Programming Languages Questions & Answers

  What are the consequences of not citing computer programs

Review the document on code citation and documentation guidelines in the Course Materials section of your student Web site and the Avoiding Plagiarism tutorial available on your student Web site. Discuss the issues of proper citation as they apply..

  Which intelligent network agent used to make a custom search

Businesses that succeed in their markets but that earn lower profits than their competitors would appear at what point on Porter's Curve?

  Binary search algorithm to search an array

The binary search algorithm that follows may be used to search array when elements are in order. This algorithm is analogous to following approach for finding name in telephone book.

  Use of various bash commands

Assignment On: This work will require scripting the use of various bash commands and / or small programs that involve directory and file structures.

  Design a system for the organization

explain the main systems in place, discuss the integration, and explain how the data collected by these systems helps the organization make decisions and carry out the strategic plan.

  Write down a program which asks the user for an angle

write a program that asks the user for an angle entered in radians. the program should then display the sine cosine and

  Design logic for application for company to store breakdown

Design the logic for an application for a company that wants a report containing a breakdown of payroll by department. Input includes each employee's last name.

  Write program that asks user for initial

Write a program that asks a user for his/her first initial. Then ask the user to type 1,2 3, 4. When the user types 4 the program ends. When the user types in 1, 2, or 3 , the program displays the message.

  Create two global varibles to declare an empty array

Need to create two global varibles. The first currentTab, which will reference the current menu tab being dispalyed with a initial value of null, the second variable is maxZ which will store the z-index and it's initial value is 1.

  Program that checks whether two given strings are circular

Detecting this condition is important in the study of genomic sequences. Write a program that checks whether two given strings s and t are circular

  London underground fire at the kings cross underground

london underground fire at the kings cross underground station on 18 november 1987 a wooden escalator caught fire

  Write a program that display amount of discount on item

Write a program that asks the user to enter number of packages purchased. Program must then display amount of the discount (if any) and total amount of the purchase after the discount.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd