By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,601 Members | 989 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,601 IT Pros & Developers. It's quick & easy.

How do i write algorithms?

P: 1
Write an algorithm that gets a numeric grade value 0 to 100 from the user, and produces the equivalent letter grade using the standard scale of 90-100 is A, 80-89 is B, 70-79 is C, 60-69 is D, and below 60 is F. The output should resemble:
The score entered was 85 and the letter grade is B
Compute and display the value x y if the value of y is not 0. If y does have the value 0, then display the message 'Unable to perform the division.'
Compute the volume and circumference of a cylinder given the length L and radius r if the radius is greater than or equal to 1.0; otherwise, your algorithm should compute only the circumference.
Write an algorithm that take three numbers and determines which number is the largest of the three and outputs something along the lines of:
The largest value of 10, 22, and 11 is 22
Sep 1 '10 #1
Share this Question
Share on Google+
3 Replies


100+
P: 201
the code below should give you an example of how to do the formulas for letter grades. the question is are u going to be creating pointers/virtual pointers or need to inherit their functions for more processing instead of re-writting the code? but for the cylinder this should give you an example as well on how to take the integers given and formulate them.

here is an example:

Expand|Select|Wrap|Line Numbers
  1. //Author Theo Werntz II
  2. //CIS 242
  3. //Date 07/21/04
  4. //Project L_2_P_1
  5.  
  6.  
  7. #include <iostream>
  8.  
  9. using std::cout;
  10. using std::cin;
  11. using std::endl;
  12.  
  13.  
  14.  
  15. // main functions
  16.  
  17.  
  18. int main()
  19. {
  20.    int total = 0;          // total feed
  21.    int feedA = 2.50;     // feedA
  22.    int feedB = 3.15;     // feedB
  23.  
  24.  
  25.  
  26.    cout << "Enter the letter of feed." << endl
  27.         << "The Feed List Is As." << endl
  28.     << "Feed A = $2.50 per 100 lbs."<< endl
  29.     << "Feed B = $3.15 per 100 lbs."<< endl
  30.     << "When Finished with Order Press."<<endl
  31.     <<    "CTRL Z to Calculate Total."<<endl;
  32.  
  33.  
  34.  
  35. //while loop for total
  36.  
  37.  
  38.    while ( ( total = cin.get() ) != EOF ) {   
  39.  
  40.  
  41. // determine which feed is input
  42.  
  43.  
  44.       switch ( total ) {      // nested switch structure in while
  45.  
  46.  
  47.          case 'A':            // feedA uppercase A
  48.          case 'a':            // or feedalowercase a
  49.             ++feedA;         // increment aCount
  50.             break;            // exit switch
  51.  
  52.  
  53.          case 'B':            // feedB uppercase B
  54.          case 'b':            // or feedb lowercase b
  55.             ++feedB;         // increment bCount    
  56.             break;            // exit switch
  57.  
  58.  
  59.          case '\n':           // ignore newlines,  
  60.          case '\t':           // tabs, 
  61.          case ' ':            // and spaces in input
  62.             break;            // exit switch
  63.  
  64.  
  65.          default:             // trap for anything except letter a 
  66.                             // and letter b.
  67.             cout << "Incorrect feed letter was entered."
  68.                  << " Enter a new feed letter." << endl;
  69.             break;            //exit switch 
  70.  
  71.  
  72.       }             // end switch
  73.  
  74.  
  75.    }                 // end while
  76.  
  77.    // output summary of feed
  78.  
  79.    cout << "\n\nTotals For each Feed Are:" 
  80.         << "\nA: " << feedA           // display number of A feed ordered
  81.         << "\nB: " << feedB           // display number of B feed ordered
  82.         << endl;
  83.  
  84.    return 0;              // indicate successful termination
  85.  
  86. }                 // end function main
  87.  
  88.  
  89.  
  90.  
Sep 1 '10 #2

Expert 100+
P: 2,398
The algorithm is the strategy you use to solve the problem. An algorithm can be expressed in text (like a cookbook recipe), graphically (like a flowchart), or in a computer language.
Sep 1 '10 #3

Oralloy
Expert 100+
P: 983
Don has the right of it.

An algorithm is simply an unambiguous statement of how to achieve a result.

The rest is implementation.

So, since we're not in the homework business, Avery, how about you take a stab at your three and tell us what your algorithms are. Then we can comment on them for you.

Cheers!
Sep 1 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.