How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask lifesaver Your Own Question

lifesaver
lifesaver, Computer Software Engineer
Category: Programming
Satisfied Customers: 5962
Experience:  Several years of intensive programming and application development experience in various platforms.
16528259
Type Your Programming Question Here...
lifesaver is online now
A new question is answered every 9 seconds

I have a practice exam and I need help with exercise. See below.

This answer was rated:

I have a practice exam and I need help with exercise. See below. Thanks.

Exercise 2: Euclid's Algorithm
Task for Exercise 2
Using the template given below and the pseudocode for Euclid's Algorithm, write a C++ program that computes the greatest common divisor (GCD) of two numbers. Remember to maintain all the blank lines, spaces, and general alignment in the template. Then replace the areas that have been highlighted in yellow with your code. Do not change any of the other code.
Code Template for Exercise 2
/*******************************************************/
/* File: name of your file with the source code */
/* */
/* Created by: give your name */
/* Date: give the date */
/* */
/* Program to compute the GCD of two integers */
/* */
/* Inputs: (keyboard) */
/* 1. Two numbers - only positive numbers allowed */
/* */
/* Output: */
/* Print the GCD of given numbers on the screen */
/* */
/* Algorithm: Euclid's Algorithm */
/* */
/*******************************************************/
#include
using namespace std ;
int main()
{
Declare x, y, temp, remainder as Integer.
// read in the two integers
cout << endl ;
cout << "Enter the first number (positive integer) : " ;
cin >> x ;
cout << "Enter the second number (positive integer) : " ;
cin >> y ;

//echo inputs

cout << "Input numbers are: " << x << " , " << y << endl ;
Write a C++ if statement to determine if x < y.
{ // exchange values of x and y

Write three assignment statements in C++ that are
equivalent to the three statements given in the
pseudocode.
}
/* At this point we will always have x >= y */
Initialize remainder.
while ( )
{
Write the loop expression and loop body code in C++.
In C++, the expression (x % y) gives the remainder
after dividing x by y.
}
// display the result
cout << endl ;
cout << "The GCD is: " << y << endl ;
return (0); // terminate with success
}
Test Plan for Exercise 2
Test your code with the following pairs of numbers:
x y Expected answer
1 1
2 2
5 5
20 20
2 10
10 2
3 4
4 3
36 48
48 36
90 390
252 108
1024 256
23,205 1,638
Hello Bamaboy,

Can you please uplaod your code to www.pastebin.com and give me the download link .

The code is not readable.
Customer: replied 7 years ago.
I can upload a word doc with what needs to be change highlighted in yellow. Is that ok?
That's fine..
Customer: replied 7 years ago.
Can I send the word doc. to you by email or some other way? Thanks.
Sorry exchange of personal information is against site rules .

Visit the link below.

www.wikisend.com

Browse and uplaod the word document.

It will give you a download link.

GIve me that download link so that i can downlaod the word document/

Customer: replied 7 years ago.

Here's the download link. Thanks,

 

http://wikisend.com/download/444782/Exercise 2.docx

Ok.

GOt the word document.

Will post the answer soon.
Customer: replied 7 years ago.
Thanks!
You can download the program from link below:-

http://pastebin.ca/1612930

OR

http://www.mediafire.com/?dyzrjwqmy2m

Here's a link that will help you calculate gcd and verify results .
http://javascript.internet.com/math-related/gcd-lcm-calculator.html

Let me know if any complications arise.

lifesaver and 2 other Programming Specialists are ready to help you
I haven't checked all the values.Just checked for 2 or 3 values.'

I am currently checking for all the values as mentioned in the word document.
Take some time and verify all the outlputs.

IF any problems let me know.

I will correct the code.
Hi,

I rechecked the program and the program gives wrong output for few cases,

Here is the perfect program.

http://pastebin.ca/1613172


Checked and it Gives correct output for all the cases.Please modify your program.

Edited by lifesaver on 10/11/2009 at 6:53 PM EST
Customer: replied 7 years ago.
I can't get this one to work.
DO you get errors?

Please try to download from this link:-

http://www.mediafire.com/?4dmztdnmzzu

Customer: replied 7 years ago.
Thanks this one works perfect. You are my hero!
You are welcome.

I even tested it with all the test cases inside your word document.

Have a good day.
Customer: replied 7 years ago.
Your are the best :)
Customer: replied 7 years ago.
Hello, I have another exercise to complete Can you help? I will pay the same price. Thanks.
Customer: replied 7 years ago.

Here's the exercise. Thanks.

Exercise 1. Course Grade

Task for Exercise 1

Suppose that a float variable called score contains the overall points earned for this course. The following set of cascaded if-then-else pseudocode statements determines your final grade.

If (score >= 85) then
Set grade = ‘A' Else
If (score >= 75) then
Set grade = ‘B'
Else
If (score >= 65) then
Set grade = ‘C'
Else
If (score >= 55) then
Set grade = ‘D'
Else
Set grade = ‘F'
End if // score >= 55
End if // score >= 65
End if // score >= 75
End if // score >= 85

Your assignment is to convert this pseudocode into a C++ program. Use the following template for your program and remember to maintain all the blank lines, spaces, and general alignment. Then replace the areas that have been highlighted in yellow with your code. Do not change any of the other code.

Code Template for Exercise 1

/****************************************************/
/* File: name of your file with the source code */ (Highlighted in yellow)
/* */
/* Created by: give your name */
/* Date: give the date */
/* */
/* Program to determine course grade */
/* */
/* Inputs: (keyboard) */
/* 1. Float - weighted total points (<= 100) */
/* */
/* Output: */
/* letter grade using pseudocode grading policy */
/* */
/* Algorithm: Comparisons using if-then-else */
/* */
/****************************************************/
#include <iostream>

using namespace std ;

int main()
{

Declare score and grade appropriately as variables. (Highlighted in yellow)

// read in total score

cout << endl ;
cout << "Enter total score (float, must be <= 100) : " ;
cin >> score ;

 

Write C++ if-then-else statements to determine course grade,
using the grading policy stated in the pseudocode. (Highlighted im yellow)

 

// display the result

cout << endl ;

 

cout << "Your grade for CMIS 102 is: " << grade << endl ;

return (0); // terminate with success
}

Test Plan for Exercise 1

Test your code with the following numbers:

85.0, 65.0001, 54.99999, -33.3, 100, 90, 150

Same methode.

Uplaodethe word template to wikiesend.
Customer: replied 7 years ago.
Here you go. http://wikisend.com/download/519900/Exercise 1.docx
Ok.

GOt the file.I am working on it.
Customer: replied 7 years ago.
Thanks
Can you open this as a new question?

Mention "to lifesaver" on top of the question to direct the question to me.

ALso please note that we receive more payment from thebonus you leave.SO please consider that fact.Can't mention the reates.

SO you may open the question for a low price but the more bonus you add ,more we ge paid.

Thanks.IF you face any problem we can continue here.
Customer: replied 7 years ago.
OK

Related Programming Questions