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...
The problem I'm having with this code is that when you choose the 24 month payment...
The problem I'm having with this code is that when you choose the 24 month payment plan and hit 2 to print your result is that there are way to many decimal places. is there a way to resolve this problem? I have tried formatting and can not figure out my setback. Thank you for any help you can give me. import java.util.ArrayList; import javax.swing.JOptionPane; import javax.swing.UIManager; import javax.swing.ImageIcon; import java.awt.Color; class market { public static void main(String[] args) {...
I'm having trouble getting a certain output with this code #include <stdio.h> //function prototypes void initializeArray(int...
I'm having trouble getting a certain output with this code #include <stdio.h> //function prototypes void initializeArray(int size, int ids[]); void printArray(int size, int * idPointer); int main(void) { // 1. declare an array of 5 integers called ids int ids[5]; // 2. declare an integer pointer called arrayPointer and // initialize it to point to the array called ids int *arrayPointer = ids; // 3. call initializeArray() function sending to it // 5 for the size and the array called...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT