BEST代写-线上编程学术专家

Best代写-最专业靠谱代写IT | CS | 留学生作业 | 编程代写Java | Python |C/C++ | PHP | Matlab | Assignment Project Homework代写

C++代写 | COSC1076 | Semester 1 2020 Final 1-2 Day Assessment

C++代写 | COSC1076 | Semester 1 2020 Final 1-2 Day Assessment

这个作业是用C++完成一个卡片游戏
COSC1076 | Semester 1 2020  
Final 1-2 Day Assessment
Instructions:  
Complete your answers to all parts of question in the files question1.cpp  
Use comments to clearly indicate where the answer to each part is located in the head-  
er/source files.  
This question contains 3 parts.  
Part A (4 marks)  
Implement a function called duplicates_def that:  
Takes an array of C-Strings, called strings1  
Takes a second array of C-Strings, called strings2  
Produces a new array of C-strings that contains all strings that occur in both string1 and  
string2.  
Returns the arrays of C-strings that was produced (through either the return value of the  
function, or a separate parameter to the function)  
For example, if strings1 is the array  
[
8dhb”,  
dhd4″,  
9hdh”  
]
and strings2 is the array  
[
,
5*@1″,  
9hdh”  
]
It will produce and return the following array of C-strings:  
[
9hdh”  
]
Implement this function using a defensive programming paradigm. That is, your function should  
account for all possible inputs.  
Additionally in implementing your function:  
Choose suitable parameters for the function, so that your it can be fully defensive.  
Choose appropriate types for the parameters  
Ensure that your function does not crash or seg-fault.  
You may not use any methods of the C++ STL, except for the iostream header file for  
reading/writing to and from standard I/O.
Part B (3 marks)  
Implement a second version of the function in Part A, called duplicates_pbc, using a programming-  
by-contract paradigm. That is, you should:  
Define a suitable contract for the function.  
Choose suitable parameters for the function, so that your it can be fully defensive.  
Choose appropriate types for the parameters  
Implement the function according to this contract.  
Use suitable C++ language features to enforce compile-time aspects of the contract where  
possible.  
Part C (3 marks)  
Compare and Contrast your two implementations from Parts A and B. Write the answer to this  
question as a comment in the question1.cpp source file.  
As part of your comparison, you should write a full C++ program (including main function) that  
calls both versions of your functions. Your program should show that both functions work correctly,  
and also highly the similarities and differences between both implementations.  
Continued . . .
Question 2: Abstract Data Types (10 marks)  
Instructions:  
Complete your answers to this question in the files:  
Card.h and Card.cpp  
Deck.h and Deck.cpp  
Pile.h and Pile.cpp  
CardSet.h and CardSet.cpp  
Use comments to clearly indicate where the answer to each part is located in the head-  
er/source files.  
In this course, we have examined list and tree structures using the game Red7 as an example. In  
this question, you will design ADTs for 3 variations of a collection of Red7 cards. (Note that you  
do not need to be familiar with the rules of Red7 to answer this question). These variations are:  
1
2
3
. A Deck of Red7 Cards  
. A Pile of Red7 Cards  
. A CardSet of Red7 Cards  
These will also be implemented as a class hierarchy, so take careful note of this as it will significantly  
affect your design and implementation.  
Design & Functionality  
To help you in this question, the implementation of an ADT for a Red7 Card has been provided.  
This contains useful methods for helping to implement the ADTs. Although you are free to change  
this implementation as you desire.  
The Deck ADT must function as a stack of Red7 Cards, supporting the following functionality:  
1
2
3
4
. Add a Red7 Card to the top of the Deck  
. Examine the top card of the Deck  
. Remove the top card of the Deck  
. Check if the Deck is empty (that is, has no cards)  
The Pile ADT must function as a list of Red7 Cards, supporting the following functionality:  
1
2
3
4
. Get the size of the Pile  
. Look at a card at any position within the Pile, using the overloaded operator: operator[]  
. Add a card to the end of the Pile  
. Remove a card from any position within the Pile  
The CardSet ADT must function as a set of Red7 Cards. This is a list (or collection) of cards  
where all card are unique, that is there must not be any duplicated cards in the list/collection.  
Comparing cards for equality is given by the comparison operator operator== on the Card ADT.  
The CardSet should support the following functionality:  
1
2
3
. Get the size of the CardSet  
. Add a card to the CardSet, ensuring only unique cards are added  
. Display the cards of the CardSet using the overloaded operator: operator<<  
You are free to choose a suitable underlying representation for the ADT(s) from the following list:  
Continued . . .
Single or double-ended linked list  
C++14 STL ordered container (array, vector, list, deque, stack, queue)  
C++14 STL associative container (set, map)  
Class Hierarchy  
Your implementation must use the following class hierarchy:  
The CardSet class must be a sub-class of the Deck class  
The Pile class must be a sub-class of the CardSet class  
Marking (10 marks)  
Implement a C++ class for each of the 3 ADTs described above. The marks are distributed as  
follows:  
Deck (2 marks)  
Pile (2 marks)  
CardSet (3 marks)  
ADT design and code re-use (3 marks)  
You must not implement any other classes.  
You will be marked on the quality of your design, not just the functionality of each class. Therefore  
your implementation you should consider:  
Abstraction, such as the scope (public, protected private) of variables and methods to ensur-  
ing only the desired functionality is available in the public interface to the ADT.  
Encapsulation, by keeping code to within the most relevant ADT and class.  
Computational efficiency, such that you should avoid computational inefficient operations.  
Minimising code duplication through Code Re-use.  
Minimising re-implementing features across the ADTs.  
Inheritance principles, such as virtual methods, and calling constructors and destructors.  
Make sure you briefly describe (in code comments) any choices that you made, as poor choices will  
results in a mark deduction.  
To help you get started, the following page(s) provide a simple implementation of a Red7 Card,  
including suitable comparison operators.  
Continued . . .  
Card.h  
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
#ifndef CARD_H  
#define CARD_H  
#include <string>  
enum Colour {  
RED,  
ORANGE,  
YELLOW,  
GREEN,  
BLUE,  
INDIGO,  
VIOLET  
};  
1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
2
2
2
2
3
3
3
3
3
3
3
3
3
3
4
4
4
4
4
/**  
* Represents a Card in Red7.  
*/  
class Card {  
public:  
Card(Colour colour, int number);  
Card(Card& other);  
Card();  
/**  
* Get the Card colour  
*/  
Colour getColour();  
/**  
* Get the Card number  
*/  
int getNumber();  
bool operator==(const Card& other) const;  
bool operator<(const Card& other) const;  
private:  
};  
Colour  
int  
colour;  
number;  
#endif // CARD_H  
Continued . . .
Card.h  
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
#include “Card.h”  
Card::Card(Colour colour, int number) :  
colour(colour),  
number(number)  
{
}
Card::Card(Card& other) :  
Card(other.colour, other.number)  
{
}
1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
2
2
2
2
3
3
3
3
C}ard::Card() {  
Colour Card::getColour() {  
return colour;  
}
int Card::getNumber() {  
return number;  
}
bool Card::operator==(const Card& other) const {  
return number == other.number &&  
colour == other.colour;  
}
bool Card::operator<(const Card& other) const {  
return colour < other.colour  
(colour == other.colour && number < other.number);  
}
Continued . . .
Question 3: Critical Analysis (10 marks)  
Instructions:  
Complete your answers to this question in the files:  
Complete your written analysis in the file question3.pdf  
Complete your code portion in the file question3.cpp  
Provide a clear and concise answer to the question.  
The C++14 language has many features and an extensive library in the STL. These give developers  
great flexibility in implementing their software, however, these also give a developer significant  
avenues to create poor software.  
The following are two features from the C++14 language and/or STL:  
Polymorphism of Class types  
auto type keyword  
Discuss how the above two language features can be used to create well-design and error free  
software. As part of your discussion you may wish to consider concepts from this course such as  
(
but not limited to):  
Writing correct and error free software  
Code Re-use  
Memory Management  
Computation Efficiency  
Code Style and Layout  
Abstraction  
Data Structures  
Type Systems  
As part of your discussion you must create two code examples:  
1
. The first code example should use both of the above features to clearly demonstrate show  
their benefits. For full marks, this example should combine both features.  
2
. The second code example should show how the first example could be implemented without  
using the above features.  
Your discussion should compare and contrast the two code examples.  
Limit the discussion to relevant information. You are marked on your ability to be selective, clear,  
and complete in the information you choose to provide. Answers that contain incorrect or irrelevant  
information may not receive full marks.  
Your discussion must be no more than 1 A4, 12pt font, 2cm margins and single-space.  
Marking  
The marks for this question are divided as follows:  
Discussion (5 marks)  
Code examples (5 marks)  
Write your critical analysis in the file question3.pdf, and place your code examples in the file  
question3.cpp. Use comments to indicate the various aspects of your code examples.  
End of Questions – Appendices to follow
Appendix A: Submission Instructions  
Combined all of the files for the questions into a single ZIP file called s3713737.zip. Upload this  
file to the Canvas assessment module for the 1-2 Day Assessment.  
You must also include this PDF files of questions in your ZIP.  
ONLY submit the above files in your ZIP. Any additionally files will not be marked  
!
Appendix B: Late Submission Policy  
Ensure that you give yourself sufficient time to prepare and submit your work  
!
The submission is a hard deadline. That is, there will be no leeway on late submissions. The late  
submission policy is:  
20% penalty if submitted up to 1 hour late  
50% penalty if submitted up to 2 hours late  
Grade of 0 is submitted 2 or more hours late  
Appendices | FINAL PAGE  
bestdaixie