Convert Flowchart to C++ - Programming I | COMP 150, Assignments of Computer Science

Material Type: Assignment; Class: Programming I; Subject: Computer Science; University: Harding University; Term: Spring 2010;

Typology: Assignments

Pre 2010

Uploaded on 08/19/2009

koofers-user-r7o
koofers-user-r7o ๐Ÿ‡บ๐Ÿ‡ธ

1

(1)

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Convert Flow Charts to C++
Introduction to Programming
10 Points
Convert the flow charts below into C++ programs. The output of your programs should match the examples below. Turn in a
printout of both .cpp files. You will not receive any credit if the programs do not compile, so you should be certain t hat they
work before making your printouts.
Extra credit: You will receive a bonus point for verifying the number X is greater than one in both programs. If the user enters a
number less than or equal to one, output an error message that tells the user to only enter 2 or above. The program should
then quit without trying to run the invalid X number through the algorithm.
Example output (input is in bold): Example output (input is in bold):
start
stop
Ask for a number
and call it X.
P
๎˜
1
D
๎˜
2
Is D > X - 1?
R
๎˜
Remainder
of X / D.
Is R = 0?
P
๎˜
0
D
๎˜
D + 1
Is P = 1?
Answer is
"Yes"
Answer is
"No"
yes no
no
yes
yes
no
Please enter a number:
11
The number 11 is prime.
start
Get a number
and call it X
D
๎˜‚
2
Is D = X?
Is the remainder
of X/D = 0?
Print D
X
๎˜‚
X / D
D
๎˜‚
D + 1
Print D
stop
yes
no
yes no
Please enter a number:
45
The prime factors of 45 are: 3 3 5

Partial preview of the text

Download Convert Flowchart to C++ - Programming I | COMP 150 and more Assignments Computer Science in PDF only on Docsity!

Convert Flow Charts to C++

Introduction to Programming

10 Points

Convert the flow charts below into C++ programs. The output of your programs should match the examples below. Turn in a

printout of both .cpp files. You will not receive any credit if the programs do not compile, so you should be certain that they

work before making your printouts.

Extra credit: You will receive a bonus point for verifying the number X is greater than one in both programs. If the user enters a

number less than or equal to one, output an error message that tells the user to only enter 2 or above. The program should

then quit without trying to run the invalid X number through the algorithm.

Example output (input is in bold): Example output (input is in bold):

start

stop

Ask for a number and call it X.

P  1

D  2

Is D > X - 1?

R  Remainder of X / D.

Is R = 0?

P  0

D  D + 1

Is P = 1?

Answer is "Yes"

Answer is "No"

yes no

no

yes

yes

no

Please enter a number: 11

The number 11 is prime.

start

Get a number and call it X

D  2

Is D = X?

Is the remainder of X/D = 0? Print D

X  X / D

D  D + 1

Print D

stop

yes

no

yes no

Please enter a number: 45

The prime factors of 45 are: 3 3 5