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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:00:30+00:00 2026-05-16T18:00:30+00:00

I have the following hierarchy: Graduate.cpp (abstract) College.cpp (abstract) Ecollege.cpp University.cpp (abstract) Tuniversity.cpp Huniversity.cpp

  • 0

I have the following hierarchy:

Graduate.cpp  (abstract)
   College.cpp  (abstract)
      Ecollege.cpp
   University.cpp (abstract)
      Tuniversity.cpp
      Huniversity.cpp  

class Huniversity for example represents a student that graduated from H university.
each non-abstract class has to implement the following method which is defined in Graduate.h:

    virtual double CalcGraduateAvg() = 0;

Tuniversity has use info from Huniversity. this info is stored it static variables.
this is for example Tuniversity header and implementation:

#include "University.h"
#define AVG_FACTOR 5

class Tuniversity : public University {
public:
    Tuniversity(int id, char identifier, double salary, double grades);
    virtual double CalcGraduateAvg();

protected:
    static int _numTGrads;
    static double _sumTGrades;
};

#include "Tuniversity.h"
#include "Huniversity.h"

//initialize static variables:
int Tuniversity::_numTGrads = 0;
double Tuniversity::_sumTGrades = 0;

Tuniversity::Tuniversity(int id, char identifier, double salary, double grades)
    : University(id,identifier, salary, grades) {

    _numTGrads++;
    _sumTGrades += grades;
}

double Tuniversity::CalcGraduateAvg() {

//HERE I CAN'T access sumHGrades and numHGrades since it's private
    double A = Huniversity::_sumHGrades / Huniversity::_numHGrads;
    double T = _sumTGrades / _numTGrads;
    _normalizedGradesAvg = A / T * _gradesAvg + AVG_FACTOR;
    return _normalizedGradesAvg;

}

My design problem is how Tuniv’ reads data from Huniv’ (the two static variables).
Besides the fact that both class inherit University there is not connection between them.
I don’t want to make these variables public since its wrong.
I don’t want to make a none static virtual function GetAvg() since it will force me to create and object in order to get the data.
I tried to make virtual static function but it’s not possible.
Do you think there is a good solution to this problem (I rather not implement a static
function GetAvg() in Tuni’ and Huniv which will return the data because if i expand my program, for instance add Muniv’ there is no interface that forces the class to implement that GetAvg() function, so i consider that option a bad design).
As far as i see there is no good solution to this problem.
Using the 2 static variables in each class is my exercise requirement and i wish to consult with you before i ask my TA to change that requirement.

Thanks you all!

  • 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-16T18:00:31+00:00Added an answer on May 16, 2026 at 6:00 pm

    class Huniversity for example represents a student that graduated from H university

    So why do you call this class Huniversity and not Hstudent ?

    I think you’re mixing university and student and put them into the same class (because you also have static members representing per-university information in a class which you say represents a student). The universities could contain a vector of (pointers to) student objects where each student object contains its grade.

    I would introduce separate classes for students and make the static members for number of students and sum of grades non-static and add the method GetAvg().

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

Sidebar

Related Questions

I have the following class hierarchy [BsonKnownTypes(typeof(MoveCommand))] public abstract class Command : ICommand {
i have the following (partial) hierarchy: @MappedSuperclass public abstract class PersistentEntity { @Id @GeneratedValue(generator=system-uuid)
If I have following type hierarchy: abstract class TicketBase { public DateTime PublishedDate {
I have the following class hierarchy public abstract BaseClass : System.Web.UI.UserControl { public virtual
I have the following class hierarchy: public abstract class BaseData { //some properties }
I have the following class hierarchy. public abstract class ResourceBase { } public abstract
I have the following class hierarchy: public abstract class NumberRangeParameter<T extends Comparable<T>> extends ComplexParameter{
I have following class hierarchy: public abstract class Property<T> { private long id; private
Let's say I have the following class hierarchy: TaskViewer inherits from ListViewer<Task> which in
Let's say I have the following class hierarchy in C++: class Base; class Derived1

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.