Question

REQUIREMENTS: Problem Description: Create a Dynamic 2D Array Class. This class should overload the Call Operator...

REQUIREMENTS: Problem Description: Create a Dynamic 2D Array Class. This class should overload the Call Operator () for the following behaviors:

Return (modifiable) Lvalue element for a non-const object

Return (read-only) Rvalue element for a const object

Return a copy of the data values for row

Return a copy of all the data as a 1D vector

Create a TestScores Class which uses a Dynamic 2D Array object as an internal data structure. This class should have the following behaviors:

Get the scores for a given student

Get the average score for a given student

Get the class average

Get the Standard Deviation for the class

Create a BandPassFilter which allow only scores within One-Sigma to pass through.

Answer the questions:

How many scores passed through?

What percentage is this?

How does this compare to a Normal Distribution?

Demonstrate your classes with a TestScores Object which has 15 students with five(5) test scores each. Generate scores between 45 and 100 using a Random Generator. Document your code, tell me what you are doing, and make it readable.

C++ ONLY PLEASE

0 0
Add a comment Improve this question Transcribed image text
Answer #1

IF YOU HAVE ANY DOUBTS COMMENT BELOW I WILL BE THERE TO HELP YOU

ANSWER:

CODE:

/*************************************************

* The objective of the program code is to create *

* a TestScores which uses a 2D dynamic array     *

* class as internal data structure. Demonstrate *

* classes with a TestScores Object.              *

*************************************************/

//use this header file

//only for visual studio

#include "stdafx.h"

//define the header section

#include<iostream>

#include<fstream>

#include<string>

#include<iomanip>

//Run with student data file as input

using namespace std;

const int maxvalue = 100;

//define the function called dataInput

//to read the data in array format

//and to store the data in array format.

void dataInput(ifstream &inputfile, string nm[], int marks[][5], int &k)

{

     //define the necessary variables

     k = 0;

     int m = 0;

     int n = 0;

     //check for the input file

     while (!inputfile.eof())

     {

          inputfile >> nm[m];

          for (int j = 0; j<5; j++)

              inputfile >> marks[m][j];

          m++;

     }

     k = m;

}

//define the function checkGrade

//to check for the grades

char checkGrade(double average)

{

     //check for the grades

     if (average >= 90 && average <= 100)

          return 'A';

     else if (average >= 80 && average <= 89)

          return 'B';

     if (average >= 70 && average <= 79)

          return 'C';

     if (average >= 60 && average <= 69)

          return 'D';

     if (average >= 50 && average <= 59)

          return 'F';

}

//define the function called CalculateAverage

//that calculates the marks of the students

//and the student's grade

void CalculateAverage(int i[][5], char grad[], double average[], int studentsCount)

{

     //use for() loop to calculate

     //the grade for the students

     for (int m = 0; m<studentsCount; m++)

     {

          double total = 0;

          for (int n = 0; n<5; n++)

              total += i[m][n];

          average[m] = total / static_cast<double> (5);

          grad[m] = checkGrade(average[m]);

     }

}

//define the function called AverageresultPrint

//to display the results in the particular format.

void AverageresultPrint(string nm[], double average[], int marks[][5], char grad[], int k)

{

     for (int m = 0; m<k; m++)

     {

          cout << left << setw(10) << nm[m];

          for (int k = 0; k<5; k++)

              cout << right << setw(8) << marks[m][k];

          cout << endl;

     }

     //define the average for the student

     cout << setw(8) << "Average: ";

     for (int n = 0; n<k; n++)

          cout << setw(5) << average[n];

     cout << endl;

}

//define the main() function

int main()

{

     //define the one-dimensional array

     //to store the names of the students

     string nm[maxvalue];

     //define the parallel two-dimensional array

     //to store the scores of the test

     int marks[maxvalue][5];

     //define the parallel one-dimensional array

     //to store the grade results

     char grad[maxvalue];

     int studentsCount;

     double average[maxvalue];

     //Read the input file

     ifstream infile("StudentData.txt");

     //check if the file exists or not

     if (!infile)

     {

          cout << "Return error, exit from the program: unable to open file" << endl;

          return 0;

     }

    

     //call the functions

     dataInput(infile, nm, marks, studentsCount);

     infile.close();

     CalculateAverage(marks, grad, average, studentsCount);

     AverageresultPrint(nm, average, marks, grad, studentsCount);

    

     //pause the system for a while

     system("pause");

     //return nothing

     return 0;

}

Programmatic insertion:

To create a dynamic 2D array class, first need to declare a 2D array:

a = [][]

for i in range(3) :

     for j in range(3) :

          a[i][j] = i + j

print a

To append values into the lists,

a = []

for i in xrange(2) :

     a.append([])

     for j in xrange(2) :

          a[i].append(i + j)

a[[0, 1, 2], [1, 2, 3]]

it will be done as given above.

Points to remember:

  • create a dynamic array of pointers
  • create a row for every pointer (Note: rows may not be contiguous)
  • initialize all entries as false to indicate that there are no edges initially

Utility method to print adjacency matrix is written below:

void Graph::print()

{

     For(int u = 0; u<V; u++)

     {

          for (int v = 0; v<V; v++)

              cout << adj[u][v] << " ";

          cout << endl;

     }

}

Output:

0 1 1 0

0 0 1 0

1 0 0 1

0 0 0 1

Note: memset() is actually used separately for individual rows. As the rows are allocated at different addresses, it can’t replace these calls with one call and making a memset() call like below would be disastrous.

memset (adj, false , V*V*sizeof (bool));

RATE THUMBSUP PLEASE

Add a comment
Know the answer?
Add Answer to:
REQUIREMENTS: Problem Description: Create a Dynamic 2D Array Class. This class should overload the Call Operator...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (C++ exercise) 5. Write a new Checkbook class that uses a dynamic array. Call the class...

    (C++ exercise) 5. Write a new Checkbook class that uses a dynamic array. Call the class a different name, since it will be different from the latest version that uses a static array. Start off with a dynamic array size of 2, made by the constructor. Every time the dynamic array becomes full and a new check has to be written, double the current size of the array. Write a doubleArray function for the class to do this, but place...

  • #ifndef STUDENTTESTSCORES_H #define STUDENTTESTSCORES_H #include <string> using namespace std; const double DEFAULT_SCORE = 0.0; class StudentTestScores...

    #ifndef STUDENTTESTSCORES_H #define STUDENTTESTSCORES_H #include <string> using namespace std; const double DEFAULT_SCORE = 0.0; class StudentTestScores { private: string studentName; // The student's name double *testScores; // Points to array of test scores int numTestScores; // Number of test scores // Private member function to create an // array of test scores. void createTestScoresArray(int size) { numTestScores = size; testScores = new double[size]; for (int i = 0; i < size; i++) testScores[i] = DEFAULT_SCORE; } public: // Constructor StudentTestScores(string...

  • C++ problem with dynamic arrays is that once the array is created using the new operator...

    C++ problem with dynamic arrays is that once the array is created using the new operator the size cannot be changed. For example, you might want to add or delete entries from the array similar to the behavior of a vector. This project asks you to create a class called DynamicStringArray that includes member functions that allow it to emulate the behavior of a vector of strings. The class should have: A private member variable called dynamicArray that references a...

  • 8.9 Coding lab #5: create a dynamic array ADT and a singly linked list ADT. Honor Code...

    8.9 Coding lab #5: create a dynamic array ADT and a singly linked list ADT. Honor Code Your answers to this homework must be your own work.You are not allowed to share your solutions.You may not engage in any other activities that will dishonestly improve your results or dishonestly improve or damage the results of others. Plagiarism Plagiarism is when you copy words, ideas, or any other materials from another source without giving credit. Plagiarism is unacceptable in any academic environment....

  • 1. Here are codes to define a stack class based on dynamic array, please complete the...

    1. Here are codes to define a stack class based on dynamic array, please complete the copy constructor //--- Definition of Stack copy constructor Stack::Stack(const Stack & original) : myCapacity(original.myCapacity), myTop(original.myTop) { //--- Get new array for copy myArray = new(nothrow) StackElement[myCapacity]; if (myArray != 0) // check if memory available                         // copy original's array member into this new array {              // Please complete the function here        } else {          cerr << "*Inadequate memory to allocate...

  • Following the instruction This is c++ programming Lab Tasks: 1. Define a dynamic array class in...

    Following the instruction This is c++ programming Lab Tasks: 1. Define a dynamic array class in DynamicArray .h and DynamicArray.cpp files, according to the following UML class diagram: DynamicArray - int arrySize; - int currentSize; int* arrayPtr; + DynamicArray(int size) // Explicit constructor, which you define- allocate space in dynamic memory for an integer array of the given size. + DynamicArray) // Explicit destructor, which you define-de allocate dynamic memory. + additem(int item): bool // Set the value of the...

  • IN C++ Create a class to act as a generic array (i.e. the user will be...

    IN C++ Create a class to act as a generic array (i.e. the user will be able to choose the data type to be stored by passing the appropriate template argument. Integer template arguments will also be used to set the upper and lower bounds of the array. Provide all necessary functionality to allow the class to act as an array ([] operator, = operator etc.). The array does not need to provide input or output methods to act on...

  • QUESTION 18 According to class materials, the program is allowed to overload operators only if at...

    QUESTION 18 According to class materials, the program is allowed to overload operators only if at least one incoming parameter received by the operator has a class type. 1. (a) True 2. (b) False QUESTION 19 According to the course materials, a function can take value parameters and reference parameters. A value parameter is a separate variable from the one in main() or another calling function only if the function value parameter has a different name than the one in...

  • put everything together in an object-oriented manner! create a class named PositiveNumberStatistics that has the following:...

    put everything together in an object-oriented manner! create a class named PositiveNumberStatistics that has the following: A private double 1D array instance variable named numbers. A constructor that takes one parameter, a 1D double array. The constructor should throw an IllegalArgumentException with the message "Array length of zero" if the parameter has a length of 0. If the exception is not thrown, the constructor should create the numbers array and copy every element from the parameter into the numbers instance...

  • The following program contains the definition of a class called List, a class called Date and...

    The following program contains the definition of a class called List, a class called Date and a main program. Create a template out of the List class so that it can contain not just integers which is how it is now, but any data type, including user defined data types, such as objects of Date class. The main program is given so that you will know what to test your template with. It first creates a List of integers and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT