Hi, I am new to this forum and this is my first post and I have been learning c++ by myself online as well as from a refernce book but I have encountered a problem in this book.
The question is :-
Define a class named Admission in C++ with following description?
Private members:
admno integer (Ranges 10-1500)
name string of 20 characters
cls integer
fees float
Public members:
A constructor which initialized admno with 10, name with “NULL”, cls with 0 & fees with 0
Function getdata() to read the object of Admission type.
Function putdata() to print the details of object of admission type.
Function draw_nos() to generate the admission no. randomly to match with admno and display the detail of object.
and here is my code but it is not giving expected results, I think that the problem is in draw_nos()function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<conio.h>
class admission
{
int admno;
char name[20];
char cls;
float fees;
public :
void readdata();
void display();
int drawnos();
int adnos(){
return admno;
}
};
void admission::readdata()
{
cout<<"Enter the admission no"<<endl;
cin>>admno;
cout<<"Enter the name"<<endl;
gets(name);
cout<<"Enter the class and fees"<<endl;
cin>>cls;
cout<<"Enter the fees"<<endl;
cin>>fees;
}
void admission::display()
{
cout<<"Admission no. : "<<admno<<endl;
cout<<name;
cout<<"\nclass : "<<cls<<endl;
cout<<"Fees : "<<fees<<endl;
}
int admission::drawnos()
{
int r1;
srand(time(0));
r1=(rand()%2000)+10;
return r1;
}
int main()
{
clrscr();
admission ad[5],ad1;
int po;
for(int n=0;n<5;n++)
{
cout<<"Enter the details of "<<n+1<<" student "<<endl;
ad[n].readdata();
}
for(int x=0;x<10;x++)
{
po=ad1.drawnos();
if(ad[x].adnos()==po)
{
ad[x].display();
break;
}
}
getch();
return 0;
}
|
Please help me