Question
I need this solution using C++
Write a report over programming. Include numbers on your submission to identify which part of the assignment you are taking c
0 0
Add a comment Improve this question Transcribed image text
Answer #1

2)C++ code to print to an csv file:

  1. #include <iostream.h> // inlcude iostream and string libraries
  2. #include <fstream.h>
  3. #include <string.h>
  4. using namespace std;
  5. ofstream outputFile; // create an ofstream for the file output
  6. ofstream fs
  7. filename = "exampleOutput.csv";// create a name for the file output std::string
  8. int i; int A; int B; int C; // create some variables for demonstration
  9. int main(int argc, char** argv)
  10. {
  11. fs.open(outputFile,filename); // create and open the .csv file
  12. outputFile << "Column A" << "," << "Column B" << "Column C" << std::endl; // write the file headers
  13. int i = 1;// i is just a variable to make numbers with in the file
  14. for (int counter = 0; counter < 10; counter++)// write data to the file
  15. {
  16. A = i + 5; // make some data
  17. B = i + 10;
  18. C = i + 20;
  19. outputFile << A << "," << B << "," << C << std::endl;// write the data to the output file
  20. i = i * 5; // increase i
  21. }
  22. outputFile.close(); // close the output file
  23. return 0;
  24. }

C++ code to read from a csv file:

  1. #include <string>
  2. #include <vector>
  3. #include <sstream> //istringstream
  4. #include <iostream> // cout
  5. #include <fstream> // ifstream
  6. using namespace std;
  7. /**
  8. * Reads csv file into table, exported as a vector of vector of doubles.
  9. * @param inputFileName input file name (full path).
  10. * @return data as vector of vector of doubles.
  11. */
  12. vector<vector<double>> parse2DCsvFile(string inputFileName) {
  13.     vector<vector<double> > data;
  14.     ifstream inputFile(inputFileName);
  15.     int i = 0;
  16.     while (inputFile) {
  17. i++;
  18.         string s;
  19.         if (!getline(inputFile, s)) break;
  20.         if (s[0] != '#') {
  21.             istringstream ss(s);
  22.             vector<double> record;
  23.             while (ss) {
  24.                 string line;
  25.                 if (!getline(ss, line, ','))
  26.                     break;
  27.                 try {
  28.                     record.push_back(stof(line));
  29.                 }
  30.                 catch (const std::invalid_argument e) {
  31.                     cout << "NaN found in file " << inputFileName << " line " << l
  32.                          << endl;
  33.                     e.what();
  34.                 }
  35.             }
  36.             data.push_back(record);
  37.         }
  38.     }
  39.     if (!inputFile.eof()) {
  40.         cerr << "Could not read file " << inputFileName << "\n";
  41.         __throw_invalid_argument("File not found.");
  42.     }
  43.     return data;
  44. }
  45. int main()
  46. {
  47.     vector<vector<double>> data = parse2DCsvFile("test.csv");
  48.     for (auto l : data) {
  49.         for (auto x : l)
  50.             cout << x << " ";
  51.         cout << endl;
  52.     }
  53.     return 0;
  54. }
Add a comment
Know the answer?
Add Answer to:
I need this solution using C++ Write a report over programming. Include numbers on your submission...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a report over programming. Include numbers on your submission to identify which part of the...

    Write a report over programming. Include numbers on your submission to identify which part of the assignment you are taking care of. 1. (10 points) Include a title that explains in a sentence what you learned or noticed. 2. (70 points) Include your code for the programming assignment Write a code to print to a csv file and read from a csv file 3. (10 points) The output of your code that shows what you have works. 4. (10 points)...

  • i need the answer for this python question using dictionary method please!!! points) Attached to the...

    i need the answer for this python question using dictionary method please!!! points) Attached to the Exam #4 code Assignment in Tracs you ## will find a file, "text.txt". Text is stored 1 sentence per line. ## Write a program below that reads the file contents and displays ## the following: 1. Number of uppercase characters in the file 2. Number of lowercase characters in the file 3. Number of digits in the file. 4. Number of whitespace characters in...

  • I need help with this assignment in C++, please! *** The instructions and programming style detai...

    I need help with this assignment in C++, please! *** The instructions and programming style details are crucial for this assignment! Goal: Your assignment is to write a C+ program to read in a list of phone call records from a file, and output them in a more user-friendly format to the standard output (cout). In so doing, you will practice using the ifstream class, I'O manipulators, and the string class. File format: Here is an example of a file...

  • To be done in C++ BER PROGRAMMING CONTENT: Submission request: For each program below: supply a...

    To be done in C++ BER PROGRAMMING CONTENT: Submission request: For each program below: supply a copy of the source code provide a screenshot of the output W if you use an online compiler like onlinegdb.com, the link of your final code. 4) (10 points) Static Variables Go to the following link (https://onlinegdb.com/HJd49mBcm) and fork the code so that you can write your own version of the function discount ( to achieve the goal as described in the comments. As...

  • Using C++ Skills Required Create and use classes Exception Handling, Read and write files, work vectors....

    Using C++ Skills Required Create and use classes Exception Handling, Read and write files, work vectors. Create Functions, include headers and other files, Loops(while, for), conditional(if, switch), datatypes,  etc. Assignment You work at the computer science library, and your boss just bought a bunch of new books for the library! All of the new books need to be cataloged and sorted back on the shelf. You don’t need to keep track of which customer has the book or not, just whether...

  • Need help with java programming. Here is what I need to do: Write a Java program...

    Need help with java programming. Here is what I need to do: Write a Java program that could help test programs that use text files. Your program will copy an input file to standard output, but whenever it sees a “$integer”, will replace that variable by a corresponding value in a 2ndfile, which will be called the “variable value file”. The requirements for the assignment: 1.     The input and variable value file are both text files that will be specified in...

  • To write a C++ program to find average of three integers using functions Objectives: To get...

    To write a C++ program to find average of three integers using functions Objectives: To get familiar with functions in C++ Task 1: Study the working of user-defined functions in C++ Task 2: To write a C++ program to find average of three integers using functions Programming Instructions: Make new project (Visual C++ Empty Project) named lab6 and add a C++ file named lab6.cpp to this project. (Some IDE may automatically generate main.cpp or source.cpp, then you just rename it...

  • write programs with detailed instructions on how to execute. code is java What you need to...

    write programs with detailed instructions on how to execute. code is java What you need to turn in: You will need to include an electronic copy of your report (standalone) and source code (zipped) of your programs. All programming files (source code) must be put in a zipped folder named "labl-name," where "name" is your last name. Submit the zipped folder on the assignment page in Canvas; submit the report separately (not inside the zipped folder) as a Microsoft Word...

  • C# P-9 Programming PLO-2 Measured: Design, implement, and evaluate computer solutions utilizing structured and object-oriented programming...

    C# P-9 Programming PLO-2 Measured: Design, implement, and evaluate computer solutions utilizing structured and object-oriented programming methodologies. Design a class named Contractor. The class should keep the following information: • Contractor name • Contractor number • Contractor start date Write one or more constructors, and the appropriate accessor and mutator functions for the class. For this assignment and P-10 you will have to include an algorithm for you program. This will be a word document attached to the dropbox. Submit...

  • write codes and give detailed explanation of how to execute. What you need to turn in:...

    write codes and give detailed explanation of how to execute. What you need to turn in: You will need to include an electronic copy of your report (standalone) and source code (zipped) of your programs. All programming files (source code) must be put in a zipped folder named "labl-name," where "name" is your last name. Submit the zipped folder on the assignment page in Canvas; submit the report separately (not inside the zipped folder) as a Microsoft Word or PDF...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT