Objectives: 1. Review reading from a file. 2. Use structures. 3. Use ...

carpentergambrinousΑσφάλεια

3 Δεκ 2013 (πριν από 3 χρόνια και 8 μήνες)

115 εμφανίσεις


Computer Science 1
-

Program 1

Bitcoin Pooling

Assigned: 8/22/2011

Due: 9/7
/2011 (
Wednesday
) BY

11:55pm (Submit on Webcourses)


Objectives:

1.

Review reading from a file.

2.

Use structures.

3.

Use Dynamic Memory Allocation.

4.

Create and use a dynamically allocated array of structs.

5.

To use enumerated types.


Problem

Description:

Bitcoin is a peer
-
to
-
peer currency which manages transactions col
lectively through the Bitcoin
network. Bitcoins can be used as a form of payment at websites that accept them, or traded
directly for US currency. Every transaction that has ever been made using Bitcoins is stored in
an encrypted transaction log called t
he block chain, which consists of a sequence of records
called blocks. All computers in the network have a copy of the block chain which they keep
updated by passing along new blocks to each other. This ensures that nobody is able to fake any
transaction
s


Anyone can join this network by installing Bitcoin software, and as an incentive for users to keep
this software running a bounty is awarded to users who participate in Bitcoin mining. Through
mining, users create blocks for the block chain in a way th
at is impossible to predict or reverse.
The user who produces the first valid block for each round is awarded a bounty of 50 Bitcoins
.


You have decided to operate a Bitcoin mining pool, where a large group of users collaborate to
distribute the work of g
enerating a block amongst themselves. Each new block in the pool is
divided into much easier problems, which are sent out to the individual users. The solutions are
then combined and tested to see if they create a valid block.
The winnings for contribut
ing
segments to the block are the following
, use enumerated types fo
r the number of segments
matched
:










Your server is lacking one final piece
before you are able to get the mining pool online. For each
successfully mined block, the server generates a text file which lists the partial solutions
generated f
rom
each user as well as the completed block which was accepted.
Your task is to use
this
data to determine how many Bitcoins each contributing user is given, using the tools you
have learned so far in CS1.


Implementation
:

You must use the exact struct as follows:

Number Segments

Winnings

1 segment

10$

2 segments

20$

3 segments

30$

4 segments

40$

5 segments

50$


typedef struct PartialBitcoinSolution {


char firstName[20];


char lastName[20]
;


int numSegs;


int
*
hash;

} BCSolution
;


Note: Because of the typedef you can use “BCSolution” instead of “struct
PartialBitcoinSolution” when referencing this structure throughout the program.


Input File Specification (
Bitcoin.in
)
:

You will read an inp
ut
from a file named “
Bitcoin
.in
”.
The first line will contain the number of
test cases in the file.
The
n the

first line

for each test case

will contain

two

integer
s
m

and

n
,
where
m

is the total number of unique users that have contributed this round

an
d
n

is the number
of user submissions
.
Since a user may submit multiple answers,
m <= n
.


The next line will contain a 25 digit number, which is the final valid block created from the
user’s partial solutions. Each block is divided into 5 equal segments,

so that each user generates
a 5 digit number as part of the sequence.


The sequence “11111

22222

33333

44444

55555” is divided into the following 5 digit segments:


segment 1: 11111

segment 2: 22222

segment 3: 33333

segment 4: 44444

segment 5: 55555


The
next 2n lines will contain information about each
user’s created
segment
s
. The information
for a
those

segment
s

will be on two lines. The first line will contain the name of the user
followed by the number of segments they contributed that round. The se
cond line contains the
list of the segments contributed. Each unit of data is separated by a space.


Sample Input File
:

1

5

7

67465

50276

15107

63278

76475

Kelly Sedlak 1

76475

Guy Hemmingway 2

15107

98731

Darryl Goncalves 1

13951

Odessa Fleurant 2

66508
67465

Max Stacker 4

63278
94661
50276

60655

Guy Hemmingway 2

15107

98731

Odessa Fleurant 2

66508
67465


Output Specification:

Your output should contain one winner per line. Each line of output should be of the following
format:


Test Case #i:

First Last
matched X segments and won $Y.


where
i is the 1
-
based test case number,
First is the first name of the winner, Last is the last name
of the winner, X is the number of winning
segments

the player
created

correctly, and Y is the
prize money won.


CAUTION!

Y
our output format must adhere to the specification above EXACTLY. If there are any extra
spaces or grammatical errors the diff program the TA’s are using to grade will count that line as
wrong. The TA’s can go back and fix these errors, but that wastes t
heir valuable time


and will
cost you
5
-
10 points off of your grade
!


Sample Output File

(saved to Bitc
oin.out)
:

Test Case #1:

Kelly
Sedlak matched 1 segments and won $10

Guy
Hemmingway matched 1 segments and won $10

Odessa
Fleurant matched 1 segments and

won $10

Max
Stacker matched 2 segments and won $20


Grading Criteria
:

1) Adher
e

to t
he implementation specifications
.

2) Your algorithmic design.

3) Correctness.

4)
Use of Dynamic Memory Allocation. If your program does NOT use DMA, you will NOT
get c
redit for the assignment.

5) The frequency and utility of the comments in the code, as well as the use of white space for
easy readability. (We're not kidding here. If your code is poorly commented and spaced and
works perfectly, you could earn as low as
80
-
85% on it.)

6
) Your output MUST adhere to the EXACT output format shown above.

7) Use enumerated types for the number of segments matched.


Restrictions

Name the file you create and turn in
Bitcoin
.c
.
Your program MUST read from an input file
named
Bitcoint.in, and write to an output file name Bitcoin.out


this is important to the
grading process and will cost you up to 10 points if not done correctly.

Although you may
use other compilers, your program must compile and run using
Dev C++.


Your prog
ram should
include a header comment with the following information: your name, course number, section
number, assignment title, and date. You should also include comments throughout your code,
when appropriate.


Deliverables

A single source file named
Bi
tcoin
.c
turned in through WebCourses.