Free Essay

Code

In:

Submitted By user777
Words 4248
Pages 17
This is CS50. Harvard College Fall 2010

Problem Set 3: The Game of Fifteen

due by 7:00pm on Fri 10/1

Per the directions at this document’s end, submitting this problem set involves submitting source code on cloud.cs50.net as well as filling out a Web-­‐based form (the latter of which will be available after lecture on Wed 9/29), which may take a few minutes, so best not to wait until the very last minute,

lest you spend a late day unnecessarily.

Be sure that your code is thoroughly commented to such an extent that lines’ functionality is apparent from comments alone.

Goals.

• Introduce you to larger programs and programs with multiple source files. • Empower you with Makefiles. • Implement a party favor.

Recommended Reading.

• Section 17 of http://www.howstuffworks.com/c.htm. • Chapters 20 and 23 of Absolute Beginner’s Guide to C. • Chapters 13, 15, and 18 of Programming in C.

0 < 12

This is CS50. Harvard College Fall 2010

Academic Honesty.

All work that you do toward fulfillment of this course’s expectations must be your own unless collaboration is explicitly allowed in writing by the course’s instructor. Collaboration in the completion of problem sets is not permitted unless otherwise stated by some problem set’s specification.

Viewing or copying another individual’s work (even if left by a printer, stored in an executable directory, or accidentally shared in the course’s virtual terminal room) or lifting material from a book, website, or other source—even in part—and presenting it as your own constitutes academic dishonesty, as does showing or giving your work, even in part, to another student. Similarly is dual submission academic dishonesty: you may not submit the same or similar work to this course that you have submitted or will submit to another. Nor may you provide or make available solutions to problem sets to individuals who take or may take this course in the future. Moreover, submission of any work that you intend to use outside of the course (e.g., for a job) must be approved by the staff.

You are welcome to discuss the course’s material with others in order to better understand it. You may even discuss problem sets with classmates, but you may not share code. In other words, you may communicate with classmates in English, but you may not communicate in, say, C. If in doubt as to the appropriateness of some discussion, contact the course’s instructor.

You may turn to the Web for instruction beyond the course’s lectures and sections, for references, and for solutions to technical difficulties, but not for outright solutions to problems on problem sets or your own final project. However, failure to cite (as with comments) the origin of any code or technique that you do discover outside of the course’s lectures and sections (even while respecting these constraints) and then integrate into your own work may be considered academic dishonesty.

All forms of academic dishonesty are dealt with harshly. If the course refers some matter to the Administrative Board and the outcome for some student is Warn, Admonish, or Disciplinary Probation, the course reserves the right to impose local sanctions on top of that outcome for that student that may include, but not be limited to, a failing grade for work submitted or for the course itself.

Grades.

Your work on this problem set will be evaluated along three primary axes.

Correctness. To what extent is your code consistent with our specifications and free of bugs? Design. To what extent is your code written well (i.e., clearly, efficiently, elegantly, and/or logically)? Style. To what extent is your code readable (i.e., commented and indented with variables aptly named)?

1 < 12

This is CS50. Harvard College Fall 2010

Getting Started.

 SSH to cloud.cs50.net and execute the command below.1

cp -r ~cs50/pub/src/psets/pset3 ~

That command will copy the staff’s pset3/ directory, inside of which is some “distribution code,” files (and subdirectories) that you’ll need for this problem set, into your own home directory. The -r switch triggers a “recursive” copy. Navigate your way to your copy by executing the command below.

cd ~/pset3/

If you list the contents of your current working directory (remember how?), you should see the below. If you don’t, don’t hesitate to ask the staff for assistance.



fifteen/

find/

As this output implies, your work for this problem set will be organized within two subdirectories. Don’t forget about help.cs50.net! Not only can you post questions of your own, you can also search for or browse answers to questions already asked by others. And never fear asking “dumb questions.” Students’ posts to the course’s bulletin board are anonymized. Only the staff, not fellow students, will know who you are!2 Be sure, too, to attend or watch this problem set’s walkthrough, the video for which will be available at http://www.cs50.net/psets/.

And, of course, there are plenty of office hours: http://www.cs50.net/ohs/.

1

Note that there’s a space between pset3 and that last tilde (~), the latter of which, recall, represents your home directory. 2 Thus, only we will make fun.

2 < 12

This is CS50. Harvard College Fall 2010

Find.

 Now let’s dive into the first of those subdirectories. Execute the command below.



cd ~/pset3/find/

If you list the contents of this directory, you should see the below. helpers.c

helpers.h

Makefile

find.c

generate.c

Wow, that’s a lot of files, eh? Not to worry, we’ll walk you through them. Implemented in generate.c is a program that uses rand to generate a whole bunch of pseudorandom numbers, one per line.

(Remember rand from Problem Set 1?) Go ahead and compile this program by executing the command below.

make generate

Now run the program you just compiled by executing the command below.

./generate

You should be informed of the program’s proper usage, per the below. Usage: generate n [s]

As this output suggests, this program expects one or two command-­‐line arguments. The first, n, is required; it indicates how many pseudorandom numbers you’d like to generate. The second, s, is optional, as the brackets are meant to imply; if supplied, it represents the value that the pseudorandom-­‐number generator should use as its seed. (Remember from Problem Set 1 what a seed is?) Go ahead and run this program again, this time with a value of, say, 10 for n, as in the below; you should see a list of 10 pseudorandom numbers.

./generate 10

Run the program a third time using that same value for n; you should see a different list of 10 numbers. Now try running the program with a value for s too (e.g., 0), as in the below. ./generate 10 0

Now run that same command again: ./generate 10 0

Bet you saw the same “random” sequence of ten numbers again? Yup, that’s what happens if you don’t vary a pseudorandom number generator’s initial seed.

3 < 12

This is CS50. Harvard College Fall 2010



Now take a look at generate.c itself with Nano. (Remember how?) Comments atop that file explain the program’s overall functionality. But it looks like we forgot to comment the code itself.

Read over the code carefully until you understand each line and then comment our code for us, replacing each TODO with a phrase that describes the purpose or functionality of the corresponding line(s) of code. Realize that a comment flanked with /* and */ can span lines whereas a comment preceded by // can only extend to the end of a line; the latter is a feature of C99 (the version of C that we’ve been using). If Problem Set 1 feels like a long time ago, you might want to read up on rand and srand again at the URLs below. http://www.cs50.net/resources/cppreference.com/stdother/rand.html http://www.cs50.net/resources/cppreference.com/stdother/srand.html Or you can execute the commands below. man rand man srand

Once done commenting generate.c, re-­‐compile the program to be sure you didn’t break anything by re-­‐executing the command below.

make generate

If generate no longer compiles properly, take a moment to fix what you broke! Now, recall that make automates compilation of your code so that you don’t have to execute gcc manually along with a whole bunch of switches. Notice, in fact, how make just executed a pretty long command for you, per the tool’s output. However, as your programs grow in size, make won’t be able to infer from context anymore how to compile your code; you’ll need to start telling make how to compile your program, particularly when they involve multiple source (i.e., .c) files.

And so we’ll start relying on “Makefiles,” configuration files that tell make exactly what to do. How did make know how to compile generate in this case? It actually used a configuration file that we wrote. Using Nano, go ahead and look at the file called Makefile that’s in the same directory as generate.c. This Makefile is essentially a list of rules that we wrote for you that tells make how to build generate from generate.c for you. The relevant lines appear below. generate: generate.c gcc -ggdb -std=c99 -Wall -Werror -Wformat=0 -o generate generate.c

The first line tells make that the “target” called generate should be built by invoking the second line’s command. Moreover, that first line tells make that generate is dependent on generate.c, the implication of which is that make will only re-­‐build generate on subsequent runs if that file was modified since make last built generate. Neat time-­‐saving trick, eh? In fact, go ahead and execute the command below again, assuming you haven’t modified generate.c.

make generate

4 < 12

This is CS50. Harvard College Fall 2010



You should be informed that generate is already up to date. Incidentally, know that the leading whitespace on that second line is not a sequence of spaces but, rather, a tab. Unfortunately, make requires that commands be preceded by tabs, so be careful not to change them to spaces with Nano (which automatically converts tabs to four spaces), else you may encounter strange errors! The -Werror flag, recall, tells gcc to treat warnings (bad) as though they’re errors (worse) so that you’re forced (in a good, instructive way!) to fix them.

Now take a look at find.c with Nano. Notice that this program expects a single command-­‐line argument: a “needle” to search for in a “haystack” of values. Once done looking over the code, go ahead and compile the program by executing the command below.

make find

Notice, per that command’s output, that Make actually executed the below for you. gcc -ggdb -std=c99 -Wall -Werror -Wformat=0 -o find find.c helpers.c -lcs50 -lm

Notice further that you just compiled a program comprising not one but two .c files: helpers.c and find.c. How did make know what to do? Well, again, open up Makefile to see the man behind the curtain. The relevant lines appear below.

find: find.c helpers.c helpers.h gcc -ggdb -std=c99 -Wall -Werror -Wformat=0 -o find find.c helpers.c -lcs50 -lm

Per the dependencies implied above (after the colon), any changes to find.c, helpers.c, or helpers.h will compel make to rebuild find the next time it’s invoked for this target. Go ahead and run this program by executing, say, the below. ./find 13

You’ll be prompted to provide some hay (i.e., some integers), one “straw” at a time. As soon as you tire of providing integers, hit ctrl-­‐d to send the program an EOF (end-­‐of-­‐file) character. That character will compel GetInt from the CS50 Library to return INT_MAX, a constant that, per find.c, will compel find to stop prompting for hay. The program will then look for that needle in the hay you provided, ultimately reporting whether the former was found in the latter. In short, this program searches an array for some value. In turns out you can automate this process of providing hay, though, by “piping” the output of generate into find as input. For instance, the command below passes 1,024 pseudorandom numbers to find, which then searches those values for 13.

./generate 1024 | ./find 13

Alternatively, you can “redirect” generate’s output to a file with a command like the below. ./generate 1024 > numbers.txt

5 < 12

This is CS50. Harvard College Fall 2010

You can then redirect that file’s contents as input to find with the command below. ./find 13 < numbers.txt

Let’s finish looking at that Makefile. Notice the line below. all: find generate

This target implies that you can build both generate and find simply by executing the below. make all

Even better, the below is equivalent (because make builds a Makefile’s first target by default). make

If only you could whittle this whole problem set down to a single command! Finally, notice these last lines in Makefile: clean: rm -f *.o a.out core find generate

This target allows you to delete all files ending in .o or called a.out, core (tsk, tsk), find, or generate simply by executing the command below. make clean



Be careful not to add, say, *.c to that last line in Makefile! (Why?) Any line, incidentally, that begins with # is just a comment. And now the fun begins! Notice that find.c calls sort, a function declared in helpers.h.

Unfortunately, we forgot to implement that function fully in helpers.c! Take a peek at helpers.c with Nano, and you’ll see that sort returns immediately, even though find’s main function does pass it an actual array. To be sure, we could have put the contents of helpers.h and helpers.c in find.c itself. But it’s sometimes better to organize programs into multiple files, especially when some functions (e.g., sort) are essentially utility functions that might later prove useful to other programs as well, much like those in the CS50 Library. Incidentally, recall the syntax for declaring an array. Not only do you specify the array’s type, you also specify its size between brackets, just as we do for haystack in find.c: int haystack[HAY_MAX];

6 < 12

This is CS50. Harvard College Fall 2010

But when passing an array, you only specify its name, just as we do when passing haystack to sort in find.c:

sort(haystack, size);

(Why do we also pass in the size of that array separately?) When declaring a function that takes a one-­‐dimensional array as an argument, though, you don’t need to specify the array’s size, just as we don’t when declaring sort in helpers.h (and helpers.c): void sort(int values[], int n);

Go ahead and implement sort so that the function actually sorts, from smallest to largest, the array of numbers that it’s passed, in such a way that its running time is in O(n2), where n is the array’s size. Odds are you’ll want to implement Bubble Sort or Selection Sort, if only because we discussed them in Week 3. Just realize that there’s no one “right” way to implement either of those algorithms; variations abound. In fact, you’re welcome to improve upon them as you see fit, so long as your implementation remains in O(n2). However, take care not to alter our declaration of sort. Its prototype must remain: void sort(int values[], int n);

As this return type of void implies, this function must not return a sorted array; it must instead “destructively” sort the actual array that it’s passed by moving around the values therein. As we’ll discuss in Week 4, arrays are not passed “by value” but instead “by reference,” which means that sort will not be passed a copy of an array but, rather, the original array itself. We leave it to you to determine how to test your implementation of sort. But don’t forget that printf and, per Week 3’s second lecture, gdb are your friends. And don’t forget that you can generate the same sequence of pseudorandom numbers again and again by explicitly specifying generate’s seed. Before you ultimately submit, though, be sure to remove any such calls to printf, as we like our programs’ outputs just they way they are! Incidentally, check out Resources on the course’s website for a great little quick-­‐reference guide for gdb. If you’d like to play with the staff’s own implementation of find on cloud.cs50.net, you may execute the below.





~cs50/pub/solutions/pset3/find

Need help? Head to help.cs50.net! Now that sort (presumably) works, it’s time to improve upon search, the other function that lives in helpers.c. Notice that our version implements “linear search,” whereby search looks for value by iterating over the integers in array linearly, from left to right. Rip out the lines that we’ve written and re-­‐implement search as binary search, that divide-­‐and-­‐conquer strategy that

7 < 12

This is CS50. Harvard College Fall 2010

we employed in Week 0 in order to search through phone book.3 You are welcome to take an iterative or a recursive approach. If you pursue the latter, though, know that you may not change our declaration of search, but you may write a new, recursive function (that perhaps takes different parameters) that search itself calls.

The Game Begins.

 And now it’s time to play. The Game of Fifteen is a puzzle played on a square, two-­‐dimensional board with numbered tiles that slide. The goal of this puzzle is to arrange the board’s tiles from smallest to largest, left to right, top to bottom, with an empty space in board’s bottom-­‐right corner, as in the below.4

Sliding any tile that borders the board’s empty space in that space constitutes a “move.” Although the configuration above depicts a game already won, notice how the tile numbered 12 or the tile numbered 15 could be slid into the empty space. Tiles may not be moved diagonally, though, or forcibly removed from the board.

Although other configurations are possible, we shall assume that this game begins with the board’s tiles in reverse order, from largest to smallest, left to right, top to bottom, with an empty space in the board’s bottom-­‐right corner. If, however, and only if the board contains an odd number of tiles (i.e., the height and width of the board are even), the positions of tiles numbered 1 and 2 must be swapped, as in the below.5 The puzzle is solvable from this configuration.

3

No need to tear anything in half.

Figure from http://en.wikipedia.org/wiki/Fifteen_puzzle. 5 Figure adapted from http://en.wikipedia.org/wiki/Fifteen_puzzle. 4

8 < 12

This is CS50. Harvard College Fall 2010



Navigate your way to ~/pset3/fifteen/, and take a look at fifteen.c with Nano. Within this file is an entire framework for The Game of Fifteen. The challenge up next is to complete this game’s implementation. But first go ahead and compile the framework. (Can you figure out how?) And, even though it’s not yet finished, go ahead and run the game. (Can you figure out how?) Phew. It appears that the game is at least partly functional. Granted, it’s not much of a game yet.

But that’s where you come in. Read over the code and comments in fifteen.c and then answer the questions below in questions.txt. i.

Besides 4 × 4 (which are The Game of Fifteen’s dimensions), what other dimensions does the framework allow? With what sort of data structure is the game’s board represented? What function is called to greet the player at game’s start? What functions do you apparently need to implement?

ii. iii. iv.



Alright, get to it, implement this game. Remember, take “baby steps.” Don’t try to bite off the entire game at once. Instead, implement one function at a time and be sure that it works before forging ahead. In particular, we suggest that you implement the framework’s functions in this order: init, draw, move, won. Any design decisions not explicitly prescribed herein (e.g., how much space you should leave between numbers when printing the board) are intentionally left to you. Presumably the board, when printed, should look something like the below, but we leave it to you to implement your own vision.

15 14 13 12
11 10

9

8

7

6

5

4

3

1

2

_

Incidentally, recall that the positions of tiles numbered 1 and 2 should only start off swapped (as they are in the 4 × 4 example above) if the board has an odd number of tiles (as does the 4 × 4 example above). If the board has an even number of tiles, those positions should not start off swapped. And so they do not in the 3 × 3 example below: 8

7

6

5

4

3

2

1

_

To test your implementation of fifteen, you can certainly try playing it. (Know that you can force your program to quit by hitting ctrl-­‐c.) Be sure that you (and we) cannot crash your

9 < 12

This is CS50. Harvard College Fall 2010

program, as by providing bogus tile numbers. And know that, much like you automated input into find, so can you automate execution of this game. In fact, in ~cs50/pub/tests/pset3/ are 3x3.txt and 4x4.txt, winning sequences of moves for a 3 × 3 board and a 4 × 4 board, respectively. To test your program with, say, the first of those inputs, execute the below.

./fifteen 3 < ~cs50/pub/tests/pset3/3x3.txt

Feel free to tweak the appropriate argument to usleep to speed up animation. In fact, you’re welcome to alter the aesthetics of the game. For (optional) fun with “ANSI escape sequences,” including color, take a look at our implementation of clear and check out the URL below for more tricks.

http://isthe.com/chongo/tech/comp/ansi_escapes.html

You’re welcome to write your own functions and even change the prototypes of functions we wrote. But we ask that you not alter the flow of logic in main itself so that we can automate some tests of your program once submitted. In particular, main must only returns 0 if and when the user has actually won the game; non-­‐zero values should be returned in any cases of error, as implied by our distribution code. If in doubt as to whether some design decision of yours might run counter to the staff’s wishes, simply contact your teaching fellow. If you’d like to play with the staff’s own implementation of fifteen on cloud.cs50.net, you may execute the below. ~cs50/pub/solutions/pset3/fifteen

If you’d like to see an even fancier version, one so good that it can play itself, try out our solution to the Hacker Edition by executing the below. ~cs50/pub/solutions/hacker3/fifteen

Instead of typing a number at the game’s prompt, type GOD instead. Neat, eh?6

 help.cs50.net!

How to Submit.

In order to submit this problem set, you must first execute a command on cloud.cs50.net and then submit a (brief) form online; the latter will be posted after lecture on Wed 9/29.

 SSH to cloud.cs50.net, if not already there, and then execute:

cd ~/pset3

6

To be clear, implementation of God Mode is part of this problem set’s Hacker Edition. You don’t need to implement God Mode for this standard edition! But it’s still pretty neat, eh?

10 < 12

This is CS50. Harvard College Fall 2010

If informed that there is “no such file or directory,” odds are you skipped some step(s) earlier! Not a problem, we’ll help you fix in a moment. If the command indeed works, proceed to execute this command next:

ls

At a minimum, you should see fifteen and find. If not, odds are you skipped some more steps earlier! If you do see those files, you’re ready to submit your source code to us:7

~cs50/pub/bin/submit pset3

That command will essentially copy your entire ~/pset3 directory into CS50’s own account, where your TF will be able to access it. You’ll know that the command worked if you are informed that your “work HAS been submitted.” If you instead encounter an error that doesn’t appear to be a mistake on your part, do try running the command one or more additional times. (The submit program’s a bit old and annoyingly flakey.) But if informed that your “work HAS been submitted,” it indeed has.

Now, if you instead see some message informing you that your code is not where it should be, you’ll need to fix that before you submit. Review the last two pages of Problem Set 1’s spec for some tips!



Anytime after lecture on Wed 9/29 but before this problem set’s deadline, head to the URL below where a short form awaits:

http://www.cs50.net/psets/3/

If not already logged in, you’ll be prompted to log into the course’s website. Once you have submitted that form (as well as your source code), you are done! This was Problem Set 3.

7

Note that there is no slash between this tilde (~) and cs50.

11 < 12

Similar Documents

Premium Essay

Code

...Pseudocode syntax, descriptions and examples Overview: This table provides a reference for commonly used pseudocode for introductory computer program design courses. You should use this as your reference and copy and paste code examples into your projects to ensure you are using proper syntax. Be sure to indent your code to make it more readable and use modify and enhance from the examples as needed. Also, capitalize the first letter of your pseudocode (e.g. While, not while). Pseudocode Write/Prompt Description Displays messages and other information on the screen Flowchart equivalent Write “What is your name?” Input Pauses execution, allowing the user to enter data Input FirstName Input FirstName Compute/Set Assigns a value to a variable Set Avg=(num1+num2)/2 Declare Example usage Write “What is your name?” Write “Your name is “ +YourName + “.” Prompt for ItemName, Price, Quantity Declares a variable to be of a specific type Input Number1, Number2 Compute average value: Set Avg= (num1 + num2)/2 Compute total cost: Set TotalCost= 1.25*Songs Declare FirstName As String Declare FirstName as String Declare Num1, Num2 As Integer Possible datatypes may include: String 1 Call Requests a module, subprogram, or function be executed Call WriteNums(num1, num2)) If End If Tests if a condition is met. If the test condition is true, the statements are executed. Enter Is Number < 5? Character Integer Float Main Module Write “Enter 2 numbers” Input Num1,Num2 Call WriteNums(num1...

Words: 712 - Pages: 3

Free Essay

Assigning Evaluation and Managment Codes

...Assigning evaluation and management codes By Tina Cunningham Initial consultation is performed of a 78 year old female with unexpected weight loss, abdominal pain, and rectal bleeding. A comprehensive history and examination is performed. I would code this 99205 The comprehensive history of the patient with detailed history. A 30 year old patient presents complaining of flu-like symptoms characterized by unremitting cough, sinus pain, and thick nasal discharge. An examination reveals bronchitis and sinus infection. The patient is prescribed a 5- day course of Zithromax. I would code this 99202 the examination was detailed, complaint addressed, and medical decision established. Established patient in lithium presents for routine blood work to monitor therapeutic levels of kidney function. A nurse reviews the results and advices the patient that tests are normal, and no change in dosage is indicated. I would code this 99211 the patient is an established patient and patient has the two components that is required. A 62- year old diabetic female presents for checkup and dressing change of wound on left foot. An examination reveals the wound is healing. The nurse applied new dressing and 0patient will return for a checkup in one week. I would code this as 99212 the patient has had history of the wound, the examination is on the wound and a medical decision was established. A mother brings in her 6 month old male child for a routine...

Words: 270 - Pages: 2

Premium Essay

Code Meshing Vs Code Switching

...Code Meshing vs. Code Switching: Which One Should be Taught in Schools? In the article “Twitterish,” John McWhorter explains the need for different forms of literacy and multimodality – Standard English and new digital literacies. He also, in a way, talks about code switching and code meshing because he shows how people can switch between different literacies and how they can also incorporate both Standard English and digital literacies into speech and writing together. John White’s paper goes into much greater detail about what code switching is and how to teach it in schools. He says that code switching – the act of changing from a culturally imbued discourse to Standard English, but not necessarily vice versa – is a priority to teach to...

Words: 914 - Pages: 4

Free Essay

Google Code

...Using Google Code and SVN to Manager project Source Code Sep. 3 Project Source Code Manager on Google Code Using NetBean IDE and SVN 1 MrToanDH * C0907i * FptAptech Using Google Code and SVN to Manager project Source Code Sep. 3 Contents I. Google Code là gì? ............................................................................................................. 3 II. 4 bước để tạo Project trên Google Code:.......................................................................... 4 III. Thiết lập các chức năng cho project : ............................................................................. 7 1.Trang chủ project (Project Home) : ................................................................................ 7 2.Thêm và quản lý các thành viên của 1 project : ............................................................. 8 3.Chức năng download : .................................................................................................... 9 4.Xóa project : ................................................................................................................. 11 IV. Giới Thiệu Về Subversion: .............................................................................................. 12 V. 2 cách cơ bản để quản lý Source code với SVN : ............................................................ 13 1.Thao tác với file và Folder : .............................................................................................

Words: 2085 - Pages: 9

Premium Essay

Code of Ethics

...Code of Ethics Teresa Sieck ETH/ 316 July 2, 2012 Ed McCullough Code of Ethics A code of ethics is a collection of principles practiced and followed by management of businesses and corporations around the world (Spiro, 2010). A businesses code of ethics works with a company’s mission statement and policies of conduct that gives employees, partners, venders, and outsiders an understanding of what the company stands for and believes in (Boylan, 2009). It should address the differences or variations in both company’s industry and its broader goals for social responsibility (How to create a company code of ethics, 2012). It should be strong enough to serve as a guide for employees with questions to resolve issues on their own if needed (Trevino & Nelson, 2007). Wal-Mart is one of the largest corporations in the United States. As one of the largest corporations the company has a social responsibility to their employees, customers, and the community. The code of ethics works with and around these principals. Wal-Mart has three basic principles, 1) respect for the individual, 2) service to the customer, and 3) striving for excellence (What is Wal-Mart’s Code of ethics, 2011). The following is an example of what a code of ethics could be and what values a business may have. Vision Statement: People are assets not possessions; employees, customers, and communities should be treated with fairness, respect, honesty and integrity. The corporation’s global vision is to...

Words: 1066 - Pages: 5

Free Essay

Gray Code

...What is Gray code? From Wikipedia The reflected binary code, also known as Gray code after Frank Gray, is a binary numeral system where two successive values differ in only one bit. The reflected binary code was originally designed to prevent spurious output from electromechanical switches. Today, Gray codes are widely used to facilitate error correction in digital communications such as digital terrestrial television and some cable TV systems. One good way to explain the use of Gray code is to take a look at how a hard drive work, in extreme simplicity. A hard drive contains a disc where information is stored. The information on the disc is stored in ones and zero´s, binaries. The disc is divided into sections which each has a binary signature. Here is a picture to explain: As we can see here, section 0 for example has the binary signature 0000 and section 15 has the binary signature 1111. When a hard drive is running it reads section by section and if the hard drive for some reason has a failure and the reader jumps from section 15 to section 0 the reading changes from 0000 to 1111 which means that every bit read is faulty. This could change alot depending on how the information is parsed. A hard drive could be exposed to a lot of external forces and the reader can jump and missread at any time. This cannot be forseen, but it can be prevented to some extent. Enter Gray code. Gray code is a way to sort the binaries so that one binary never...

Words: 1010 - Pages: 5

Premium Essay

Code of Hammurabi

...present day is known as Iraq. (Ancient Mesopotamia) Hammurabi created a list of rules and laws for the people of his empire to follow called “The Code of Hammurabi”. This is one of the oldest and most detailed documents in existence and gives insight as to how the members of Babylonian society lived. The code listed 282 rules for society to obey by and the consequences or guidelines for each member given their social status and their gender. There were rules of every category. From marriage and adultery, criminal acts such a stealing, property, and monetary trading. What’s interesting about this rulebook is the detail and coverage of the book. While in today’s world we may not follow rules such as “An eye for an eye, and a tooth for a tooth” like the Code of Hammurabi, whose punishments for a crime were much more extravagant and gruesome at times. There was segregation in gender and social status. The topics addressed in the code are some of the same topics addressed that we, today, value and instill. In today’s government we have laws of crime and punishment, monetary laws, and laws regarding marriage. We have these laws so we can have structure and a successful government and society. It’s amazing how such early civilization started these fundamentals and on some linear level, had the same values. Not discovered until 1901, the Code of Hammurabi shows us how Hammurabi viewed himself and the people of Babylon. This insight is significant. Hammurabi believed he could run his empire...

Words: 2731 - Pages: 11

Free Essay

Code Obfuscation

...Code Obfuscation One of a company's biggest concerns is that their software falls prey to reverse engineering. A secret algorithm that is extracted and reused by a competitor can have major consequences for software companies. Also secret keys, confidential data or security related code are not intended to be analysed, extracted and stolen or even corrupted. Even if legal actions such as patenting and cyber crime laws are in place, reverse engineering remains a considerable threat to software developers and security experts. In software development, obfuscation is the deliberate act of creating obfuscated code, i.e. source or machine code that is difficult for humans to understand. Programmers may deliberately obfuscate code to conceal its purpose (security through obscurity) or its logic, in order to prevent tampering, deter reverse engineering, or as a puzzle or recreational challenge for someone reading the source code. Programs known as obfuscators transform readable code into obfuscated code using various techniques. Obfuscation present the concept of code encryption, which offers confidentiality, and a method to create code dependencies that implicitly protect integrity. This paper majorly focuses on obfuscating java code. This research topic will give more knowledge on how to protect a java software from a tampering. I can use these concepts in my future work and give suggestions to the team/group. This not only extends my knowledge on this topics, I will learn how...

Words: 258 - Pages: 2

Free Essay

Dress Code

...Dress Code: To Be or Not to Be A dress code may be a hard rule to put into practice. Although it is hard to implement, studies have been done that show that schools with a dress code have better performance. Not everyone agrees a school having a dress code, which makes it hard to execute. People can argue that it is a good idea or it is a bad idea. I think it is a good idea to have some sort of a dress code, but not to the point where students have to wear the same uniform every day. Everyone wants there kid to do well in school. Studies show that the schools that have strict dress codes do better than schools that do not have dress codes. When you have a certain structured dress code, kids are less likely to worry about what they are wearing and focus more on the schooling. If you require the students to wear uniforms all of the time, the use of the same colors could possible cause depression with the kids. Instead of making them wear a uniform every day, make them wear one on certain days of the week. Variety of clothes and being able to pick what you want to wear is a fun part of school for most people. When required to wear certain uniforms, depending on what they are, the students could have better school spirit. On the other hand, they could go completely against the school for requiring them to have to wear uniforms. Someone will not like the uniform no matter how nice it is that is just the way it is. Everyone wants to show off their new clothes they...

Words: 671 - Pages: 3

Premium Essay

Code of Hammurabi

...Code of Hammurabi Western Civilization and the World I 100 Professor Preface This paper will examine the Code of Hammurabi and how it affected the people of Babylon before, during and after its creation. The nature of the topic is to have a better understanding of how the Code of Hammurabi changed society, hindered women’s rights and independence and left a lasting impression for future generations. Chronology 1810 BC Hammurabi was born to the then-king of Babylon Sin-muballit. 1792 BC Hammurabi, king of Babylon, started his rule. 1787 BC King Hammurabi captured Uruk and Isin. 1784 BC King Hammurabi campaigned against Rapigum and Malgium. 1772 BC Code of Hammurabi was created. 1763 BC With the aid of Mari and Eshnunna King Hammurabi conquered Larsa, putting an end to the long reign of Rim-Sin I. 1755 BC Captured Eshnunna which was the last of his Mesopotamian rivals. 1750 BC King Hammurabi died and passed the reigns of the empire to his son, Samsu-iluna. 1738 BC Under Samsu-iluna’s rule his empire fell to the Sealand Dynasty. 1595 BC Babylonian empire restored to glory of the Hammurabi’s age. 1901 Code of Hammurabi monument is discovered by French archaeologists. 1910 The Code of Hammurabi was translated by Leonard William King. During the rule of King Hammurabi he wrote the Code of Hammurabi. This consisted of many laws that changed the society, hindered women’s rights and independence and left a lasting impression for future generations...

Words: 2447 - Pages: 10

Premium Essay

Dree Code

...Dress Codes In Junior High And High Schools? Name: Institution: Should There Be Dress Codes In Junior High And High Schools? Introduction The dress code for junior and high schools has been a hot debate over the years. It has sought to address various issues and have resulted in different levels of controversy. For instance, in the early 1970s boys with long hair sometimes got attracted to their classmates. Resultantly, schools required young men to cut their hair short. Moreover, at the beginning of the 1990s several organizations and parents pushed for a dress code as a strategy to curb gang-related violence (Valdez, 2015). Over the years, the desire to create a professional school environment and reduce struggle over designer clothes made uniforms and dress codes become a familiar topic. However, identical strategies are more restrictive than dress code policies. Dress codes are strict as in the case of schools in California and Napa. For instance, schools in this areas required students to put on solid colors and logos or banned images on clothes. The primary objective of this argumentative essay is to provide adequate evidence that there should be dress codes in both junior and high schools. Claim 1: dress code may increase student safety and reduce crime. Each year several schools adopt a certain form of dress code. Although some challenges are emerging on the constitutionality, court’s rulings have supported dress codes that...

Words: 1717 - Pages: 7

Free Essay

Qr Codes

...list I compiled of positives and negatives concerning QR codes. Pros Easy to make. All you really need is a free QR code generator, and there are plenty of them floating around the Internet. Cost effective. Since most of the QR code generators are free, making the actual codes is inexpensive. The cost of printing materials can also remain relatively low, since they can be used on business cards or stickers. Stores can print their QR codes in ads, which they already invest money into. Anyone can make a QR code. Saves paper. People can scan a QR code to do things like enter contact information or store a coupon on a cellphone. Instead of having to carry paper coupons, people can just scan a QR coupon and have it available in their phone. Very quick transfer of information. Since the advent of DSL internet and now the 4G network for cellphones, people have gotten very used to getting information very quickly. Relatively small in size. This makes the codes great to put on business cards, in a corner of an ad, somewhere on a coupon, or anywhere there is a small bit of space. These codes can be made much smaller than the information they contain. So instead of placing a long, ugly, URL, on an advertisement or resume, simply place a small QR code. Cons Potential for over usage. Marketers should be aware that placing a QR code absolutely everywhere can be overkill. Reputation issues. Many people are making their QR code that link to social media, such as Facebook. This might...

Words: 500 - Pages: 2

Free Essay

Reusability of Code

...Reusability of Code One of the key factors for large software development projects is the ability to reuse code amongst team members. This allows for efficiency and reduces the time to get a software product delivered to a customer (or brought to market). This paper is intended to focus on the different areas that would benefit a software development team (or company) by having a structured and reusable code library in place. I have experience in supporting large ECM (Electronic Content Management) systems and I will refer to these re-world scenarios throughout this document. Reusability refers to the ability for a single developer that specializes in one area (or is assigned the task of developing) to develop a class or specific code that can then be used by other developers. As an example, a senior developer defines a class that serves as a blueprint for developing various objects that would input data into a Filenet ECM system. Once this class has been defined and created, other developers can reuse this class to develop objects that allow for public input and that will eventually store data in the ECM database. This stored data that is specifically formatted to be read by the Filenet application, allows end users to run reports that have a specific output that the want to view. In essence, the reusability of code is akin to manufacturing one part of a car that can then be used for many cars (such as a single frame that can hold various models of cars). The developer...

Words: 317 - Pages: 2

Free Essay

Code of Ethics

...Iranian Journal of Public Health Tehran University of Medical Sciences The Code of Ethics for Nurses F Zahedi, M Sanjari, [...], and M Vahid Dastgerdi Additional article information Abstract Nurses are ever-increasingly confronted with complex concerns in their practice. Codes of ethics are fundamental guidance for nursing as many other professions. Although there are authentic international codes of ethics for nurses, the national code would be the additional assistance provided for clinical nurses in their complex roles in care of patients, education, research and management of some parts of health care system in the country. A national code can provide nurses with culturally-adapted guidance and help them to make ethical decisions more closely to the Iranian-Islamic background. Given the general acknowledgement of the need, the National Code of Ethics for Nurses was compiled as a joint project (2009–2011). The Code was approved by the Health Policy Council of the Ministry of Health and Medical Education and communicated to all universities, healthcare centers, hospitals and research centers early in 2011. The focus of this article is on the course of action through which the Code was compiled, amended and approved. The main concepts of the code will be also presented here. No doubt, development of the codes should be considered as an ongoing process. This is an overall responsibility to keep the codes current, updated with the new progresses of science and emerging challenges...

Words: 3684 - Pages: 15

Free Essay

Code of Conduct

...an effective program is necessary. The Federal Sentencing Guidelines for Organizations encourages firm to set up ethics programs. Review this Website, located here , prior to doing the assignment. Write a 4-6 page paper in which you: 1. Briefly describe your company and then benchmark the codes of conduct used by similar companies in the industry. Critique the codes of conduct of at least three (3) similar companies in order to write codes for your company. 2. Analyze ways ethical challenges affect your business and create a code of conduct for your company. Provide a rationale on how these specific codes enhance your company’s ethics program. 3. After reviewing the Federal Sentencing Guidelines for Organizations, explain how these guidelines influence the ethics program you created. 4. Anticipate where the challenges or setbacks may be in the adoption and enforcement of the codes of conduct for your company. Explain how you will address these challenges and anticipated setbacks. 5. Given the influences of changing economic, political, social, cultural, and technological forces on business and society, explain how you can ensure that your codes of conduct will remain relevant in the years ahead. Your assignment must follow these formatting requirements: 1. Be typed, double spaced, using Times New Roman font (size 12), with one-inch margins on all sides; references must follow APA or school-specific format....

Words: 434 - Pages: 2