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
(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...
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,...
IN JAVA Iterative Linear Search, Recursive Binary Search, and Recursive Selection Sort: <-- (I need the...
IN JAVA Iterative Linear Search, Recursive Binary Search, and Recursive Selection Sort: <-- (I need the code to be written with these) I need Class river, Class CTRiver and Class Driver with comments so I can learn and better understand the code I also need a UML Diagram HELP Please! Class River describes river’s name and its length in miles. It provides accessor methods (getters) for both variables, toString() method that returns String representation of the river, and method isLong()...
MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment:...
MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment: MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment: In cryptography, encryption is the process of encoding a message or information in such a way that only authorized parties can access it. In this lab you will write a program to decode a message that has been encrypted using two different encryption algorithms. Detailed specifications: Define an...
In C++ Employee Class Write a class named Employee (see definition below), create an array of...
In C++ Employee Class Write a class named Employee (see definition below), create an array of Employee objects, and process the array using three functions. In main create an array of 100 Employee objects using the default constructor. The program will repeatedly execute four menu items selected by the user, in main: 1) in a function, store in the array of Employee objects the user-entered data shown below (but program to allow an unknown number of objects to be stored,...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT