Question

In C++, please do not google Problem Description: Create a Dynamic 2D Array Class. This class...

In C++, please do not google

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.

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


Screenshot of the program code:

Screenshot of the Input file:

Input file: StudentData.txt

Screenshot of the Sample Output:

look for the indentation of the program code in the screenshot of the program code given above.

Program 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));

Add a comment
Know the answer?
Add Answer to:
In C++, please do not google Problem Description: Create a Dynamic 2D Array Class. This class...
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
  • 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:...

  • --C++-- --spc16-7.cpp-- // Chapter 16, Programming Challenge 7: TestScores class #include <iostream> #include "TestScores.h" #include "NegativeScore.h"...

    --C++-- --spc16-7.cpp-- // Chapter 16, Programming Challenge 7: TestScores class #include <iostream> #include "TestScores.h" #include "NegativeScore.h" using namespace std; int main() { // Constant for the number of test scores const int NUM_SCORES = 5;       try    {        // Create an array of valid scores.        int myScores[NUM_SCORES] = { 88, 90, 93, 87, 99 };        // Create a TestScores object.        //TestScores myTestScores(myScores, NUM_SCORES); // optional constructor        TestScores myTestScores(myScores);...

  • #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...

  • 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...

  • Please do it carefully Using the header file ( MyArray.h ) Type the implementation file MyArray.cpp,...

    Please do it carefully Using the header file ( MyArray.h ) Type the implementation file MyArray.cpp, and a test file to test the functionality of the class. Hint: read all the explanations in the header with attention. MyArray.h : #ifndef MYARRAY_H #define MYARRAY_H #include <iostream> using namespace std; class MyArray { friend ostream& operator<<( ostream & output, const MyArray & rhs); // to output the values of the array friend istream& operator>>( istream & input, MyArray & rhs); // to...

  • please write in c++. 4 Derived class JPG 4.1 Class declaration • The class JPG inherits...

    please write in c++. 4 Derived class JPG 4.1 Class declaration • The class JPG inherits from File and is a non-abstract class. 1. Hence objects of the class JPG can be instantiated. 2. To do so, we must override the pure virtual function clone() in the base class. • The class declaration is given below. class JPG : public File { public: JPG(const std::string& n, int n, int w, const double rgb()) : File(...) { // ... } *JPG()...

  • 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...

  • (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...

  • please do this C++ question asap Create a class Hugelnteger that uses a 40-element array of...

    please do this C++ question asap Create a class Hugelnteger that uses a 40-element array of digits to store integers as large as 40 digits each. Overload the equality (==) operator Overload the add (+)operator Overload the multiply (*) operator (extra bonus)

  • In C++: Implement a class Polynomial that uses a dynamic array of doubles to store the...

    In C++: Implement a class Polynomial that uses a dynamic array of doubles to store the coefficients for a polynomial. This class does not need the method the overloaded += operator. Your class should have the following methods: Write one constructor that takes an integer n for the degree of a term and a double coefficient c for the coefficient of the term and creates the polynomial c x^n. (This constructor can be given default arguments easily to have a...

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