Question

In: Computer Science

Write the header and the implementation files (.h and .cpp separatelu) for a class called Course,...

  1. Write the header and the implementation files (.h and .cpp separatelu) for a class called Course, and a simple program to test it, according to the following specifications:                   
  1. Your class has 3 member data: an integer pointer that will be used to create a dynamic variable to represent the number of students, an integer pointer that will be used to create a dynamic array representing students’ ids, and a double pointer that will be used to create a dynamic array to represent the GPAs of each student.
  1. Your class has the following member functions:

       

  1. a constructor with an int parameter representing the number of students; the constructor creates the dynamic variable and sets it to the int parameter, creates the two dynamic arrays and sets everything to zero.

  1. a function which reads in all the ids and the GPAs into the appropriate arrays.
  1. a function called print_info which, for each student, does all of the

                following:

                It prints the student’s id and GPA. If the student’s GPA is greater than or equal to 3.8, it prints “an honor student”.

Solutions

Expert Solution

#include<bits/stdc++.h> 
using namespace std;

class Course                   // creation of class
{
    
    int *num_of_stud;            // int pointer to hold no of students
    int* id = NULL;              // int pointer to hold the array of ids
    double* gpa = NULL;          // int pointer to hold the grades array
    
    Course(int n)                // constructor which initializes all variables and arrays
    {
        *num_of_stud = n;
        id = new int[n];
        gpa = new double[n];
        
        for(int i=0; i<n; i++)
        {
            id[i] = 0;
            gpa[i] = 0.0;
        }
    }
    
    void read_data()                  // function to read the data 
    {
        for(int i=0; i<*num_of_stud; i++)
        {
            cin>>id[i];
            cin>>gpa[i];
        }
    }
    
    void print_info()                      // function to print the data according to the question
    {
         for(int i=0; i<*num_of_stud; i++)
        {
            cout<<"ID of student "<<i+1<<" : "<<id[i]<<endl;
            cout<<"Grade : "<<gpa[i]<<endl;
            
            if(gpa > 3.8)
            cout<<"an honour student"<<endl;
        }
    }
};

int main()
{
  // write your code inside main() accordingly 
}

here is the code for the above problem

created the required class

declared all necessary pointer variables and arrays

defined each asked function as well

can tell me if you want me to write something in main() as well


Related Solutions

