Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Programming Language Expert

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.

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M92025250
  • Price:- $45

Priced at Now at $45, Verified Solution

Have any Question?


Related Questions in Programming Language

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

Background informationthis assignment tests your

Background Information This assignment tests your understanding of and ability to apply the programming concepts we have covered throughout the unit. The concepts covered in the second half of the unit build upon the fun ...

Question 1 what is hadoop explaining hadoop 2 what is

Question: 1. What is Hadoop (Explaining Hadoop) ? 2. What is HDFS? 3. What is YARN (Yet Another Resource Negotiator)? The response must be typed, single spaced, must be in times new roman font (size 12) and must follow t ...

Task silly name testeroverviewcontrol flow allows us to

Task: Silly Name Tester Overview Control flow allows us to alter the order in which our programs execute. Building on our knowledge of variables, we can now use control flow to create programs that perform more than just ...

Task arrays and structsoverviewin this task you will

Task: Arrays and Structs Overview In this task you will continue to work on the knight database to help Camelot keep track of all of their knights. We can now add a kingdom struct to help work with and manage all of the ...

1 write a function named check that has three parameters

1. Write a function named check () that has three parameters. The first parameter should accept an integer number, andthe second and third parameters should accept a double-precision number. The function body should just ...

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

Task - hand execution of arraysoverviewin this task you

Task - Hand Execution of Arrays Overview In this task you will demonstrate how arrays work by hand executing a number of small code snippets. Instructions Watch the Hand Execution with Arrays video, this shows how to ste ...

Assignment - haskell program for regular expression

Assignment - Haskell Program for Regular Expression Matching Your assignment is to modify the slowgrep.hs Haskell program presented in class and the online notes, according to the instructions below. You may carry out th ...

Question - create a microsoft word macro using vba visual

Question - Create a Microsoft Word macro using VBA (Visual Basic for Applications). Name the macro "highlight." The macro should highlight every third line of text in a document. (Imagine creating highlighting that will ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As