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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:11:54+00:00 2026-05-26T16:11:54+00:00

I am self-learning C++ from a text book and I have a problem to

  • 0

I am self-learning C++ from a text book and I have a problem to solve, outlined below.

I have the following class structure:

 #include <iostream>
 #include <cstdio>
 #include <ctime> 

 using namespace std;


   class classroom{

     char name[25];
     int student_id;
     float grades[10];
     float average;
     int num_tests;
     float letter_grade;

   public:       
     void enter_name_id(void);
     void enter_grade(void);
     void average_grades(void);
     void letter_grades(void);
     void output_name_id_grade(void);
     classroom();

   };

And I have the following Constructor for the above class:

 classroom::classroom(){

      int i;

      srand((unsigned)time(0));
      int random_integer=0; 
      random_integer = (rand()%5) + (rand()%5); 

      num_tests=0;
      average=0.0;

      for(i=0;i<10;i++){

        grades[i]=0.0;

      }

      for(i=0;i<27;i++){

         name[i]='-';       
      }
      cout<<"\n*****************Finished*****************";
 }

There will be 3 students of this class structure declared in the main:

int main()
{       
  classroom students[3]; 
//and so...

}

I need to generate a unique student ID for each student in the constructor within a range of values, say, 0 to 10.

I have copied the following code snippet into the constructor. It generates my random number for me within the desired range:

srand((unsigned)time(0));
  int random_integer=0; 
  random_integer = (rand()%5) + (rand()%5);

The problem is that I need to get rid of any duplicates within the range of random numbers that are generated.

  • 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-26T16:11:54+00:00Added an answer on May 26, 2026 at 4:11 pm

    Why does the number need to be random? Can’t you just use a static int that gets incremented every time you need to generate a new student number?

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

Sidebar

Related Questions

Hello to all that read I am self learning C++ from a text book:
Hello to all that read I am self learning C++ from a text book.
I was doing some self-learning on how to pass data from JQuery Ajax to
I am learning RoR coming from many years of c# and MSSQL. I have
I'm a beginner (self-learning) programmer learning C++, and recently I decided to implement a
I'm self-learning iPhone development and I see that one of the aspects of an
To make story short, i'm building self-learning banner management system. Users will be able
I'm trying to broaden my mind by learning Haskell. My self-inflicted homework was to
[[self mainFrame] loadHTMLString:@<html><body><link href='main.css' rel='stylesheet' type='text/css' /></body></html> baseURL:nil]; I am trying to load a
I am doing some self-learning about JQuery and stuck over a question: I am

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.