Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A prime number is an integer greater than 0 that has exactly 2 different factors, 1 and itself. A composite number is a positive integer

A prime number is an integer greater than 0 that has exactly 2 different factors, 1 and itself. A composite number is a positive integer that has at least 1 positive divisor other than 1 and itself. For example, 2 and 17 are prime, 4 and 25 are composite.

Create a C++ program that will run in batch mode (read its input from a file from Linux Redirection). The input file will contain a series of integers that could be positive, negative, or zero. The program must do the following:

For each integer read from the file, display (in the form of a nicely formatted table) (see sample below): -the number -if it is positive (greater than 0), the number of factors it has -if it is prime, the word "prime" -if it is composite, the word "composite" -if it is neither prime nor composite, do not display a factor count or a descriptive term

Continue processing integers until the end of file is encountered. After all numbers have been processed, display the number of values in each category with appropriate labels. FORMATTING REQUIREMENTS

-Include labels for each column. -Right justify numbers (assume input values will be >= -100,000,000 and <= 100,000,000). -Left justify the words describing in each number (prime, composite). -DO NOT USED USER DEFINED FUNCTIONS IN THE PROGRAM. The program should consist of whatever loops are necessary (while, for) and should have if statements.

ASSUMPTIONS

-Each value in the data file will be an integer between -100,000,000 and 100,000,000 inclusive and the numbers will be separated by whitespace (blanks or linefeeds). -The input file will not be empty. -The last line of the input file will be terminated by a linefeed.

Sample terminal session: [keys]$ more data4three 17 -2 4 188 0 31 1054 -56 123456 [keys]$ g++ assign.cpp [keys]$ ./a.out < data4three

NUMBER FACTORS CATEGORY 17 2 prime -2 4 3 composite 188 6 composite 0 31 2 prime 1054 8 composite -56 123456 28 composite Primes: 2 Composites: 4 Neither prime or composite: 3

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Application Development And Design

Authors: Michael V. Mannino

1st Edition

0072463678, 978-0072463675

Students also viewed these Databases questions

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago