Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7534969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:10:10+00:00 2026-05-30T06:10:10+00:00

I am writing a program for a class assignment on learning about pointers and

  • 0

I am writing a program for a class assignment on learning about pointers and memory management. Allocating memory for student and courses is necessary with the new operator in this assignment and the program seems to run properly but after it prints everything the program crashes and it says that that it has triggered a break point. Any help would be appreciated.

The error is located here but I’m not sure what it means
/* verify block type */
_ASSERTE(_BLOCK_TYPE_IS_VALID(pHead->nBlockUse));

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

struct Student //Structs
    {
        string firstName, lastName, aNumber;
        double GPA;
    };
struct Course
    {
        int courseNumber, creditHours;
        string courseName;
        char grade;
    };

Student* readStudent();                                    // Function Prototypes
Course* readCourseArray(int&);
void computeGPA(Student *student, Course *courseArray, int coursesTaken);
void printSummary(Student *studentPTR, Course *courseArray, int courses);
int main()                                                //Main
{
    int courses = 0;
    Student *studentPTR = readStudent();
    Course *coursePTR = readCourseArray(courses);
    computeGPA(studentPTR, coursePTR, courses);
    printSummary(studentPTR, coursePTR, courses);


    delete studentPTR;
    delete coursePTR;
    system ("pause");
    return 0;
}

Student* readStudent()                                       // Read Student
{
    Student* student = new Student;
    cout<<"\nEnter students first name\n";
    cin>>student->firstName;
    cout<<"\nEnter students last name\n";
    cin>>student->lastName;
    cout<<"\nEnter students A-Number\n";
    cin>>student->aNumber;


    return student;
}

Course* readCourseArray(int &courses)                           //Read Courses
{
    cout<<"\nHow many courses is the student taking?\n";
    cin>>courses;
    const int *sizePTR = &courses;
    Course *coursePTR = new Course[*sizePTR]; 

    for(int count = 0; count < *sizePTR; count++)  //Enter course information
    {
        cout<<"\nEnter student "<<count+1<<"'s course name\n";
        cin>>coursePTR[count].courseName;
        cout<<"\nEnter student "<<count+1<<"'s course number\n";
        cin>>coursePTR[count].courseNumber;
        cout<<"\nEnter student "<<count+1<<"'s credit hours\n";
        cin>>coursePTR[count].creditHours;
        cout<<"\nEnter student "<<count+1<<"'s grade\n";
        cin>>coursePTR[count].grade;
    } 


    return coursePTR;
}


void computeGPA(Student *studentPTR, Course *courseArray, int coursesTaken)             // Compute GPA
{
    double total = 0, hours = 0;
    for(int count = 0; count < coursesTaken; count++)
    {
        hours += courseArray[count].creditHours;
        if (courseArray[count].grade == 'A')
            total+=4;
        else if (courseArray[count].grade == 'B')
            total+=3;
        else if (courseArray[count].grade == 'C')
            total+=2;
        else if (courseArray[count].grade == 'D')
            total+=1;
        else if (courseArray[count].grade == 'F')
            total+=0;
    }
    studentPTR->GPA = (total / hours);
}


void printSummary(Student *studentPTR, Course *courseArray, int courses)
{
    cout<<"\nReport\n";
    cout<<"\nNumber   Name                    Hours  Letter Grade  Point Grade";  
    cout<<"\n------   ----                    -----  ------------  -----------\n";
    for(int count = 0; count < courses; count++)
         cout<<setw(3)<<courseArray[count].courseNumber<<"   "<<courseArray[count].courseName<<setw(20)<<"   "<<courseArray[count].creditHours<<setw(5)<<"  "<<courseArray[count].grade<<endl;

    cout<<"\nStudent :"<<studentPTR->firstName<<" "<<studentPTR->lastName;
    cout<<"\nA-Number :"<<studentPTR->aNumber;
    cout<<"\nOverall GPA :"<<studentPTR->GPA;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T06:10:12+00:00Added an answer on May 30, 2026 at 6:10 am

    You’re allocating courses with operator new[] (which is for arrays), but freeing it with operator delete, instead of operator delete[].

    You should deallocate it like that:

    delete[] coursePTR;
    

    I also don’t understand why you use the sizePTR pointer instead of directly using courses.

    BTW, just so you’d know, this is not a ‘find my bug’ site. You have a code review site for that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing c++ program. This is Student class: #include Student.hpp #include Home.hpp #include
I'm writing a program for class, and I'm wondering about the output for a
I'm writing a simple program. There is only one class in it. There is
Suppose we are writing a class (let's call it Class) in an iPhone program.
I am writing a program for class that is asking us to create a
I am writing a program to find adapters, and have made a class called
For a class assignment, we are writing a custom syscall which pulls certain information
Recently for a programming class, we were given the assignment to write a program
I am writing a program for a class I am taking. I am having
I am writing a program for class in which I analyze different product codes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.