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'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 writing a code for the Secant Method for root finding, but my code makes an...
I'm writing a code for the Secant Method for root finding, but my code makes an infinite code of the correct answer. Below is my code, how do I fix it? def f(x): return (x**6)+7*(x**5)-15*(x**4)-70*(x**3)+75*(x**2)+175*x-125 def secant(): p0=float(input('Enter an initial guess for the root ')) p1=float(input('Enter another guess ')) TOL=float(input('Enter a tolerance in decimal form ')) n=15 i=1 while i<=n: p=p1-f(p1)*(p1-p0)/(f(p1)-f(p0)) if abs(p-p1)<TOL: print(p) else: p0=p1 p1=p i=i+1 else: print(p) return p    print(secant())
I'm getting an error message with this code and I don't know how to fix it...
I'm getting an error message with this code and I don't know how to fix it The ones highlighted give me error message both having to deal Scanner input string being converted to an int. I tried changing the input variable to inputText because the user will input a number and not a character or any words. So what can I do to deal with this import java.util.Scanner; public class Project4 { /** * @param args the command line arguments...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT