GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 01-Dec-2008, 21:33
Hielo77 Hielo77 is offline
New Member
 
Join Date: Dec 2008
Posts: 1
Hielo77 is on a distinguished road

I could use some help


Hey all! So I'm taking a Computer Science course at my college and it was going pretty easy for the most part.. until our professor threw us a curve ball. I have to write 6 programs by Wednesday that go a little bit beyond what we learned and I'm have quite some time figuring it out. Of course, don't feel obligated to answer all of these questions but if you offer any help and advice I will be very, very grateful.

  1. So I got the first program no problem, that wants me to check whether or not a user specified number is prime or not, and why.

    But I also need to write one that lists prime numbers to a user specified range. (1-100) Well it prints out the numbers... but not to the range. I understand that the "range <= 100" thing controls the range, but how do I specifiy it with a cin command? Also, how can I get it to not show the numbers that are not prime and only the numbers that are? This is from the model that my teacher gave me to start from but when I remove the stuff about the number not being prime it doesn't work altogether. Here's my code for the program right now.
    CPP / C++ / C Code:
    #include <iostream.h>
    void main()
    {
    
    int the_number;
    int d;
    int range;
    bool isPrime; // true/false
    
    d = 3; // the dividor
    
    
    cout << "Enter a range of numbers. (1-100) I'll pick out the numbers that are prime. " << endl;
    cin >> range;
    
    
    for(the_number = 2; range <= 100; the_number++)
    {
    isPrime = true;
    
    for(d = 2; d <= the_number/2; d++)
    {
    
    
    // check with d (dividor)
    if(the_number % d == 0)
    {
    cout << " " << the_number << " is NOT a prime number because ";
    cout << "the number is divisible at least by " << d << endl;
    isPrime = false;
    break; // breaks out of the inner loop
    
    }
    else
    {
    
    // cout << "the number is not divisible by " << d << endl;
    }
    
    
    } // end of the for-loop
    
    
    
    if(isPrime == true) cout << the_number << " is a prime number, not divisible by any number" << endl;
    
    
    }
    
    return;
    }
  2. I also have to write a program to find all the solutions numerically within the domains given, for these three questions.

    a) 2sin(x^2) = x - 0.5 [-5, 5]
    b) ln(x) = -2x + 5cos(x) [0, 10]
    c) 3x^2 + 4x -9 = 0 [-20, 20]

    I unfortunately have no idea what that means.
  3. I also have to another similar to that involving mortgage rates. Using the formula

    R= (Pr) / (1-(1+r)^-n

    And write an interactive program that asks the user about P, n, and yearly interest rate, and then compute R and print it out. It should go something like this:

    How much will you borrow?
    12000
    How many years is that for?
    10
    What is the yearly interests rate?
    0.06
    Your payment will be $133.225 a month for 120 months.
  4. So then I have to write a program that that will print out a periodic monthly schedule for a loan, for as long as the amount of years specified. Should create a six column table with Month, Payment, Interest, Interest Paid, Total Payment and Balance.
  5. Then write a program that will print a hexidecimal colored American flag. White stars with blue background and white and red colored stripes which are equal signs. You know, *** and ====
  6. I also have to write a program that will print out tables of squares and cubes in a user specified range and intervals. How can print out squares?
  7. Also a program that will convert a decimal number into it's binary equivalent.
    Should run like this:

    Enter a number:
    10
    Binary: 1010
  8. And lastly write a program that converts a decimal number into it's hexadecimal equivalent.
    Should run like this:

    Enter a number:
    26
    Hexadecimal: 1A

Good God that is a lot.
Last edited by admin : 02-Dec-2008 at 01:30. Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
  #2  
Old 02-Dec-2008, 16:12
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,218
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: I could use some help


Quote:
Originally Posted by Hielo77
...
But I also need to write one that lists prime numbers to a user specified range.

Wouldn't you simply need something like the following:

CPP / C++ / C Code:
#include <stdio.h>

int main()
{
    int i, range;

    /* Prompt the user for a number. This is the "range" */
    
    /* 
     * Get the range and verify that it is a
     * valid integer whose value is greater than 1
     * and less than whatever limit you wish to
     * set on the maximum to be inspected.
     */

    for (i = 2; i < range; i++) {
        /*  Put your prime number testing stuff here */
        if (/* i is a prime */) {
            printf("%d is a prime number\n", i);
        }
    }
    return 0;
}

Regards,

Dave
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 13:11.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.