Thread: Homework help

  1. #1
    Registered User
    Join Date
    Mar 2002

    Homework help


    The objective of this assignment is to get you familiar with good design practices, writing in C++ in a Borland environment, and using functions. It may also heighten your appreciation of mathematics

    The study of mathematics is separated into many fields. The one that tends to lead students to discover the beauty of mathematics is the field of number theory. This field deals with numbers and their relationships to each other.

    The field of number theory has lead to discoveries such as :

    Prime numbers -- those which can only be divided by themselves and one. Some special primes that you might find interesting are of the form 2p - 1, where p is prime. These are called Mersenne Primes after the French monk Marin Mersenne who discovered them. The search for Mersenne primes continues. You can participate in the search for new Mersenne primes by joining GIMPS (the Great Internet Mersenne Prime Search). The 39th and largest known Mersenne prime is 213466917 - 1. It was just discovered on November 14, 2001.
    ˇ Perfect numbers -- ancient mathematicians were interested in the relationship of a number and the sum of its divisors. A positive integer that is equal to the sum of its divisors (excluding itself) is called a "perfect" number. For example, the divisors of 6 are 1, 2 and 3. Since 6 = 1 + 2 + 3, 6 is a perfect number. The next three perfect numbers are 28, 496 and 8128. If the sum of the divisors is greater than the number, the number is called "abundant". If the sum of the divisors is less than the number, the number is called "deficient". Perfect numbers demonstrate some interesting properties -- all known perfect numbers end in 6 or 8; there are no known odd perfect numbers. Mersenne primes and perfect numbers are closely related.

    ˇ Squares -- many positive integers are considered geometric in nature. You learned about perfect squares in high school -- 1, 4, 9, 16. They are called "squares" because a group of 1, 4, 9 or 16 dots can be arranged in a square.

    ˇ Triangular numbers -- Groups of 1, 3, or 6 dots can be arranged in a triangle and so these numbers are called "triangular" numbers. (If you've ever gone bowling, you'll recognize that 10 is also triangular.)
    A more natural example arises when we consider a group of people who meet for the first time and everyone shakes hands with everyone else. The number of handshakes will be a triangular number.
    Turns out that triangular numbers are the sum of consecutive integers.

    o 1 = 1
    o 3 = 1 + 2
    o 6 = 1 + 2 + 3
    o 10 = 1 + 2 + 3 + 4
    To us this may just be an interesting relationship. To early Pythagoreans, it showed the mysterious nature of the universe and the way in which numbers and shapes have esoteric relationships.

    Positive integers can be categorized in many different ways. This project will let you investigate some familiar and some new ways of looking at integers.

    Coding Specifications
    Your mission is to write a program that examines positive integers within a range that the user specifies and categorizes them as follows:

    1. ODD or EVEN

    2. PRIME or COMPOSITE -- a prime number is an integer greater than one that is divisible only by itself and one. Any number that is not "prime" is "composite".

    3. PERFECT/ABUNDANT/DEFICIENT --- as described above

    4. SQUARE -- as described above

    5. TRIANGULAR -- as described above

    Your program will also count the number of integers in the specified range that fall into each category and print a summary at the end. You should restrict the user to positive integers between 1 and 100000, inclusive. The ending number specified by the user should always be greater than or equal to the starting number s/he chose. You must validate the user's input. I guarantee that all input used to test your program will be of type int.

    Your program MUST include the following functions. Do NOT change the functions prototypes given below. You may choose to use more functions if you wish, but these are sufficient. All "predicate" functions below should return 1 for TRUE and 0 for FALSE. You have some flexibility in implementing the other functions.

    void PrintGreeting (void); -- displays a suitable greeting to the user
    int GetValidInt (int min, int max); -- gets an integer from the user between min and max, inclusive and returns that valid integer.
    void PrintTableHeading (void); -- prints the heading of the table
    int IsOdd (int n); -- a predicate function that returns TRUE if n is Odd and returns FALSE if it is not.
    int IsPrime (int n); -- a prediate funtion that returns TRUE if n is prime, and FALSE if it is not
    int CheckForPerfect (int n); -- classifies n as "perfect", "abundant" or "deficient". A different value is returned for each different category.
    int SumDivisors (int n); -- returns the sum of the divisors of n.
    int IsDivisor (int a, int b); -- a predicate function that returns TRUE if a is a divisor of b, and FALSE if not
    int IsSquare (int n); -- returns TRUE if n is a perfect square, FALSE if not
    int IsTriangular (int n); -- returns TRUE if n is a triangular number, FALSE if not
    void PrintTableLine (int n, int odd, int prime, int perfect, int square, int triangular); -- prints the information for one number on one line of the table
    void PrintTotals (int first, int last, int numOdd, int numEven, int numPrime, int numComposite, int numDeficient, int numPerfect, int numAbundant, int numSquare, int numTriangular); -- prints the summary of the number of different classifications found in the range specified.

    Sample Run

    This program classifies positive integers as
    Odd/Even, Prime/Composite, Perfect/Abundant/Deficient, Square, and Triangular

    You will now get to choose the range of positive integers that
    you would like to see classified.

    Start with which positive integer ?
    Please enter an integer between 1 and 100000 : 1
    End with which positive integer ?
    Please enter an integer between 1 and 100000 : 30

    Int Classifications................................... .
    1 Odd Prime Deficient Square Triangular
    2 Even Prime Deficient
    3 Odd Prime Deficient Triangular
    4 Even Composite Deficient Square
    5 Odd Prime Deficient
    6 Even Composite Perfect Triangular
    7 Odd Prime Deficient
    8 Even Composite Deficient
    9 Odd Composite Deficient Square
    10 Even Composite Deficient Triangular
    11 Odd Prime Deficient
    12 Even Composite Abundant
    13 Odd Prime Deficient
    14 Even Composite Deficient
    15 Odd Composite Deficient Triangular
    16 Even Composite Deficient Square
    17 Odd Prime Deficient
    18 Even Composite Abundant
    19 Odd Prime Deficient
    20 Even Composite Abundant
    21 Odd Composite Deficient Triangular
    22 Even Composite Deficient
    23 Odd Prime Deficient
    24 Even Composite Abundant
    25 Odd Composite Deficient Square
    26 Even Composite Deficient
    27 Odd Composite Deficient
    28 Even Composite Perfect Triangular
    29 Odd Prime Deficient
    30 Even Composite Abundant

    Between 1 and 30 there were
    15 Odd integers and 15 Even integers
    11 Prime numbers and 19 Composite numbers
    2 Perfect, 5 Abundant and 23 Deficient numbers
    5 Squares
    7 Triangular numbers

    Although your output need not be identical to the above, all information (including the greeting) must be present.

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    What bit are you stuck on?

  3. #3
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Hannover, Germany
    Attention to all....

    The purpose of these board is not for other to do your homework for you! Try things out work on your own, homework has a purpose. If you still have trouble with a specific thing or whatever please feel free to ask. But please DO NOT ask people to do your entire homework for you, it simply annoys people most of the time.
    Taken from the Read this first thread on this board, which you should have read first (obviously).

    We are not here as an easy solution to your homework. Don't expect us to do anything for you if you dump your work here. Show us your problem, and show us that you tried it yourself first and we will help you.

    Open up a new thread when you did at least a tiny part of the work you are supposed to do. Post a specific question.

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Homework
    By kermi3 in forum A Brief History of
    Replies: 11
    Last Post: 11-03-2001, 04:39 PM
  2. Homework
    By kermi3 in forum C Programming
    Replies: 10
    Last Post: 09-27-2001, 04:49 PM
  3. Homework
    By kermi3 in forum C++ Programming
    Replies: 15
    Last Post: 09-26-2001, 03:16 PM
  4. Homework
    By kermi3 in forum C Programming
    Replies: 0
    Last Post: 09-10-2001, 01:26 PM