General program logic and program design

Assignment Help C/C++ Programming
Reference no: EM133143636

CO7105 Advanced C++ Programming - University of Leicester

Task 1
The main concepts that you will be assessed in this task are memory management, operator overloading, templates, exceptions, in addition to general programming logic. You must not use any STL containers in this task.

This task builds on what was in A ssignment 1. You need to understand all the requirements of that assignment;
they will not be stated here again but they all still apply. But you do not need to "re-do" any of it: you are free to use the sample solution given there, or your previous attempt at it, as a starting point.
You will make two major changes to the BucketList data structure in Assignment 1:

Each data item to be stored is no longer just a string, but a (key, value) pair where the "keys" are strings,
and the "values" are objects of a template type T. The template parameter T can be any primitive data type (int, double, etc) or any class that has its own default constructor, copy constructor and copy assignment
(that performs deep copy where necessary), and output stream redirection operator. As long as the type T supports these operations, your code should work correctly. Note that as a result of this, the whole data structure is templated and therefore all the code should appear in BucketList.h; there will be no BucketList.cpp.

The strings are how the data items are accessed; insertion, removal, search and the mash calculations are all based on the string only, as before. The "value" object of type T is just some arbitrary data that are "carried along".

The primary part of the data structure, i.e. the table pointed to by the buckets_ pointer, is no longer an
array of Node pointers, but rather an array of Nodes. Each entry in the array is no longer a pointer to the head of a linked list, but rather the head of the linked list itself, storing the first item in this bucket. Any further entries that goes into this bucket are linked to by the next_ pointers in a linked list.

The empty string should no longer be accepted as valid input as the "key" part of any data item. You can therefore use the empty string to indicate that an entry in the buckets_ table does not store any valid data item.

As a result of these changes, the Node and BucketList classes should be modified as follows:

// you probably need this "forward declaration" template <class T> class BucketList;

template <class T> class Node {
string s_; // string stored at this node T t_; // T object stored at this node
Node* next_; // pointer to next Node in the list
...
};

template <class T> class BucketList {
Node* buckets_; // pointer to an array of Node
...
};

As before, the buckets_ array will be dynamically resized, so instead of declaring it as Node[], it is declared as
Node*.

Supported operations

You data structure should support all the functionalities in Assignment 1 (where you may need to make changes to the code to adapt to the changes above), plus the following changes/additions:

The default constructor now initialises each bucket to contain a empty data item (i.e. the string part is the empty string).

void insert(const string& s, const T& t): add the data item with key s and value t to the data structure. If the string s is already in the BucketList, replace the value object currently associated with s with the new value object t. If s is an empty string, do nothing. All other aspects are the same as before (mashing based on s, resizing, items in a bucket to be stored in alphabetical order of the strings, etc).

T operator[](const string& s) const T& operator[](const string& s)

Overloaded "subscript" operator that allows array-indexing like access of the data items. The first version returns a copy of the value object (of type T) associated the key string s stored in the data structure. The second version updates the value object associated with the key string s currently in the data structure, by returning a reference to it so that the caller can write a new value object to it.

For example, if a BucketList b contains the 7 items in the example before, then b["C++"] should return the value 4, and the line b["C++"] = 5 should set it to a new value 5.

In both cases, if there are no data item with key s in the data structure, it should throw a
std::invalid_argument exception (and make no changes to the data structure).

std::ostream& operator<<(ostream& os, const BucketList& bl): write to the output stream os a "visual" representation of the contents of the BucketList. More precisely, there should be one row per bucket. Each row begins with a number which is the index to the buckets_ array (i.e. the mash value of the strings in that bucket), followed by a space, then by each data item in the linked list of that bucket, in the order they are stored. For each data item, the key string is printed, followed by a space, followed by the value object. Between two data items, the string " -> " should be printed to separate them. The type T itself is assumed to support the << operator. For example, the BucketList above will be printed like this:

0 F# 3 -> blue 2
1
2 banana 1 3
4
5 C++ 4
6
7
8
9 abc 5 -> apple 7 -> c 3

The output consists of multiple lines, separated by the '\n' character. Please take care not to include any extra invisible whitespaces. This is to be implemented as a friend function (not a member function of Node or BucketList).

Task 2
The main concepts that you will be assessed in this task are file I/O and STL, in addition to general program logic and program design.

You will write a terminal-based version of the game Wordle. Please refer to their website for rules of the game.

Your program should first read from a file called dict.txt, from the same directory (folder) where the program runs from. This file contains a list of 5-letter words, one on each line. You can assume this file only stores 5- letter words, and all letters of all words are in lowercase, but the words are not necessarily in any sorted order. Your program must not assume any arbitrary limit on the number of words in this file. An example file can be found below.
The program should pick a random word from this file, which is going to be the answer to this game. Then the game begins: the user is given six attempts, and in each attempt is asked to type in a 5-letter word as their guess. If the user's word is not in the dictionary, the word is rejected and the user is asked to enter again (without using up an attempt). Otherwise, the program checks each letter in the user's guess and assigns a colour as follows:
If a letter is present in the answer and at the correct position, it is shown in green.
If a letter is present in the answer but not at the correct position, it is shown in yellow. If a letter is not present in the answer at all, it is shown in a normal colour.

Note however that in situations where a letter appears more than once in the guess and/or the answer, the green/yellow colouring should apply only if the matching letter has not already been "used up". For example, if

the answer is COLOR and the user guess is HELLO, only the middle L should be in green, and the other L is in normal colour. On the other hand, if the answer is HELLO and the user guess is COLOR, then only one of the two O's (doesn't matter which one) is yellow and the other L is in normal colour. Finally, if the answer is COLOR and the user guess is COOLS, the first O should be green and the second O is yellow.

If the user's guess is correct (all letters green), the game should display some simple congratulatory message and ends. Otherwise one guess is used up and the user is asked to make another guess. If after 6 guesses the user still hasn't got the correct answer, the game should display some simple "game over" message and ends.

The program should not care whether the user's inputs are uppercase or lowercase. The display of results (letters possibly with colours) should always be in uppercase.

You are encouraged to use the method in the sample code below to display coloured texts, in terminals that support them. You do not have to stick to green and yellow; you may want to change to some other colours of better visibility. Alternatively you can use some other notation to indicate the correctness of the guesses. In either case you should make clear indications as to what colours/symbols represent what. See examples below.

You are encouraged to write all your code in a single file wordle.cpp. Your program will be compiled simply by g++ wordle.cpp -o wordle. If however you choose to separate your code into multiple files, this is permitted but you must also supply a makefile so that when typing "make" it will compile your files into an executable called "wordle".

Attachment:- Resit Coursework.rar

Reference no: EM133143636

Questions Cloud

List the top three behaviors you can practice demonstrating : List the top three behaviors you can practice demonstrating that you act as a moral and ethical leader.
Cross-cultural differences in the business : 1. Think of some foreign products that are marketed in the Philippines. Have the foreign manufacturers used marketing that is sensitive to Philippine culture?
Prepare a transaction analysis for the January transactions : Prepare a transaction analysis for the January transactions - Jan 18 Performed services for customers and received cash immediately for $8,000
Prepare a brief report of energy consumption : Others worried the sustainability project was just another passing fad. A small group of colleagues believed the company should be most concerned with performan
General program logic and program design : General program logic and program design - If a letter is present in the answer and at the correct position, it is shown in green
Stage of the traditional product life cycle : Currently, which stage of the traditional Product Life Cycle (PLC) do you believe they are at? Share your opinion and support it with a relevant but brief expla
What is the couple tax on taxable income : Jane and Blair also have qualified dividend income of $3,000. What is the couple's tax on taxable income and the related tax savings from the alternative tax
Costs and benefits of government regulation : Using the concepts about the costs and benefits of government regulation, and your own experience with social media, answer the following question: should Faceb
Healthier lifestyle for everyone in the community : Review and revise your introduction paragraph. Below We live in a community not designed for physical activity. Having a park in our community will encourage us

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Generate a random number

Generate a random number between 1 – 5 and 3 – 8 for express and normal lanes, respectively. This represents the arrival time of the first customer into each lane. Set the variable for total time elapsed to 0.

  Program that asks the user to enter up to 100 integer score

Write a C program that asks the user to enter up to 100 integer scores, which are to be stored in an array. (You should allow the user to terminate input prior to entering all 100 scores.) The program should then display all the scores, ten per line,..

  Large number of files and folders

As part of her business activities, Sharon has created a large number of files and folders. Whenever she needs to view the details of the files stored in a folder, Sharon browses to the folder using Windows Explorer. However, she finds it cumberso..

  Write a program to calculate existing angles and do if and

write a program to calculate existing angles and do if and then from this and to place fixed angles at certain position

  What are abstract classes

What are abstract classes

  Research paper on c++ loop statements

Create codes for the following problem/s. Compile, test run, and edit them if necessary. Include your original .cpp and related file(s) (if any) in a single folder.

  Write a function called distance

Write a function called distance that takes two Points as arguments and returns the distance between them.

  Write a program that request a students name

Write a program that request a student's name in the subsequent form: lastName,firstName.

  Write a recursive and iterative versions of binary search

in C++ write a recursive and iterative versions of binary search and compare their run times using the array a[i]=i, i=0,..., n-1

  Write a program, use class to create many fields

Write a program, use class to create many fields: Name,DOB,Address,Class,Mark,Average mark. Allow user save data to a text file, user also can add more students, can delete student, edit info about student.

  Design a file-copying program in the c programming language

Design a file-copying program, in the C programming language, namedfilecopyusing ordinary pipes.This program will be passed two parameters: the name of the file

  Write a program to design an appointment calendar

Write a program to design an appointment calendar. An appointment includes the date, starting time, ending time, and a description.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd