Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a Class ArrayListClass in C++ Create an array class that has an array of

ID: 3681491 • Letter: C

Question

Create a Class ArrayListClass in C++

Create an array class that has an array of 27 List Classes

Ignore index 0... Indexes 1...26 correspond to the first letter of a Last name.

Again - ignore index 0. index 1 is A, index 2 is B, index 3 is C... index 26 is z.

Create a file of 260 random ordered last names... 10 each for each letter...

Read in the file one name at a time, store/add each Name in the correct index LIST element.

Search for a Name to see if it in the LIST class.

Print out the ALL names found on each list..

Basically,What I understand is our professor wants us to write a program can sort name and when we press A, it can print all names start with A. But the Program I tried was always overflow while printing out the names.

please someone helps me with the assignment with an proper soultion that meets the requirment.

Explanation / Answer

Note: Please create a list of 260 last names and then run the program

#include<string.h>
#include<iostream>
#include <fstream>

using namespace std;
class ListClass{
private:
char lastname[10][20];
int index;
public:
ListClass(){
index=0;
}
void setLastName(char name[20]){
strcpy(lastname[index++],name);
}
void printLastNames(){
int i;
for(i=0;i<10;i++){
cout<<lastname[i]<<endl;
}
}
int find(char name[20]){
int i;
for(i=0;i<10;i++){
if(strcmp(lastname[i],name)==0){
return i+1;
}
}
return 0;
}
};

class ArrayListClass{
private:
ListClass arrayListClass[27];
public:
void add(int index,char lastname[20]){
arrayListClass[index].setLastName(lastname);
}
void printNames(int index){
cout<<"List "<<char(index+64)<<":"<<endl;
cout<<"******"<<endl;
arrayListClass[index].printLastNames();
}
int find(char lastname[20]){
int i;
for(i=1;i<27;i++){
if(arrayListClass[i].find(lastname)){
return 1;
}else{
return 0;
}
}
}
};

int main(){
ArrayListClass a;
ifstream infile("d:\lastnames.txt"); //change the filename accordingly
char lastname[20];
while(infile>>lastname){
a.add(lastname[0]-64,lastname);
}
int i;
cout<<"Displaying all the lists ";
for(i=1;i<3;i++){
a.printNames(i);
}
cout<<" *****Searching for ABC*****";
if(a.find("ABC")){
cout<<" ABC is found in the list";
}else{
cout<<" ABC is NOT found in the list";
}
if(a.find("EFG")){
cout<<" EFG is found in the list";
}else{
cout<<" EFG is NOT found in the list";
}
}