CO7105 Advanced C++ Programming Assignment

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

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 Assignment 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.

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. (See e.g. https://www.cplusplus.com/reference/cstdlib/rand/ on how to generate random numbers in C++.) 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:- memory management.rar

Reference no: EM133141514

Questions Cloud

What amount should be reported as bond interest expensed : Interest is payable semiannually January 1 and July 1. For the six months ended June 30, 2020, what amount should be reported as bond interest expensed
Determine the amount of capital loss carry forward : Silver has no un-recaptured net §1231 losses, and it made no other sales during the year. Determine the amount of capital loss carry forward
Important personal leadership learning : Describe the most important personal leadership learning you have taken from this class. Describe at least two effective ways organizations use symbols
Prepare journal entries on the books of veronica company : Before occupancy, the lessee incurred leasehold improvement of Php600,000 with useful life of 5 years. Prepare journal entries on the books of Veronica Company
CO7105 Advanced C++ Programming Assignment : CO7105 Advanced C++ Programming Assignment Help and Solution, University of Leicester - Assessment Writing Service
What is the company total budget for the next year : Interest expense = $37,750, 10-year fixed interest rate loan. What is the company's total budget for the next year for the four selected items
Explain concept of regression : Explain the concept of regression and point out its importance in business forecasting. Point out the role of regression analysis in business decision-making.
How much is the depreciation for the year : An accounting change was made in 2024 to reflect these additional data. How much is the depreciation for the year 2022
What challenges can investment managers face : What challenges can investment managers face and what recommendations would you make in effort to meet these challenges?

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

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