Deleting specific class objects stored in an array C++

#include<iostream>
#include<conio.h>
#include<stdlib.h>
using namespace std;
class student{
public:
int id;
string name;
string sex;
int age;
float eng;
float math;
float com;
float total;
float average;
void inputdata();
void outputdata();
};
void student::inputdata(){
cout<<“ID :”;cin>>id;
cout<<“Name :”;cin>>name;
cout<<“Sex :”;cin>>sex;
cout<<“Age :”;cin>>age;
cout<<“Math :”;cin>>math;
cout<<“Eng :”;cin>>eng;
cout<<“Com :”;cin>>com;
total=math+eng+com;
average=total/3;
}
void student::outputdata(){
cout<<id<<“\t”<<name<<“\t”<<sex<<“\t”;
cout<<age<<“\t”<<math<<“\t”<<eng<<“\t”;
cout<<com<<“\t”<<total<<“\t”<<average<<“\n”;
}
int main(){
int n,i,k,ID,AGE;
float a;
string NAME,SEX;
char z;
student x[30];
AEU:
cout<<“\n1. Add Data to Class”;
cout<<“\n2. Delete Data from Class”;
cout<<“\n3. Display Data from Class”;
cout<<“\nPlease Select: “;cin>>n;
switch(n){
case 1:
cout<<“\nInput Name Of Student:”;cin>>k;
for(i=0;i<=k-1;i++)
x[i].inputdata();
break;
case 2: // can’t delete object in an array
cout<<“\n\nEnter the ID you wanna delete : “;cin>>ID;
x[ID-1]=x[ID];
break;
case 3:
cout<<“\nResult from Class: \n”;
cout<<“ID\tName\tSex\tAge\tMath\tEng\tCom\tTotal\tAverage\n\n”;
for(i=0;i<=k-1;i++)
x[i].outputdata();
break;
default:
cout<<“Wrong Number…!”;
}
cout<<“\nPress Key to back to Menu.”;
getch();
system(“cls”);
goto AEU;
}

Leave a Reply

Your email address will not be published. Required fields are marked *