Question

In: Computer Science

I'm having a problem getting my code to function correct, *num_stu keeps losing its value when...

I'm having a problem getting my code to function correct, *num_stu keeps losing its value when ever another function is called from the class. Can someone proof read this for me and let me know what'd up?

Header.h file
#include <iostream>

using namespace std;

class report {
   private:
       int* num_stu;
        int xx;
       int* id;
       double* gpa;

   public:
      
        report(int x) {
            num_stu = &x;
            xx = x;
            id = new int[*num_stu];
            gpa = new double[*num_stu];

            for (int i = 0; i < *num_stu; i++) {
                id[i] = 0;
                gpa[i] = 0;
            }
        }

        void assign() {
            cout <<"You still losing your value? " << *num_stu << endl << num_stu << xx << endl;;
            for (int i = 0; i < *num_stu; i++) {
                cout << "Enter ID: " << endl;
                cin >> id[i];
                cout << "Enter GPA: " << endl;
                cin >> gpa[i];
              
            }
        }

        void print_info() {

            for (int i = 0; i < *num_stu; i++) {
                cout << id[i] << " " << gpa[i] << " ";

                if (gpa[i] >= 3.8) {
                    cout << "an honor student. ";

                }
                cout << endl;
            }
        }

        ~report() {
            delete[]id;
            delete[]gpa;
        }


};

Main.cpp file

#include <iostream>
#include "report.h"

using namespace std;


int main() {
  
   report boy(5);
   boy.assign();
   boy.print_info();
}

Solutions

Expert Solution

class report {
private:
    int *num_stu;
    int xx;
    int *id;
    double *gpa;

public:

    report(int x) {
        num_stu = new int;  // create a new integer
        *num_stu = x;   // then use x to set value of num_stu
        xx = x;
        id = new int[*num_stu];
        gpa = new double[*num_stu];

        for (int i = 0; i < *num_stu; i++) {
            id[i] = 0;
            gpa[i] = 0;
        }
    }

    void assign() {
        cout << "You still losing your value? " << *num_stu << endl << num_stu << xx << endl;;
        for (int i = 0; i < *num_stu; i++) {
            cout << "Enter ID: " << endl;
            cin >> id[i];
            cout << "Enter GPA: " << endl;
            cin >> gpa[i];

        }
    }

    void print_info() {

        for (int i = 0; i < *num_stu; i++) {
            cout << id[i] << " " << gpa[i] << " ";

            if (gpa[i] >= 3.8) {
                cout << "an honor student. ";

            }
            cout << endl;
        }
    }

    ~report() {
        delete[]id;
        delete[]gpa;
    }
};



Related Solutions

I'm having a very hard time getting this c++ code to work. I have attached my...
I'm having a very hard time getting this c++ code to work. I have attached my code and the instructions. CODE: #include using namespace std; void printWelcome(string movieName, string rating, int startHour, int startMinute, char ampm); //menu function //constants const double TICKET_PRICE = 9.95; const double TAX_RATE = 0.095; const bool AVAILABLE = true; const bool UNAVAILABLE = false; int subTotal,taxAdded, totalCost; // bool checkAvailability( int tickets, int& seatingLeft){ //checks ticket availability while(tickets > 0 || tickets <= 200) //valid...
I'm getting an error with my code on my EvenDemo class. I am supposed to have...
I'm getting an error with my code on my EvenDemo class. I am supposed to have two classes, Event and Event Demo. Below is my code.  What is a better way for me to write this? //******************************************************** // Event Class code //******************************************************** package java1; import java.util.Scanner; public class Event {    public final static double lowerPricePerGuest = 32.00;    public final static double higherPricePerGuest = 35.00;    public final static int cutOffValue = 50;    public boolean largeEvent;    private String...
I am having trouble with my assignment and getting compile errors on the following code. The...
I am having trouble with my assignment and getting compile errors on the following code. The instructions are in the initial comments. /* Chapter 5, Exercise 2 -Write a class "Plumbers" that handles emergency plumbing calls. -The company handles natural floods and burst pipes. -If the customer selects a flood, the program must prompt the user to determine the amount of damage for pricing. -Flood charging is based on the numbers of damaged rooms. 1 room costs $300.00, 2 rooms...
I'm having problems with my java code not correctly spellchecking certain words. 1) Determine if a...
I'm having problems with my java code not correctly spellchecking certain words. 1) Determine if a word entered by the user is spelled correctly. A word is considered correct if it's found in dictionary.txt (see required output to get file). these are the input and output that are suppose to come out i already have the dictionary.txt i just don't know hoe to set it up someone please help me Standard Input                 Files in the same directory glimmer hello...
I'm having trouble with validating this html code. Whenever I used my validator, it says I...
I'm having trouble with validating this html code. Whenever I used my validator, it says I have a stray end tag: (tbody) from line 122 to 123. It's the last few lines. Thanks and Ill thumbs up whoever can help solve my problem. Here's my code: <!DOCTYPE html> <html lang="en"> <head> <title>L7 Temperatures Fields</title> <!--    Name:    BlackBoard Username:    Filename: (items left blank for bb reasons    Class Section: (blank)    Purpose: Making a table to demonstrate my...
I'm having difficulty trying to make my code work. Create a subclass of Phone called SmartPhone....
I'm having difficulty trying to make my code work. Create a subclass of Phone called SmartPhone. Make this subclass have a no-arg constructor and a constructor that takes a name, email, and phone. Override the toString method to return the required output. Given Files: public class Demo1 { public static void test(Phone p) { System.out.println("Getter test:"); System.out.println(p.getName()); System.out.println(p.getNumber()); } public static void main(String[] args) { Phone test1 = new SmartPhone(); Phone test2 = new SmartPhone("Alice", "8059226966", "[email protected]"); System.out.println(test1); System.out.println(test2); System.out.println(test1);...
I'm finally getting my head around the concept of chirality and stereoisomers, but I'm still really...
I'm finally getting my head around the concept of chirality and stereoisomers, but I'm still really struggling with the assigning of absolute configurations. If someone could demonstrate how they would draw one of the stereoisomers of the chiral molecule, Adrenalin, and assign it the correct R or S designation, I would really appreciate it...if you could throw the enantiomer in there as well (with the opposite configuration) that would also be helpful. Thank you!
(PLEASE SHOW STEPS TO SOLUTIONS. I'M GETTING STUCK IN MY PROCESS AND NOT SURE WHERE I'M...
(PLEASE SHOW STEPS TO SOLUTIONS. I'M GETTING STUCK IN MY PROCESS AND NOT SURE WHERE I'M GOING WRONG AND WHAT TO DO NEXT.) Skycell, a major European cell phone manufacturer, is making production plans for the coming year. Skycell has worked with its customers (the service providers) to come up with forecasts of monthly requirements (in thousands of phones) as shown in the table below (e.g., demand in Jan. is 1,000,000 units.) Manufacturing is primarily an assembly operation, and capacity...
Please see if you can correct my code. I am getting an ReferenceError in Windows Powershell...
Please see if you can correct my code. I am getting an ReferenceError in Windows Powershell that says payment is undefined. I am trying to create a main.js file that imports the function from the hr.js file; call the function passing the necessary arguments and log the result to the console. main.js var Dev = require("./hr.js") const { add } = require("./hr.js") var dev_type = 1; var hr = 40; console.log("your weekly payment is " + payment(dev_type, hr)) dev_type =...
I'm having trouble with my do while loop. I'm trying to get it where if the...
I'm having trouble with my do while loop. I'm trying to get it where if the user enter's 3 after whatever amount of caffeinated beverages they've entered before then the loop will close and the rest of my code would proceed to execute and calculate the average price of all the caffeinated beverages entered. Can someone please help me with this? Here's my Code: import java.util.Scanner; public class Main { public static void main(String[] args) { CaffeinatedBeverage[] inventory = new...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT