Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your HW1 program starts by printing out to the screen a quick description of what an HCN is. The program continues by asking the interactive

Your HW1 program starts by printing out to the screen a quick description of what an HCN is. The program continues by asking the interactive user for an integer from 1 to 10,000,000, inclusive. I will call that number X. The prompt should be explicit about what X should be.

If the user enters something that is not an integer, then your program should give an appropriate error message and reprompt for X. If the user enters something that is an integer, but is outside the specified range, then the program should give a different, appropriate error message and reprompt for X. This should continue until the user enters an X that is legal according to the specification above.

When a legal X has been entered by the interactive user, your program should print out the HCN that is closest to X, with an explanation. Perhaps there could be a tie between two HCNs where HCN1 < HCN2, and (X HCN1) = (HCN2 X); if that is the case, the program should print out both HCN1 and HCN2, with an appropriate explanation. If X is itself an HCN, then X is the closest to X, and your program should print out an appropriate explanation.

With a little thought, you can imagine at several different strategies to approach this problem:

1. Have your program generate a list of HCNs long enough to be sufficient for the 10,000,000 limit described in the specification, and use that list in solving the problem. This has a major advantage if (in the future) someone wanted to expand the 10,000,000 limit. Your program could change one constant, and would be ready to go.

2. Find a list of HCNs on the internet, and hard code in the necessary numbers for your program. This is less useful than point 1 if someone decides they want to improve the program by raising the 10,000,000 limit.

3. Find a way to determine if a particular number is an HCN, and look at X, then X-1 and X+1, then X-2 and X+2, and so on until you find an HCN (or two HCNs).

4. Look for code in your favorite language that does something useful for you when trying to solve this problem. It is OK to find and use code on the internet to do this, as long as you GIVE CREDIT WHERE CREDIT IS DUE by mentioning in your opening comments the source of the code. Also, give a credit using internal comments where you use the code you found.

No matter what programming language you eventually use, start the source code for your program with an extensive opening comment that includes your name, the date, the name of our class, an explanation of what the program is designed to do, a description of the central data structures in your program, and an explanation of any external files used. If your program doesn't include any of these, then indicate that by listing the category, and indicating "None," or something like that. For example, if the program doesn't use external files, your opening comment should include something like:

External files: None.

In addition to the extensive opening comment, internal comments should explain important data structures where they are declared and/or used, delineate large sections of code (paragraphing comments), and clarify anything clever or hard to understand in your code. We grade documentation carefully and critically, so I recommend that you spend some time on your opening and internal comments. There are other ways in which you might be able to submit your programs, but for many reasons, I REQUIRE you to hand in your program as a single text file. If you can't manage to do that with one particular language, pick a different language that you CAN do with a single text file using onlinegdb.com.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions