Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USE C++ ONLY PLEASE Given an input file of zero or more three-dimensional vectors formatted as ' ' where: < is the less than character

USE C++ ONLY PLEASE

Given an input file of zero or more three-dimensional vectors formatted as '<' x-coordinate ',' y-coordinate ',' z-coordinate '>' where:

  • < is the less than character
  • , is the comma character
  • > is the greater than character, and,
  • x-coordinate, y-coordinate, and z-coordinate are all double floating-point values

and all of these occur possibly with whitespace before and after each item. (NOTE: The single quotes around '<', ','. and '>' are not part of the input.) Thus, an example input file could be:

<1,-1,10> < 2 , -2,20 ><3,-3.3,30><-5,5,-50.5> 

You are to write a program that reads in from standard input (i.e., std::cin) all three dimensional vector values until an error (e.g., failed input or some other stream error) or EOF occurs. As the program reads in each vector, the program must do the following:

  • keep a running count of the number of vectors successfully read in, and,
  • add each subsequent vector to the previous vector sum.

The vector sum obviously will start with an all-zero vector value before any vector is read in. (Ensure you hard-code this in your program. Do not assume variables will get set to zero!)

Your program must produce its output as follows:

  • the first line must output "count: " (i.e., count: followed by a space, without the quotes) followed by the number of vectors read in, and,
  • the second line must output "sum: " (i.e., sum: followed by a space, without the quotes) followed by the final vector sum. (If there are no valid vectors in the input, then the all-zero vector needs to be output.)

Your program must produce the correct output regardless of the input provided to it --so ensure you do proper input checking.

Sample Program Run

Given an input.dat file such as:

<1,-1,10> < 2 , -2,20 ><3,-3.3,30><-5,5,-50.5> 

Then compiling a program (say it is called a01.cpp) and running it with input.dat redirected to its standard input, would look like this at a Linux/Unix shell prompt:

$ g++ -Wall -Wextra -o a01.exe a01.cpp $ ./a01.exe  $ 

since there are four 4 vectors in input.dat.

When done to submit your assignment by uploading only your C++ SOURCE CODE (do not upload the compiled executable!) using the upload area later on this page. Realize that your assignment may be tested with other input than what is shown above --so ensure your program can handle all inputs including nothing, input with vector, invalid vector, and/or non-vector data, etc. Clearly your code will only process all valid three-dimensional vectors until there is invalid input, an error, etc. and will ignore anything else that may remain unprocessed in the input.

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

Step: 3

blur-text-image

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 Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions

Question

2. Place a value on the outcomes.

Answered: 1 week ago