Question

In: Computer Science

Create an unsorted LIST class. Each list should be able to store 100 names.

Create an unsorted LIST class. Each list should be able to store 100 names.

Solutions

Expert Solution

C++ code to implement an unsorted LIST class:

#include <iostream>

using namespace std;

class LIST {
   private:
    string names[100];
    int size;      // Number of elements in the list
    int capacity;  // Total capacity of the list

   public:
    LIST();
    string get(int index);
    void add(string name);
    void print();
};

// Constructor to initialize variables
LIST::LIST() : capacity(100), size(0) {}

// Function to get a name at particular index
string LIST::get(int index) {
    return names[index];
}

// Function to add a name
void LIST::add(string name) {
    if (size >= capacity)
        return;  // Addition failed
    names[size] = name;
    size++;
}

// Function to print the list
void LIST::print() {
    for (int i = 0; i < size; i++) {
        if (i == size - 1)
            cout << names[i] << endl;
        else
            cout << names[i] + ", ";
    }
}

int main() {
    LIST names;
    names.add("John");
    names.add("Jack");
    names.add("Holly");
    cout << "Name at index 2: " << names.get(2) << endl;
    cout << "Names: ";
    names.print();
    return 0;
}

Output:

Kindly rate the answer and for any help just drop a comment


Related Solutions

Create an ADT class that creates a friend contact list. The program should be able to...
Create an ADT class that creates a friend contact list. The program should be able to add, remove and view the contacts. In C++
Create a Python program that will take an unsorted list of 1000 integers and sort them...
Create a Python program that will take an unsorted list of 1000 integers and sort them using a bubble sort and an insertion sort. Your output should include displaying both sorted lists (from each algorithm) identifying each sorted list by the algorithm used.
Create an array list (names) that will hold the names of several hall of fame soccer...
Create an array list (names) that will hold the names of several hall of fame soccer players. 2. Place your name on the screen as the master recorder:              “Master Hall of Fame Recorder: John Paul Jones” 3. Ask the user how many names they would like to record. (input 5 when the program runs) 4. Create a loop that will ask for the “Hall of fame member #1: “, etc Add in the following names: Pele Rooney Maradona Messi...
I need to be able to store 5000 names into an array. I currently have a...
I need to be able to store 5000 names into an array. I currently have a code that generates one random name. I just need to generate an array of 5000 the same way. #include <cstdlib> #include <ctime> #include <iostream> #include <iomanip> using namespace std; string RandomFirstGen(int namelength); int main(){ srand(time(NULL)); int namelength = rand()%(16-8+1)+8; cout<<"name is: "<<RandomFirstGen(namelength)<<endl; return 0; } string RandomFirstGen(int namelength){ for (int i=0; i<=5000 ; i++){ const int MAX = 26; char alphabet[MAX] = { 'a',...
Build a simple list implementation that uses arrays to store the values. Create a class SimpleArrayList...
Build a simple list implementation that uses arrays to store the values. Create a class SimpleArrayList with a public constructor that initializes the list using a passed array of Object references. Assert that the passed array is not null. Next, implement: 1)Object get(int), which takes an int index and returns the Object at that index 2)void set(int, Object), which takes an int index and an object reference and sets that value at the index to the passed reference Both your...
how do I create a graph class to store a adjacency list representation of a graph?...
how do I create a graph class to store a adjacency list representation of a graph? I need some help and dont conpletely understand how to start. if you could provide a code with some steps id appreciate it.
JavaScript - Create a class using "names" as the identifier. Create a constructor. The constructor must...
JavaScript - Create a class using "names" as the identifier. Create a constructor. The constructor must have elements as follow: first ( value passed will be String ) last ( value passed will be String ) age ( value passed will be Numeric ) The constructor will assign the values for the three elements and should use the "this" keyword Create a function, using "printObject" as the identifier printObject: This function will have three input parameters: allNames , sortType, message...
Create a Class to contain a customer order Create attributes of that class to store Company...
Create a Class to contain a customer order Create attributes of that class to store Company Name, Address and Sales Tax. Create a public property for each of these attributes. Create a class constructor without parameters that initializes the attributes to default values. Create a class constructor with parameters that initializes the attributes to the passed in parameter values. Create a behavior of that class to generate a welcome message that includes the company name. Create a Class to contain...
Create a table of the different classes of neurotransmitters . List names of neurotransmitters, their main...
Create a table of the different classes of neurotransmitters . List names of neurotransmitters, their main functions and implications in human disease.
Create a table of the different classes of neurotransmitters. List names of neurotransmitters, their implications in...
Create a table of the different classes of neurotransmitters. List names of neurotransmitters, their implications in human disease,  and their main functions .
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT