Im having a issue with my employee class. The program itself has a sample employee and allows the user to input more employees to the program. The issue I am having is that I can add in 1 new employee and print the list of both the sample employee and the newly added employee, however when i try to add in a second employee and print, the second one with over write the first added employee.
Im not sure if the issue is with the array im using (which has 4 elements, number, first name, last name and department) or if its with the function thats being called, below the code ive done up.
header file:
#include <iostream>
using namespace std;
class employee
{
public :
employee();
employee(int, char*, char*, char*); // employee works number, name, department
void Set( int, char*, char*, char*); // set the number, name and dept
void Print();
void printmenu();
~employee(); //destructor
private:
int e_num; // employee number
char e_fname[30];
char e_lname [30];
char e_dept[30];
};
CPP File:
#include <iostream>
#include "employee.h"
using namespace std;
employee::employee()
{
}
employee::employee(int num, char* fname, char* lname, char* dept)
{
Set(num, fname, lname, dept);
}
void employee::Set( int num, char* fname, char* lname, char* dept)
{
if (num < 0 )
{
return ; // add in code here to give error message if works is less than 0
}
e_num = num;
strcpy (e_fname, fname);
strcpy (e_lname, lname);
strcpy (e_dept, dept);
}
void employee::Print()
{
cout << e_num <<" \t " << e_fname <<" "<< e_lname <<" \t " << e_dept << " \n";
}
void employee::printmenu()
{
cout << "EMPLOYEE MENU\n"
<< "~~~~~~~~~~~~~\n"
<< "1. Add New Employee\n"
<< "2. Edit Employee\n"
<< "3. Delete Employee\n"
<< "4. Print Employee List\n"
<< "5. Exit\n";
}
employee::~employee()
{
}
Main:
#include <iostream>
#include "employee.h"
using namespace std;
void main (void)
{
char input;
bool done = false;
employee emp1(1, "Joe", "Bloggs", "Customer Service");// sample employee
int empcount = 1;
employee empnew[20];
int num, j=0, k=0; // num is employee number
char* fname = new char [20]; // employee first name
char* lname = new char [20]; // employee last name
char* dept = new char [30]; // employee department
while(!done)
{
employee pmenu;
pmenu.printmenu();
cout <<"Please make your selection:";
cin >> input;
switch (input)
{
case '1': // add new employee
cout<<"\nEnter Employee Number:";
cin >> num;
cout<<"\nEnter first name:";
cin >> fname;
cout<<"\nEnter Last name:";
cin >> lname;
cout << "\nEnter Department:";
cin >> dept;
cout << "\n";
empnew[j].Set(num, fname, lname, dept);
empcount++;
cout << "New employee added:"<< fname <<" "<<lname << "\n";
cout<< "New Number of Employees:" << empcount<< "\n\n";
break;
case '2': //Edit Employee
// enter stuff here
break;
case '3': //Delete Employee
// enter stuff here
break;
case '4': // print employee list
cout <<"Total number of Employees:"<<empcount<<endl;
cout <<"Number \t Employee Name \t Department \n" ;
if (empcount == 1)
{
emp1.Print();
}
else
{
emp1.Print();
empnew[j].Print();//print input
}
cout <<"\n";
break;
case '5':
cout << "Program closing\n";
done = true;
break;
}
}
getchar();
return ;
}
(sorry for posting all the code, didnt want to leave something important out)
Ive tried several different ways to get the 2nd (and subsequent employee) to print but which ever way i try to change the array or the function i get errors and the code wont compile.
I thought when added the new employee to use
empnew[j]= new employee (num ,fname,lname,dept);
but that gives me "Error: no operator "=" matches these operands"
along with many other variations of that which dont work either.
As you might guess ive just started with c++ so any help would be greatly appricated.
You set employee data into empnew[j] array item, yet j variable never changes. Judging from this snippet:
empnew[j].Set(num, fname, lname, dept);
empcount++;
probably you should change into to
empnew[empcount++].Set(num, fname, lname, dept);
The new operator returns a pointer and you have an array of values.
Either you have to create an array of pointers, or (what I recommend) implement a copy-constructor and use copying:
empnew[j] = employee (num ,fname, lname, dept);
Related
I'm trying to write a C++ code for a course I'm enrolled in, where I keep the information of the students enrolled in the course.
I should be able to add a student to the classrrom in the user interface written in main , by calling the function void addNewStudent(int ID, string name, string surname), where I create my object instances, Student, and Course inside the function.
I should also be able to search by given ID by calling the function void showStudent(int ID) in the main, where the function uses the getStudent(ID) method of the object of the classCourse
I did not write all the methods, but when I try to debug this code, I got the error " Exception has occured, unknown signal error."
My questions are:
What is the reason of this error? How can I fix it?
Suppose that the user interface in the main is necessary to use as well as the functions it calls. Do I have to create a class object again inside each function as I wrote?
Can a more effective implementation be made in accordance with the object oriented principles I have defined above?
#include <iostream>
using namespace std;
#define MAX 10
class Student {
private:
int ID;
string name;
string surname;
public:
Student()
{
ID = 0;
string name = "" ;
string surname = "";
}
void setID(int ID_set);
int getID();
void setName(string name_set);
string getName();
void setSurName(string surname_set);
string getSurName();
};
class Course {
private:
Student students[MAX];
int num =0 ; // The current number of students in the course, initially 0.
float weightQ;
float weightHW;
float weightF;
public:
Course()
{
students[num] = {};
weightQ = 0.3;
weightHW = 0.3;
weightF = 0.4;
}
int getNum(); // Returns how many students are in the course
void addNewStudent(Student new_student);
void updateWeights(float weightQ_update, float weightHW_update, float weightF_update);
void getStudent(int ID_given);
};
// Method declerations for the class Student
void Student :: setID(int ID_set){
ID = ID_set;
}
int Student :: getID(){
return ID;
}
void Student :: setName(string name_set){
name = name_set;
}
string Student :: getName(){
return name;
}
void Student :: setSurName(string surname_set){
surname = surname_set;
}
string Student :: getSurName(){
return surname;
}
// Method declerations for the class Course
int Course :: getNum(){
return num;
}
void Course :: addNewStudent(Student new_student){
students[num] = new_student ;
num = num + 1;
}
void Course :: updateWeights(float weightQ_update, float weightHW_update, float weightF_update){
weightQ = weightQ_update;
weightHW = weightHW_update;
weightF = weightF_update;
}
void Course :: getStudent(int ID_given){
for(int i = 0; i<MAX; i++){
if(ID_given == students[i].getID()){
cout << "Student Name & Surname : " << students[i].getName() << " " << students[i].getSurName()<<"\n";
}
}
}
void addNewStudent(int ID, string name, string surname){
Student student;
Course ECE101;
student.setID(ID);
student.setName(name);
student.setSurName(surname);
ECE101.addNewStudent(student);
}
void showStudent(int ID){
Course ECE101;
ECE101.getStudent(ID);
}
int main(){
Course ECE101;
cout << "Welcome to the ECE101 Classroom Interface"<<"\n";
cout << "Choose your option\n";
string option_1 = "1) Add a student ";
string option_2 = "2) Search a student by ID";
cout << "Enter your option: ";
int x;
int ID;
string name, surname;
cin >> x;
if (x == 1)
cout << "Enter the student ID ";
cin >> ID;
cout << endl;
cout << "Enter the student name ";
cin >> name;
cout << endl;
cout << "Enter the student surname " ;
cin >> surname;
addNewStudent(ID, name, surname);
return 0;
}
To make the menu more interactive you could add a do while statement that would accept 3 options:
register
show data
exit
int main(){
Course ECE101;
int x;
int ID;
string name, surname;
string option_1 = "1) Add a student\n";
string option_2 = "2) Search a student by ID\n";
cout << "Welcome to the ECE101 Classroom Interface\n";
cout << "Choose your option\n";
cout << option_1 << option_2;
cin >> x;
do {
if (x == 1) {
cout << "Enter the student ID ";
cin >> ID;
cout << endl;
cout << "Enter the student name ";
cin >> name;
cout << endl;
cout << "Enter the student surname " ;
cin >> surname;
addNewStudent(ID, name, surname, ECE101);
}
else {
cout << "Enter the student ID\n";
cin >> ID;
showStudent(ID, ECE101);
}
cout << "Choose your option\n";
cin >> x;
} while(x != 3);
return 0;
}
addnewStudent() and showStudent() methods now accepts an instance of Course as an argument to be able to add students.
void addNewStudent(int ID, string name, string surname, Course &course) {
Student student;
student.setID(ID);
student.setName(name);
student.setSurName(surname);
course.addNewStudent(student);
}
void showStudent(int ID, Course &course) {
course.getStudent(ID, course);
}
the function is modified from the same class as well.
void Course::getStudent(int ID_given, Course &course) {
for(int i = 0; i<MAX; i++){
if(ID_given == students[i].getID()){
cout << "Student Name & Surname : " << students[i].getName() << " " << students[i].getSurName()<<"\n";
}
}
}
Demo
Your addNewStudent function creates a new course everytime it is called. You could pass a reference to the course as a parameter into the function and call Course.addNewStudent(student). You'll want to make sure you specify it's a reference though when you define your function or you'll just create a copy of the course.
I tried this code but when I am calling the member function inside the loop it is giving the garbage value of the details and when I am calling the member function outside the loop it is giving me error.
#include<iostream>
#include<string.h>
using namespace std;
class student
{
char name[10];
int id,rollno;
public:
student(char name[10],int id,int rollno)
{
strcpy(this->name,name);
this->id=id;
this->rollno=rollno;
cout<<"the name of the student is:"<<name<<endl;
cout<<"the id of the student is:"<<id<<endl;
cout<<"the roll no of the student is:"<<rollno<<endl;
}
};
int main()
{
int id1,rollno1;
char name1[10];
for(int i=1;i<=2;i++)
{
cout<<" enter the detail of the student "<<i<<" "<<endl;
cout<<"enter the name of the student:";
cin>>name1;
cout<<"enter the id of the student:";
cin>>id1;
cout<<"enter the roll no of the student:";
cin>>rollno1;
student d[]={student(name1,id1,rollno1)};
d[i].print();
}
return 0;
}
Here's your code review.
#include <iostream>
#include <string.h>
using namespace std; // it is strongly suggested that you don't use the whole header unless your intent is speeding up coding
class Student // capitalize classes
{
char _name[10];// it is ok, however, if you use the <string> header, why would you go back to char type?
int _id, _rollno;
public:
Student(char name[10] /* this is just the array's first item passed! */, int id, int rollno)
{
// Don't use this->, use an underscore for one of the names.
// I use underscores for the encapsulated data
strncpy_s(_name, name, 9);// a safer version
_id = id;
_rollno = rollno;
cout << "\nCtor says: ";
cout << "the name of the student is: " << _name << endl;
cout << "the id of the student is: " << _id << endl;
cout << "the roll no of the student is: " << _rollno << endl;
cout << '\n';
}
const char* getName() { return _name; }
const int getId() { return _id; }
const int getRollNo() { return _rollno; }
// unless you overload operator<< , you have to make getters for your info, or make it public
};
int main()
{
int id, rollno;// why 1? they won't intersect with the function
char name[10];
Student *s[2];//you must make that on the heap; otherwise you need a default constructor
for (int i{ 0 }; i < 2; i++)// start with 0 and make it just <
{
cout << "enter the details of the student " << i << endl;// Why so many spaces?
cout << "enter the name of the student: "; // add space after the colon
cin >> name;// remember, you're limited to 9 chars + \n !!!
cout << "enter the id of the student: ";
cin >> id;
cout << "enter the roll no of the student: ";
cin >> rollno;
//student d[] = { student(name,id,rollno) }; // you can't do this. It's not flexible.
// You either assign enough space for the intended number of students in the stack, statically, or
// you lett it find more space in the heap = dynamically
//this goes to the heap
s[i]= new Student( name,id,rollno );// parentheses are well
//s[i] = new Student{ name,id,rollno };// initializer list may also do
//d[i].print();// what's to print here? It's not POD, cout needs instructions
cout << "Stored data -> Id: " <<
s[i]->getId() << ", Name: " // -> dereferences the pointer, and s is a pointer now
<< s[i]->getName() << ", Roll no: "
// or you can dereference it
<< (*s[i]).getRollNo()
<< endl << endl; // make some extra space here
}
return 0;
}
This is the question my teacher gave me:
Construct a structure Employee that consists of the following fields:
ID, name, degree, age
A function that creates an object (a variable of Employee type), fills it from the user the, then returns it.
A function that receives an object (a variable of Employee type) and prints its fields.
Inside the main function:
Ask the user to specify the number of employees.
Create a dynamic array of the size specified by the user for the employees.
Inside a loop, fill the array elements one at a time by calling the first function.
Inside another loop, print the array elements one at a time by calling the second function.
I tried to solve it although I didn't understand it and this is what I have, Pleas help:
struct Employee
{
int ID;
char name[10];
char degree;
int age;
};
int fillin()
{ Employee employee;
cout<<"Enter employee ID, NAME, DEGREE and AGE:\n";
cin>>employee.ID;
cin>>employee.name;
cin>>employee.degree;
cin>>employee.age;
}
int print()
{
Employee employee;
cout<<"ID: "<< employee.ID<<" , ";
cout<<"NAME: "<< employee.name<<" , ";
cout<<"Degree: "<< employee.degree<<" , ";
cout<<"AGE: "<< employee.age<<".\n ";
}
int main()
{
int num;
cout<<"Enter number of employees: ";
cin>> num;
string *name= new string[num];
for(int i = 0; i < num;i++)
{
name[i]=fillin();
}
for(int j : name){
print();
}
return 0;
}
A function can have parameters and return a value. So here, fillin should return an Employee object, and print should take an Employee (or better a const reference) parameter:
Employee fillin()
{ Employee employee;
cout<<"Enter employee ID, NAME, DEGREE and AGE:\n";
cin>>employee.ID;
cin>>employee.name;
cin>>employee.degree;
cin>>employee.age;
return employee; // return the local object
}
void print(const Employee& employee)
{
cout<<"ID: "<< employee.ID<<" , ";
cout<<"NAME: "<< employee.name<<" , ";
cout<<"Degree: "<< employee.degree<<" , ";
cout<<"AGE: "<< employee.age<<".\n ";
}
Your main function could become:
int main()
{
int num;
cout<<"Enter number of employees: ";
cin>> num;
Employee *name= new Employee[num];
for(int i = 0; i < num;i++)
{
name[i]=fillin();
}
for(int i=0; i<num; i++){
print(name[i]);
}
return 0;
}
Of course, you should check that the input methods return valid values (check cin after each read)
There are several issues with the code, below is the working example.
the functions should receive and return parameters somehow, references are used in the code
array should be of appropriate type
wrong iterator used
However, keep in mind that there are more issues with the code, like no boundary checking, it is better to use STL library... consider this just as a starting point.
#include <iostream>
using namespace std;
struct Employee
{
int ID;
char name[10];
char degree;
int age;
};
int fillin(Employee& employee)
{
cout<<"Enter employee ID, NAME, DEGREE and AGE:\n";
cin>>employee.ID;
cin>>employee.name;
cin>>employee.degree;
cin>>employee.age;
}
int print(const Employee& employee)
{
cout<<"ID: "<< employee.ID<<" , ";
cout<<"NAME: "<< employee.name<<" , ";
cout<<"Degree: "<< employee.degree<<" , ";
cout<<"AGE: "<< employee.age<<".\n ";
}
int main()
{
int num;
cout<<"Enter number of employees: ";
cin>> num;
Employee *emp= new Employee[num];
for(int i = 0; i < num;i++)
{
fillin(emp[i]);
}
for(int j = 0; j< num; j++){
print(emp[j]);
}
return 0;
}
Employee fillin()
{
Employee employee;
cout << "Enter employee ID, NAME, DEGREE and AGE:\n";
cin >> employee.ID;
cin >> employee.name;
cin >> employee.degree;
cin >> employee.age;
return employee;
}
void print(Employee emp)
{
cout << "ID: " << emp.ID << " , ";
cout << "NAME: " << emp.name << " , ";
cout << "Degree: " << emp.degree << " , ";
cout << "AGE: " << emp.age << ".\n ";
}
This should help put you on the right track. You just need the dynamic array to accept Employee objects and then you need to supply the objects to print when you call print(someEmployeeObject) in main.
Okay, I have a variety of comments on your code. First, do not use character arrays. Use string instead:
#include <string>
struct Employee
{
int ID;
std::string name;
char degree;
int age;
};
String allows for dynamic-length strings, so if someone enters a really, really long name, you won't overrun the space. It will just handle it. Plus there are a bunch of other advantages.
Next, let's change this method just slightly:
Employee fillin() {
Employee employee;
cout<<"Enter employee ID, NAME, DEGREE and AGE:\n";
cin>>employee.ID;
cin>>employee.name;
cin>>employee.degree;
cin>>employee.age;
return employee;
}
You weren't returning anything at all, but you need to return the employee you're creating. So this is a small change.
And now a small change to the print method:
#include <iostream>
std::ostream & operator<<(std::ostream &ostr, const Employee &employee) {
{
ostr <<"ID: "<< employee.ID<<" , ";
ostr <<"NAME: "<< employee.name<<" , ";
ostr <<"Degree: "<< employee.degree<<" , ";
ostr <<"AGE: "<< employee.age<<".\n ";
return ostr;
}
Then to use it:
std::cout << employee;
This is the C++ way to do it and lets you use the exact same method if you want to dump the employee somewhere else (like a file).
And finally, small changes to your main:
#include
int main()
{
std::vector employees;
int num;
cout<<"Enter number of employees: ";
cin>> num;
for(int i = 0; i < num;i++)
{
employees.push_back(fillin());
}
for (const Employee &employee: employees) {
std::cout << employee;
}
return 0;
}
Let's talk about this. First, rather than using a fixed-length array, we're using a vector. This is a dynamic-length array similar to how string is a dynamic length string. You can push_back() to append items to the array. When defining it, you specify what it holds. So in this case, I have a vector of Employee objects.
I started with your for-loop, but I call the new version of fillin to actually get an employee record, and then I push them into the vector.
Then there's a second for-loop. You may not be familiar with this style. Basically that's a for-loop that iterates over every element of employees -- the ones we just did push_back() on. And then I use the output method I wrote earlier.
You were close. You were just missing a few key things -- basically passing elements into your methods and returning elements.
So, I am making this bank management system in c++ where I will have to give the user an option to create an account, deposit the money, withdraw it, and display the details. I also need to store in the array of objects so that the entire data can be displayed after the user exits. The restrictions are that I cannot use file handling. But it isn't working properly.
Please help.
When I run it, it keeps asking me for full name. How do I resolve this issue?
I feel like this issue is occurring because of the persons array of type bankaccount, but I don't see any other possible way to do this.
I have deleted the details of some functions because it became a lengthy block of code.
#include<iostream>
#include<string>
#include <time.h>
#include <cstdlib>
using namespace std;
class bankaccount {
private:
int id;
string name;
int cash;
int money;
int age;
public:
string get_name() {
return name;
}
int get_id() {
return id;
}
void withdraw();
void deposit();
int see_money();
bankaccount(int id1) {
id = id1;
cout << "\n Enter Full Name:";
getline(cin, name);
}
friend ostream& operator<<(ostream& os, const bankaccount& d);
};
ostream& operator<<(ostream& os, bankaccount& d) {
os << "\n Your name is:" << d.get_name();
os << "\n Your id is:" << d.get_id();
os << "\n You have a total of : " << d.see_money();
}
int main() {
bankaccount persons[100] = 0;
int option;
int id;
int number = 0;
cout << "BANKING MANAGEMENT SYSTEM!" << endl;
cout << "-------------------------------------------------------------------------------";
while (1) {
cout << "\nEnter 1 to create an account. Enter 2 to deposit money. Enter 3 to withdraw money. Enter 4 to check money. Enter 5 to display. Enter 6 to exit";
cin >> option;
switch (option) {
case 1: {
bankaccount p(number);
persons[number] = p;
cout << "Your ID is:" << number << endl;
number++;
break;
}
case 2: {
cout << "\n Enter Your ID:";
cin >> number;
persons[number].deposit();
break;
}
case 3: {
cout << "\n Enter Your ID:";
cin >> number;
persons[number].withdraw();
break;
}
case 4: {
cout << "\n Enter Your ID:";
cin >> number;
persons[number].see_money();
break;
}
case 5: {
cout << "\n Enter Your ID:";
cin >> number;
cout << persons[number];
break;
}
}
}
}
bankaccount persons[100]=0;
Here you construct 100 objects of your bankaccount.
Your bankaccount constructor has these 2 lines:
cout<<"\n Enter Full Name:";
getline(cin,name);
So each time you create a bankaccount object, you're prompted for its name. You probably didn't intend that. You need to de-couple this, so asking the user for the Full Name, assigning it to a bankaccount, and constructing a bankaccount object are separate.
e.g. you can create option 6 to assign a name to the bankaccount instead of doing it inside the constructor of your bankaccount class.
If you aren't restricted the use of pointers or you don't have to specifically store it in a static array you can try this. You can create an array of bankaccount type pointers. In this case an array of 100 pointers. Each pointer will point to a separate object of bankaccount. https://imgur.com/a/KflNVbc for a better visual understanding.
You can create it like this:
bankaccount* persons[100];
So in case 1, when you create a new account and add it to the array you can do this:
persons[number] = new bankaccount();
number++;
This way you won't have to change your constructor. Just a cool way of doing this.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
i have this c++ assignment....and iam having a bit of a problem since iam used more to c#
i created a class student in order to create an array with different elements...the problem is how can i see the array in the functions in the class part...inorder to fill it with students details and display it..here is the code:
#include <iostream>
#include <string>
#include <array>
#include <iomanip>
using namespace std;
class student{
private:
int id, age;
string fname, lname, cob;
char s;
int stdcount;
public:
void addstd();
void searchstd(int n);
void displayinfo();
void deletestd(int n);
void displayrange();
void modifyinfo(int n);
};
void student::addstd()
{
cout<<"Enter ID Number"<<endl;
cin>>id;
cout<<"Enter First Name"<<endl;
cin>>fname;
cout<<"Enter last Name"<<endl;
cin>>lname;
cout<<"Enter age"<<endl;
cin>>age;
cout<<"Enter student's Sex(F or M) "<<endl;
cin>>s;
cout<<"Enter Country of birth"<<endl;
cin>>cob;
}
void student::displayinfo()
{
for(int i=0;i<100;i++)
{
cout<<ar[i];
}
}
void student::searchstd(int m)
{
}
void main()
{
student s;
student std[100];
int choice;
do{
cout << "-----------Menu------------" << endl;
cout << " 1. Add a student " << endl;
cout << " 2. Search for student by ID " << endl;
cout << " 3. Display all students information " << endl;
cout << " 4. Remove a students " << endl;
cout << " 5. Display students aged between 34 - 50 " << endl;
cout << " 6. Modify a student's information " << endl;
cout << " 7. Exit " << endl;
cout << " Enter your choice 1, 2, 3, 4 ,5,6,7 " << endl;
cin>>choice;
switch(choice) {
case 1:
for(int i=0;i<3;i++)
{
std[i].addstd();
}
break;
case 2:
int numid;
cout <<"enter id "<<endl;
cin>>numid;
s.searchstd(numid);
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
default:
cout << "Please enter 1, 2, 3, 4, 5, 6 or 7 : " << endl << endl;
}
}while(choice!=7);
}
Your problem has very little to do with C++ and everything to do with proper design. Even if you used C#, you would have very little, if any justification for creating a student object as the way you did for C++.
First, as others have mentioned, a student should only know about themself (first name, last name). It isn't a student's responsibility to keep track of other students. A very rough design would look like this:
#include <string>
class student {
private:
int id, age;
std::string fname, lname, cob;
char s;
public:
student() {}
void setId(int n) { id = n; }
void setFirstName(const std::string& s) { fname = s; }
void setLastName(const std::string& s) { lname = s; }
//etc..
int getId() const { return id; }
std::string getFirstName() const { return fname; }
std::string getLastName() const { return lname; }
// etc...
};
That is all a student should have. Setting and getting the student's information. Nothing more, nothing less. You can embellish this by adding a constructor to easily create an entire student in one call (if you want to do this). But this is the basic gist of what a student class should look like.
Now you create an array of these students:
typedef std::array<student, 100> StudentList; // creates an array of 100 students.
or preferably, a vector< student >, so that it becomes a lot easier to handle:
#include <vector>
//..
typedef std::vector<student> StudentList;
Then you use StudentList as your array / vector of students.
It then becomes trivial when it comes to display the students -- just go through the array one by one and display the students information.
Modify your displayInfo function to take an input
void student::displayInfo(student ar[], int numStudents)
{
for(int i=0;i<numStudents;i++)
{
cout<<ar[i]; // if you have << operator defined
}
}
Then in main you could say:
student std[100];
displayInfo (std, 100); // this is passing your array in (you need to populate it though)