Question: , create two files: Block.h (class definition) and Block.cpp (class implementation). The following UML describes the class: Member Variables: The id variable of the Block

, create two files: Block.h (class definition) and Block.cpp (class implementation). The following UML describes the class: Member Variables: The id variable of the Block is initialized through the input parameter of the Block constructor. txCount is a variable that keeps track of the number of Transaction objects added to the Blocks transaction list, and has an initial value of zero. MAX_TX refers to the maximum number of transaction objects that a Block can accept and is set to a constant value of 5 for this assignment. txList is a one-dimensional dynamically allocated array that contains pointers to Transaction objects. The array is instantiated to contain MAX_TX objects during Block initialization. blockHash holds the final hash value (described in a later section) of the block contents, and is initialized to an empty string. prevBlockHash contains the hash value of the contents of the last block in the blockchain, upon which the current block builds. The variable is initialized to the value of the second argument of the Block constructor. minerName refers to the name of the blocks owner. A block can only be created by a miner. This value is set through the constructor via the last argument. 6 Block - id : int - txCount : int - MAX_TX : int - txList : Transaction** - blockHash : string - prevBlockHash : string - minerName : string - confirmed : bool + Block(i : int, prevh : string, n : string): + Block(other: Block&) + ~Block(): + getId(): int + canAddTransaction(): bool + addTransaction(t : Transaction*): void + addTransaction(f : string, t : string, s : string, a : float ): void + getTransaction(i : int): Transaction* + getNumTransactions(): int + setBlockHash(h : string): void + getBlockHash(): string + getPreviousBlockHash(): string + getMinerName(): string + confirm(): void + isConfirmed(): bool + printBlockSummary(): void confirmed is a variable that indicates if a block has been added to the blockchain, thus confirmed. It is initially set to false. Member Functions: Block constructors: both the normal and copy constructor should dynamically allocate memory for the Transaction list array, txList, that will contain the dynamic Transaction objects associated with the block. The rest of the variables should be initialized as mentioned above or based on the copied object (in the case of the copy constructor). ~Block() should deallocate all dynamically created memory. getId() returns the Block id. canAddTransaction() - checks if a Transaction pointer can still be added to the transaction list (i.e. if the number of transactions does not supersede the allocated space) addTransaction(Transaction* t) - creates a deep copy of the given Transaction * object and adds the copy to the first available position of the blocks 7 transaction list. If the transaction list is full, the function should not copy or add the object but print the following statement instead: "Maximum entries of transactions reached. The block cannot accept any more transactions." addTransaction(string f, string t, string s, float a) - dynamically allocates a Transaction object with the given parameters and stores the new object in the next available position of the transaction list. If the transaction list is full, the function should not create or add the object but print the following statement instead: "Maximum entries of transactions reached. The block cannot accept any more transactions." getTransaction(int i) - retrieves a Transaction* object from the blocks transaction list at the given index i. If the index is out of bounds, the function should print out "Block transaction retrieval unsuccessful: index out of bounds." and return a null pointer. getNumTransactions() - returns the number of transactions currently in the block. setBlockHash(string h) and getBlockHash() - store and return the blocks hash string variable respectively getPreviousBlockHash() - returns the hash string of the previous block as recorded from the constructor. getMinerName() - returns the name of the miner associated with the block. confirm() - sets the confirmed status of the block to true. It then cascades the newly confirmed status to the transactions it holds, by setting the confirm status of every transaction in its list to true. It would typically be called upon when a block has been added to the blockchain. isConfirmed() - returns the confirmed status of the block printBlockSummary() - prints out certain properties of the block and the transactions it holds. The content and format of the summary should be as shown in the image below. Set the column widths as you see fit, but take care to use the same labels as those in the figure.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!