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 7760849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:59:53+00:00 2026-06-01T13:59:53+00:00

I have the following code: #include <iostream> #include Student.h <– fixed the problem #include

  • 0

I have the following code:

#include <iostream>
#include "Student.h" <-- fixed the problem
#include "SortedList.h" <-- fixed the problem

using namespace std;

int main() {
    // points to the sorted list object
    SortedList *list = new SortedList;   //This is line 17

    // array to hold 100 student objects
    Student create[100];

    int num = 100000;   // holds different ID numbers

    // fills an array with 100 students of various ID numbers
    for (Student &x : create) {
        x = new Student(num);
        num += 100;
    }

    // insert all students into the sorted list
    for (Student &x : create)
        list->insert(&x);

    delete list;
    return 0;
}

And I keep getting the compile time error:

main.cpp: In function ‘int main()’:
main.cpp:17: error: ‘SortedList’ was not declared in this scope
main.cpp:17: error: ‘list’ was not declared in this scope
main.cpp:17: error: expected type-specifier before ‘SortedList’
main.cpp:17: error: expected `;' before ‘SortedList’
main.cpp:20: error: ‘Student’ was not declared in this scope
main.cpp:20: error: expected primary-expression before ‘]’ token
main.cpp:20: error: expected `;' before ‘create’
main.cpp:25: error: expected `;' before ‘x’
main.cpp:31: error: expected primary-expression before ‘for’
main.cpp:31: error: expected `;' before ‘for’
main.cpp:31: error: expected primary-expression before ‘for’
main.cpp:31: error: expected `)' before ‘for’
main.cpp:31: error: expected `;' before ‘x’
main.cpp:34: error: type ‘<type error>’ argument given to ‘delete’, expected pointer
main.cpp:35: error: expected primary-expression before ‘return’
main.cpp:35: error: expected `)' before ‘return’

My Student.cpp and SortedList.cpp files compile just fine. They both also include .h files. I just do not understand why I get an error on that line. It seems to be a small issue though. Any insight would be appreciated.

UPDATE1: I originally had .h files included, but i changed it when trying to figure out the cause of the error. The error remains with the .h files included though.

UPDATE2:

SortedList.h

#ifndef SORTEDLIST_H
#define SORTEDLIST_H

#include "Student.h"

/*
 * SortedList class
 *
 * A SortedList is an ordered collection of Students.  The Students are ordered
 * from lowest numbered student ID to highest numbered student ID.
 */
class SortedList {

  public:

    SortedList();
    // Constructs an empty list.

    SortedList(const SortedList & l);
    // Constructs a copy of the given student object

    ~SortedList();
    // Destructs the sorted list object

    const SortedList & operator=(const SortedList & l);
    // Defines the assignment operator between two sorted list objects

    bool insert(Student *s);
    // If a student with the same ID is not already in the list, inserts 
    // the given student into the list in the appropriate place and returns
    // true.  If there is already a student in the list with the same ID
    // then the list is not changed and false is returned.

    Student *find(int studentID);
    // Searches the list for a student with the given student ID.  If the
    // student is found, it is returned; if it is not found, NULL is returned.

    Student *remove(int studentID);
    // Searches the list for a student with the given student ID.  If the 
    // student is found, the student is removed from the list and returned;
    // if no student is found with the given ID, NULL is returned.
    // Note that the Student is NOT deleted - it is returned - however,
    // the removed list node should be deleted.

    void print() const;
    // Prints out the list of students to standard output.  The students are
    // printed in order of student ID (from smallest to largest), one per line

  private:

    // Since Listnodes will only be used within the SortedList class,
    // we make it private.
    struct Listnode {    
      Student *student;
      Listnode *next;
    };

    Listnode *head; // pointer to first node in the list

    static void freeList(Listnode *L);
    // Traverses throught the linked list and deallocates each node

    static Listnode *copyList(Listnode *L);
    // Returns a pointer to the first node within a particular list
};

#endif

Student.h

#ifndef STUDENT_H
#define STUDENT_H
/*
 * Student class
 *
 * A Student object contains a student ID, the number of credits, and an
 * overall GPA.
 */
class Student {

  public:

    Student();
    // Constructs a default student with an ID of 0, 0 credits, and 0.0 GPA.

    Student(int ID);
    // Constructs a student with the given ID, 0 credits, and 0.0 GPA.

    Student(int ID, int cr, double grPtAv);
    // Constructs a student with the given ID, number of credits, and GPA.\

    Student(const Student & s);
    // Constructs a copy of another student object

    ~Student();
    // Destructs a student object

    const Student & operator=(const Student & rhs);
    // Defines the assignment operator between two student objects

    // Accessors
    int getID() const;       // returns the student ID
    int getCredits() const;  // returns the number of credits
    double getGPA() const;   // returns the GPA

    // Other methods

    void update(char grade, int cr);
    // Updates the total credits and overall GPA to take into account the
    // additions of the given letter grade in a course with the given number
    // of credits.  The update is done by first converting the letter grade
    // into a numeric value (A = 4.0, B = 3.0, etc.).  The new GPA is 
    // calculated using the formula:
    //
    //            (oldGPA * old_total_credits) + (numeric_grade * cr)
    //   newGPA = ---------------------------------------------------
    //                        old_total_credits + cr
    //
    // Finally, the total credits is updated (to old_total_credits + cr)

    void print() const;  
    // Prints out the student to standard output in the format:
    //   ID,credits,GPA
    // Note: the end-of-line is NOT printed after the student information 

  private:
    int studentID;
    int credits;
    double GPA;
};

#endif
  • 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-06-01T13:59:55+00:00Added an answer on June 1, 2026 at 1:59 pm

    You want to include .h files, not .cpp files:

    #include "Student.h"
    #include "SortedList.h"
    

    Without more code it’s hard to speculate what else the issue may be.

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

Sidebar

Related Questions

i have following code #include <iostream> using namespace std; int main(int argc,char arg[]){ int
i have following code #include <iostream> using namespace std; int main(){ int i; char
i have following code #include <iostream> #include <cstdlib> using namespace std; int main() {
I have following code #include <iostream> #include <string> #include <algorithm> using namespace std; int
I have following code: #include <iostream> using namespace std; template<class T> T max(T *data,int
I have the following code: #include <iostream> using namespace std; class testing{ int test()
I have the following code #include <iostream> #include <vector> using namespace std; int distance(vector<int>&
I have the following code: #include <iostream> using namespace std; struct S { S(int
i have following code for heapsort #include <iostream> using namespace std; void exch(int a[],int
I have the following code: #include <iostream> #include <vector> using namespace std; struct A{};

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.