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

  • Home
  • SEARCH
  • 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 7531295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:08:03+00:00 2026-05-30T05:08:03+00:00

This is a class assignment that must be done using a dynamically created array

  • 0

This is a class assignment that must be done using a dynamically created array of Course. I am trying to read into each member variable inside of course inside of my for loop but I’m not really sure how to do it. I did it with my student struct but the difference in this being an array is messing me up because I’m not sure how to proceed with it.

My problem is in the readCourseArray function when trying to read in struct members. If anyone could tell me how I do that I’d be appreciative. I know using the new operator isn’t ideal along with many of the pointers being unnecessary but it is just how my instructor requires the assignment to be turned in.

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

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

Student* readStudent();
Course* readCourseArray(int);
int main()
{
    int courses = 0;
    Student *studentPTR = readStudent();
    Course *coursePTR = readCourseArray(courses);


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

Student* readStudent()
{       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)
{
    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<<"'s course name\n";
        cin>>coursePTR[count]->courseName>>endl;
        cout<<"\nEnter student "<<count<<"'s course number\n";
        cin>>coursePTR[count]->courseNumber;
        cout<<"\nEnter student "<<count<<"'s credit hours\n";
        cin>>coursePTR[count]->creditHours;
        cout<<"\nEnter student "<<count<<"'s grade\n";
        cin>>coursePTR[count]->grade>>endl;
    }


    return coursePTR;
}
  • 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-30T05:08:04+00:00Added an answer on May 30, 2026 at 5:08 am

    Array subscript operator return an element of the array.

    coursePTR[count] is equivalent to incrementing the pointer to the start of array and dereferencing the result, like: *(coursePTR + count). What you get is an object (or a reference to one) of type Course. So you’ll need to use ‘dot’ operator, not ‘arrow’ operator to access the elements:

    cin >> coursePTR[count].creditHours;
    

    You’ve got another error:

    cin >> coursePTR[count].courseName >> endl;
                                          ^^^^
    

    This won’t compile. endl can only be used on output streams.

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

Sidebar

Related Questions

Below is selected code from one of 5 classes for this assignment. Each class
For this assignment I had to create my own string class. I initially wrote
I have a C++ class that contains a non-copyable handle. The class, however, must
I have an Entity class that looks like this: <?php namespace Entities; /** @Entity
Working on my assignment for Java and I have created a class called Triangle.
i got assignment, where i must write a class for multidimensional vector i was
Most posts I have read regarding implementation of copy constructor is that you must
I'm trying to fetch list of files using a method that apparently works well
Given this class class Foo { // Want to find _bar with reflection [SomeAttribute]
Consider this class hierarchy: Book extends Goods Book implements Taxable As we know, there

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.