C++ hw7 | Computer Science homework help
Introduction
We have discussed ?inheritance?, one of the fundamental concepts of Object Oriented Programming (OOP). In this homework we will experience inheritance concept through C++ programming to reinforce what we have learned in class. We will extend Sequence class to create Gene class. We also create a driver program to test each function in Gene class.
ÿ
Instructions: Download starter code from [emailÿprotected] under Content (Homework). Then implement Gene.h and Gene.cpp and create a tester program.
ÿ
In the Visual Studio project, there are three files:
úÿÿÿÿÿÿÿÿ Sequence.h: Sequence class hearder file
no change required
úÿÿÿÿÿÿÿÿ Sequence.cpp: Sequence class implementation file
no change required
úÿÿÿÿÿÿÿÿ GeneTest.cpp: a driver program that tests Gene class implementation
ÿ
Sequence
–ÿÿÿÿÿÿÿÿÿ sequence: char*
–ÿÿÿÿÿÿÿÿÿ length: int
+ Sequence(string s)
+Sequence(const Sequence& s) //Copy constructor
+Sequence& operator=(const Sequence& s) //Assignment operator
+void set(int index, char c) //Set character at index to value in c
+ ~Sequence()
+ getSequence() const :char*
+ size() const :int
Friend functions
+ bool operator==(const Sequence& lhs, const Sequence&rhs)
+ostream& operator<< (ostream&ostr, constSequence&g)
+ bool operator<( const Sequence& lhs, const Sequence&rhs)
ÿ
Gene
ÿ
+ Gene(string s)
+Gene(const Gene& g)//Copy constructor
+Gene& operator=(const Gene& g) //Assignment operator
+ ~Gene()
+ aCount() const:int
+ cCount() const :int
+ tCount() const :int
+ gCount()const :int
For this assignment you will design a C++ class to store information about a Gene using the existing Sequence class. Starter code includes sequence class declaration (Sequence.h) and member function implementation (Sequence.cpp).
ÿ
The SequenceClass:ÿ This class simulatesa sequence in biology.ÿ
Data Members
Array of characters for each element in the sequence. Each element is represented by a character. The array is allocated during object construction.
length to represent the number of elements in the Sequence.
Member Functions
Constructor that takes in a string object representing the Sequence.
A string object in C++ has the following useful methods:
ÿsize()
[index] that returns the character at each index.
Initialize the data members using this input by determining the size of input string and then creating and filling sequence.ÿ
Destructor to deallocate memory allocated by the constructor (Do last)
Copy Constructor
Assignment operator=
set(): void sets character at index to value in c.
getSequence():char* returns a pointer to the start of the sequence array.
size():int returns the number of elements in the sequence (chars)
Friend Functions
Operator== that returns true if the Sequences have the same size and exactly the same sequence. Note that an equal sequence could be listed in reverse order.
Operator<< to output the sequence with up to 40 characters per line.
Operator<ÿ checks to see if the sequence on the left hand side is a subsequence of the right hand sequence. The entire subsequence must be found in the right hand sequence to be true otherwise return false. Note again that the reverse of the subsequence may be contained in the sequence.
ÿ
ÿ
ÿ
The GeneClass:ÿ This class should simulate a gene in biology.ÿ
Member Functions
Constructor that takes in a string object representing the Gene.
Use the string to call the Sequence constructor
Copy Constructor (also in Sequence)
Assignment operator operator= (also in Sequence)
Destructor to deallocate memory used on the heap.
aCount():int returns the count of nucleotides in gene represented by a.
cCount():int returns the count of nucleotides in gene represented by c.
tCount():int returns the count of nucleotides in gene represented by t.
gCount():int returns the count of nucleotides in gene represented by g.
ÿ
Must have exact method header in code as in the UML so that a different tester file can be used to grade the assignment.
ÿ
Task #1 Coding the UML Diagrams (20 points)
ÿ
Create the header file Gene.h including all functions and data members. It will inherit from Sequence. You must use the exact names described in the UML diagram. I will provide a test file to test your code and calculate the grade.
ÿ
Create the implementation file Gene.cpp and a tester file named GeneTester.cpp.
Add a single function implementation at a time.
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ i.ÿÿÿÿÿ Constructor
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ii.ÿÿÿÿÿ aCount(), cCount(), tCount(), and gCount()
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ iii.ÿÿÿÿÿ Destrutor
After each file is implemented create an object in the main method of GeneTester to test the implementation. Be sure to test all aspects of each function thinking about boundary cases.
ÿ
3.ÿÿÿÿÿ After each file is implemented create an object in the main method of GeneTest to test the implementation. Be sure to test all aspects of each function.
ÿ
Task #2 Testing
ÿ
I will provide tester program to be downloaded from D2L. It will test your code to see that the implementations are correct. You will need to replace this tester program with yours.
ÿ
ÿ
Submission note: You do NOT NEED TO SUBMIT ANYTHING TO THE DROPBOX!ÿ Instead, you will need to show your programs for your answers to the instructor or SIs during class.
ÿ
