Question

Part 1 - LIST Create an unsorted LIST class ( You should already have this code...

Part 1 - LIST

Create an unsorted LIST class ( You should already have this code from a prior assignment ). Each list should be able to store 100 names.

Part 2 - Create a Class ArrayListClass

It will contain an array of 27 "list" classes.

Next, create a Class in which is composed a 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 names starting with 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… FileName: Names.txt

Have an constructor function that Reads in the Names.txt file, one name at a time, store/add each Name in the correct index LIST element.

Write a function that can Search for a Name to see if it in the LIST class.

Write a function that will print out the names starting with a specific letter, prints just ONE list.

Write a Function that can print out the ALL names found on each list..

HUGE HINT.. create a LIST class first, each that can hold 10 names.. Then create a class the can hold an array of 27 list classes.

Homework Answers

Answer #1

C++ CODE:

#include<bits/stdc++.h>
using namespace std;

string Last(string p){
int i,l=p.size();
string k;
for( i = 0 ; i < l ; i++ ){
if(p[i] == ' ')
k="";
else
k+=p[i];
}
return k;
}

class LIST{
  
list<string> List;

public :

void push(string name){
(this->List).push_back(name);
}

int Size(){
return (this->List).size();
}

void print(){
list <string> :: iterator it;
for(it = (this->List).begin(); it != (this->List).end(); ++it)
cout <<*it<<" ";
}

bool check(string name){
list <string> :: iterator it;
for(it = (this->List).begin(); it != (this->List).end(); ++it)
if(name == *it)return true;
return false;
}

};
class Array_ListClass{
LIST arr[27];
public :
Array_ListClass(){
ifstream fin;
fin.open("Output.txt");
if(!fin){
printf("Error in file opening\n");
}else{
printf("File is ready to read\n");
while(fin){
string name;
getline(fin,name);
if(name.size() > 0){
//cout<<name<<endl;
string s=Last(name);
int n = (int)s[0];
(this->arr[n-'A'+1]).push(name);
}
}
fin.close();
}
}
void print_All_Names(){
for( int i =1 ; i < 27 ; i++ ){
printf("Names at index %d : ",i);
(this->arr[i]).print();
cout<<endl;
}
}
void print(int n){
printf("Names with %c : ",n+'A'-1);
(this->arr[n]).print();
cout<<endl;

}
bool check(string name,string s){
int n = (int)s[0];
return (this->arr[n-'A'+1]).check(name);
}
};
int main(){
ofstream fout;
fout.open("Output.txt");
string s="";
int i,j,m;
if(!fout){
printf("Error in creating file\n");
}else{
for( i = 0 ; i < 260 ; i++ ){
s += 'A' + (i/10);
for( m =1 ; m < 10 ; m++ ){
j = rand()%26;
s += 'A'+j;
}
fout<<s<<"\n";
s="";
}
}
printf("File is created\n");
fout.close();
Array_ListClass obj;
printf("Enter name to search\n");
getline(cin,s);
  
if(obj.check(s,Last(s))){
printf("Present\n");
}
else{
printf("Not Present\n");
}
printf("Enter character to print name with that character\n");
getline(cin,s);
s=Last(s);
obj.print(s[0]-'A'+1);
obj.print_All_Names();
return 0;
}

OUTPUT SCREENSHOT:

I hope you like the code and explanation, don't forget to give UPVOTE as it means a lot...THANKS:)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In c++ create a class to maintain a GradeBook. The class should allow information on up...
In c++ create a class to maintain a GradeBook. The class should allow information on up to 3 students to be stored. The information for each student should be encapsulated in a Student class and should include the student's last name and up to 5 grades for the student. Note that less than 5 grades may sometimes be stored. Your GradeBook class should at least support operations to add a student record to the end of the book (i.e., the...
(EXCEL VBA)Create a new worksheet and name it as “Roster”.You have the class roster in the...
(EXCEL VBA)Create a new worksheet and name it as “Roster”.You have the class roster in the worksheet “Roster” and the full names of students are in column A, starting in Cell A3, with last name last and case insensitive (such as Ben ALT). Write a sub that counts the number of names in the list with last name ALT and then displays this count in an MsgBox that is titled “Number of ALTs” and has an Exclamation icon button. Note...
Create a program that allows the user to input a list of first names into one...
Create a program that allows the user to input a list of first names into one array and last names into a parallel array. Input should be terminated when the user enters a sentinel character. The output should be a list of emial addresses where the address is of the following form: [email protected] Declare FirstName[100] as String Declare LastName[100] as String Declare email as String Declare K as Integer Declare index as Integer Write "Enter first and last name." Write...
Write Python code to define a class called Student. The Student class should have the following...
Write Python code to define a class called Student. The Student class should have the following private fields: name – to store the name of a student attend – to store how many times a student attend the class grades – a list of all student’s grades The Student class should have the following methods: a constructor getter method for the name field attendClass method: that increments the attend field (should be called every time a student attends the class)....
Create a stadium class. The class header file content (.h file) can go in this question,...
Create a stadium class. The class header file content (.h file) can go in this question, the class implementation (.cpp file) can go in the following question, and the main.cpp content can go in the third question. static data members: starting seat number next seat number data members: stadium name name of home team current opponent seats sold (vector of seat numbers) member functions: custom constructor - take input of stadium name default constructor get next seat number (static) change...
write code using python or repl.it 1. List 4 attributes that you'd create for class "student"....
write code using python or repl.it 1. List 4 attributes that you'd create for class "student". 2. List 2 setters and 2 getters for class student including their parameters 3. Write the complete definition for class student including attributes and methods created above using the correct Python syntax. 4. Create one object of class student and print the values of all its attributes. You can either call the getter method or access the attribute directly using the dot notation.
Assignment Statement Use the skeleton file starter code (below) to create the following classes using inheritance:...
Assignment Statement Use the skeleton file starter code (below) to create the following classes using inheritance: ⦁   A base class called Pet ⦁   A mix-in class called Jumper ⦁   A Dog class and a Cat class that each inherit from Pet and jumper ⦁   Two classes that inherit from Dog: BigDog and SmallDog ⦁   One classes that inherit from Cat: HouseCat The general skeleton of the Pet, Dog, and BigDog classes will be given to you (see below, "Skeleton", but...
Java code Problem 1. Create a Point class to hold x and y values for a...
Java code Problem 1. Create a Point class to hold x and y values for a point. Create methods show(), add() and subtract() to display the Point x and y values, and add and subtract point coordinates. Tip: Keep x and y separate in the calculation. Create another class Shape, which will form the basis of a set of shapes. The Shape class will contain default functions to calculate area and circumference of the shape, and provide the coordinates (Points)...
Create a class called BirthYear. It should only have two member, both of them arrays. One...
Create a class called BirthYear. It should only have two member, both of them arrays. One of type string called Names. The second of type int called BirthYears. in your main class create a StudentBirthYear object. Make sure both arrays are of the size 10. Add ten different names and ten different birth years. Then display each name with its birth year using only 1 for loop. (You can display in a for loop as well as a foreach loop,...
Write a Java class called CityDistances in a class file called CityDistances.java.    2. Your methods...
Write a Java class called CityDistances in a class file called CityDistances.java.    2. Your methods will make use of two text files. a. The first text file contains the names of cities. However, the first line of the file is a number specifying how many city names are contained within the file. For example, 5 Dallas Houston Austin Nacogdoches El Paso b. The second text file contains the distances between the cities in the file described above. This file...