Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
22 views2 pages

Assignment 3

This document provides instructions for a programming assignment to work with array-based lists. Students are asked to: 1. Modify an existing array-based list class to double the array size when the list is full during insertion. 2. Create a Student class with attributes for name, ID, and GPA. Generate 1,000,000 Student objects with unique IDs and insert into an ordered array list, timing binary vs linear searches. 3. Add a removeAll method to a list class to remove all occurrences of an element, and test the method. 4. Add a findAll method to return the locations of all occurrences of an element. 5. Add a min method to return

Uploaded by

ezzsawalmeh101
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views2 pages

Assignment 3

This document provides instructions for a programming assignment to work with array-based lists. Students are asked to: 1. Modify an existing array-based list class to double the array size when the list is full during insertion. 2. Create a Student class with attributes for name, ID, and GPA. Generate 1,000,000 Student objects with unique IDs and insert into an ordered array list, timing binary vs linear searches. 3. Add a removeAll method to a list class to remove all occurrences of an element, and test the method. 4. Add a findAll method to return the locations of all occurrences of an element. 5. Add a min method to return

Uploaded by

ezzsawalmeh101
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Data structure – List Programming Assignment 3

Adnan Salman

Objective: To learn how to use array-based list.

1) The array-based list discussed in class displays a message and exits the program if we try to
insert an item into a full list. Instead, we can grow the size of the list whenever it is full. In
this assignment, your task is to double the size of the array list whenever we try to insert it
into a full list.

2) Write a class Student that has the following 3 attributes

class Student {
public:
// add any necessary public methods
private:
string name;
string id;
float gpa;
}
Then generate 1000,000 object of type student and insert them in an ordered array list. Each
student object must have a unique id. Use the following functions to generate unique Ids.

string generateUniqueId() {
string uniqueId;
time_t now = time(nullptr);
uniqueId = to_string(now);
random_device rd;
mt19937 gen(rd());
uniform_int_distribution<int> dist(1000, 9999);
int randomNumber = dist(gen);
uniqueId += to_string(randomNumber);
return uniqueId;
}

Also, you can use the following function to generate names of some length.

string generateArbitraryName(int length) {


string name;
random_device rd;
mt19937 gen(rd());
uniform_int_distribution<int> dist('a', 'z');
for (int i = 0; i < length; ++i) name += char(dist(gen));
return name;
}

Measure the time needed to search for an item that is not in the list using the binary search
method compared to the linear search. You can use one of the following codes to measure the
required time:

using namespace std;


using namespace std::chrono;

int main() {

auto start = high_resolution_clock::now();


// code to time
auto stop = high_resolution_clock::now();
duration<double> duration = duration_cast<microseconds>(stop - start);
cout << "Time taken by function: " << duration.count() << " microseconds" <<
endl;
return 0;
}

Or

#include <time.h>
using namespace std;

int main() {
time_t begin, end;
time(&begin);
// code to time
time(&end);
time_t elapsed = end - begin;

printf("Time measured: %ld seconds.\n", elapsed);


return 0;
}

Note: co compare different student objects for the binary search, you need to overload the
three operator (==, <, >) of the class Student.

3) The function remove of the class UnorderedArrayList removes only the first occurrence of an
element. Add the function removeAll to the class UnorderedArrayList that would remove all
occurrences of a given element. Also, write the definition of the function removeAll and a
program to test this function

4) Add a function findAll (item) to the class UnorderedArrayList that finds all occurrences of
the item “item” and returns a list of integers that contains the locations of these occurrences.
5) Add the function min to the class UnorderedArrayList to return the smallest element of the
list. Also, write the definition of the function min and a program to test this function.

Grading
1) If the program doesn’t compile, you will get 0, otherwise, each part worth 12 points = 5 *
12 = 60
2) 15 points comments + program organization.
3) 15 points if there is a submission.
4) 10 points up to the grader to decide.

Good luck

You might also like