Sie sind auf Seite 1von 3

#include <iostream>

#include <string.h>
#include <iomanip> //For formatting output
#include <set>
#include<conio.h>
using namespace std;

struct StudentProfile {
string userid;
string userName;
string subject;
string degreeName;
string uniName;
};

class ArrayList {
private:
StudentProfile* arr;
int current;
int listSize;
public:
ArrayList();
void add(StudentProfile student);
StudentProfile find(int x);
void update(int postition, StudentProfile student);
void remove(int x);
int listLenght();
void showList();
void cmpStdRec(StudentProfile x, StudentProfile y);
~ArrayList();
};
ArrayList::ArrayList() {
arr = new StudentProfile[6];
listSize = 0;
current = 0;
}
void ArrayList::add(StudentProfile x) {
arr[listSize] = x;
listSize++;
current = listSize;
}
StudentProfile ArrayList::find(int x) {
return arr[x];
}
void ArrayList::update(int position, StudentProfile student) {
arr[position] = student;
}
void ArrayList::remove(int x) {
arr[x].userid = "";
arr[x].userName = "";
arr[x].subject = "";
arr[x].degreeName = "";
arr[x].uniName = "";
}
int ArrayList::listLenght() {
return listSize;
}
void ArrayList::showList() {
cout << std::left << setw(2) << "Sr: ID Name
Subject Deg Uni " << endl;
for (int i = 0; i <= listSize; i++) {
if (arr[i].userid != "") {
cout << std::left << setw(2) << i + 1 << " " << arr[i].userid
<< " " << arr[i].userName << " " << arr[i].subject << "
" << arr[i].degreeName << " " << arr[i].uniName << endl;
}
}
}
ArrayList::~ArrayList() {
delete[]arr;
}
int main() {
cout <<
"----------------------------------------------------------------------------------
------\n";
cout << "Array List of Student Data......\n\n ";
ArrayList StudentArray;
StudentProfile std1, std2, std3, std4, std5, std6;
std1.userid = "BC10000000";
std1.userName = "InfoP";
std1.subject = "CS301";
std1.degreeName = "BSCS";
std1.uniName = "VU";

std2.userid = "BC20000000";
std2.userName = "Waqas";
std2.subject = "CS301";
std2.degreeName = "BSCS";
std2.uniName = "VU";

std3.userid = "BC30000000";
std3.userName = "Ahmed";
std3.subject = "CS301";
std3.degreeName = "BSCS";
std3.uniName = "VU";

std4.userid = "BC40000000";
std4.userName = "Amir";
std4.subject = "CS301";
std4.degreeName = "BSCS";
std4.uniName = "VU";

std5.userid = "BC50000000";
std5.userName = "Sajjad";
std5.subject = "CS301";
std5.degreeName = "BSCS";
std5.uniName = "VU";

StudentArray.add(std1);
StudentArray.add(std2);
StudentArray.add(std3);
StudentArray.add(std4);
StudentArray.add(std5);
StudentArray.showList();

cout <<
"----------------------------------------------------------------------------------
------\n ";
cout << "\nFind 4th Student Record......\n ";
//cout << "Record with id "+std4.userid+ " found at 4th Position\n ";
StudentProfile found = StudentArray.find(3);
cout << "\n Record with id " <<found.userid << " found at 4th position."
<<endl ;
cout <<
"----------------------------------------------------------------------------------
------\n\n ";
cout << "Update 4th Student Record...\n\n ";
StudentArray.update(3, std1);

StudentArray.showList();
cout <<
"----------------------------------------------------------------------------------
------\n\n ";

cout << "Remove 4th Student Record...\n\n ";


StudentArray.remove(3);

StudentArray.showList();
cout <<
"----------------------------------------------------------------------------------
------\n\n ";

cout << "\n Lenght of the ArrayList is " <<


StudentArray.listLenght()<<"." << endl ;
cout << "\nPress any Key to Close the Window........";
getch();
return 0;
}

Das könnte Ihnen auch gefallen