Write the header and the implementation files (.h and .cpp separately) for a class called Course,...
Write the header and the implementation files (.h and .cpp separately) for a class called Course, and a simple program to test it (C++), according to the following specifications:                    Your class has 3 member data: an integer pointer that will be used to create a dynamic variable to represent the number of students, an integer pointer that will be used to create a dynamic array representing students’ ids, and a double pointer that will be used to create a dynamic...
WRITE ONLY THE TO DO'S   in FINAL program IN C++ (necessary cpp and header files are...
WRITE ONLY THE TO DO'S   in FINAL program IN C++ (necessary cpp and header files are witten below) "KINGSOM.h " program below: #ifndef WESTEROS_kINGDOM_H_INCLUDED #define WESTEROS_KINGDOM_H_INCLUDED #include <iostream> namespace westeros { class Kingdom{         public:                 char m_name[32];                 int m_population; };         void display(Kingdom&);                      } #endif } Kingdom.cpp Program below: #include <iostream> #include "kingdom.h" using namespace std; namespace westeros {         void display(Kingdom& pKingdom) {                 cout << pKingdom.m_name << ", population " << pKingdom.m_population << endl;                                                               FINAL:...
Complete the following task in C++. Separate your class into header and cpp files. You can...
Complete the following task in C++. Separate your class into header and cpp files. You can only useiostream, string and sstream. Create a main.cpp file to test your code thoroughly. Given : commodity.h and commodity.cpp here -> https://www.chegg.com/homework-help/questions-and-answers/31-commodity-request-presented-two-diagrams-depicting-commodity-request-classes-form-basic-q39578118?trackid=uF_YZqoK Create : locomotive.h, locomotive.cpp, main.cpp Locomotive Class Hierarchy Presented here will be a class diagram depicting the nature of the class hierarchy formed between a parent locomotive class and its children, the two kinds of specic trains operated. The relationship is a...
Complete the following task in C++. Separate your class into header and cpp files. You can...
Complete the following task in C++. Separate your class into header and cpp files. You can only use iostream, string and sstream. Create a main.cpp file to test your code thoroughly. Given : commodity.h and commodity.cpp here -> https://www.chegg.com/homework-help/questions-and-answers/31-commodity-request-presented-two-diagrams-depicting-commodity-request-classes-form-basic-q39578118?trackid=uF_YZqoK Given : locomotive.h, locomotive.cpp, main.cpp -> https://www.chegg.com/homework-help/questions-and-answers/complete-following-task-c--separate-class-header-cpp-files-useiostream-string-sstream-crea-q39733428 Create : DieselElectric.cpp DieselElectric.h DieselElectric dieselElectric -fuelSupply:int --------------------------- +getSupply():int +setSupply(s:int):void +dieselElectric(f:int) +~dieselElectric() +generateID():string +calculateRange():double The class variables are as follows: fuelSuppply: The fuel supply of the train in terms of a number of kilolitres...
In C++ You will create 3 files: The .h (specification file), .cpp (implementation file) and main...
In C++ You will create 3 files: The .h (specification file), .cpp (implementation file) and main file. You will practice writing class constants, using data files. You will add methods public and private to your BankAccount class, as well as helper methods in your main class. You will create an arrayy of objects and practice passing objects to and return objects from functions. String functions practice has also been included. You have been given a template in Zylabs to help...
BankAccount: You will create 3 files: The .h (specification file), .cpp (implementation file) and main file....
BankAccount: You will create 3 files: The .h (specification file), .cpp (implementation file) and main file. You will practice writing class constants, using data files. You will add methods public and private to your BankAccount class, as well as helper methods in your main class. You will create an array of objects and practice passing objects to and return objects from functions. String functions practice has also been included. Extend the BankAccount class. The member fields of the class are:...
Separate code into .cpp and .h files: // C++ program to create and implement Poly class...
Separate code into .cpp and .h files: // C++ program to create and implement Poly class representing Polynomials #include <iostream> #include <cmath> using namespace std; class Poly { private: int degree; int *coefficients; public: Poly(); Poly(int coeff, int degree); Poly(int coeff); Poly(const Poly& p); ~Poly(); void resize(int new_degree); void setCoefficient(int exp, int coeff); int getCoefficient(int exp); void display(); }; // default constructor to create a polynomial with constant 0 Poly::Poly() { // set degree to 0 degree = 0; //...
c++ Write the implementation (.cpp file) of the Counter class of the previous exercise. The full...
c++ Write the implementation (.cpp file) of the Counter class of the previous exercise. The full specification of the class is: A data member counter of type int. An data member named counterID of type int. A static int data member named nCounters which is initialized to 0. A constructor that takes an int argument and assigns its value to counter. It also adds one to the static variable nCounters and assigns the (new) value of nCounters to counterID. A...
You are to write a class named Rectangle. You must use separate files for the header...
You are to write a class named Rectangle. You must use separate files for the header (Rectangle.h) and implementation (Rectangle.cpp) just like you did for the Distance class lab and Deck/Card program. You have been provided the declaration for a class named Point. Assume this class has been implemented. You are just using this class, NOT implementing it. We have also provided a main function that will use the Point and Rectangle classes along with the output of this main...
In C++ ifdef QUESTION2    /*    2. Create a header and implementation for a class...
In C++ ifdef QUESTION2    /*    2. Create a header and implementation for a class named bottle. bottle objects should be able    to set and get their size in ounces, the type of liquid it contains(as a string), the amount of    liquid it contains and whether they are less than another bottle object(based on the amount    of liquid they contain). Do not comment your code.    */    std::cout << "QUESTION 2: " << std::endl <<...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT