Question

C++ I need to use the function getData to put in all my data using arrays....

C++

I need to use the function getData to put in all my data using arrays. I need the program to use a function called displayData and will output the text file called students.txt and it will be grabbing the name, gender, age, id, GPA.

Example of text file :

Joe Clarkson

M

13

863546

4.0

Klent Patterson

M

51

346347

2.4

It will just get the text file and say:

The person's name is : Joe Clarkson

The person's gender is : M

The person's age is : 13

The person's id is: 863546

The person's GPA is : 4.0

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hey here is answer to your question.

In case of any doubt comment below. Please UPVOTE if you Liked the answer.

#include <bits/stdc++.h>
using namespace std;
void getData(){
ifstream file("students.txt");
string str;
string name,gender;
int counter = 0;
  
vector<string> colour;
  
while (getline(file, str)) {
colour.push_back(str);
}
int temp;
for (int i = 0; i < colour.size()/5; i++) {
       temp = i*5;
cout<<"The person's name is : "    <<colour[temp]<<endl;
       cout<<"The person's gender is : "    <<colour[temp+1] <<endl;
       cout<<"The person's age is : "   <<colour[temp+2]<<endl;
       cout<<"The person's id is : "   <<colour[temp+3]<<endl;
       cout<<"The person's GPA is : "   <<colour[temp+4]<<endl;
   }
}

int main ()
{
   getData();
}

Add a comment
Know the answer?
Add Answer to:
C++ I need to use the function getData to put in all my data using arrays....
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
  • I need help solving this C++ problem please. A data file will be provided that contains...

    I need help solving this C++ problem please. A data file will be provided that contains the first names and student IDs for a class. Write a program that stores this information using parallel arrays in C++. Assume that the data file will be named "students.txt" and will contain information with no more than 100 students. You can also assume that none of the first names will contain any spaces. The program will need to contain four functions: Read data...

  • Hello I need help fixing my C++ code. I need to display in the console the...

    Hello I need help fixing my C++ code. I need to display in the console the information saved in the file as well have the content saved in the file output in a fixed position like the screenshot. Thanks. CODE #include<iostream> #include<fstream> #include<iomanip> using namespace std; //main function int main() {    //variable to store student id    int id;       //variables to store old gpa(ogpa), old course credits(occ), new course credits(ncc), current gpa(cur_gpa), cumulative gpa(cum_gpa)    float ogpa,...

  • Hello I need a small fix in my program. I need to display the youngest student...

    Hello I need a small fix in my program. I need to display the youngest student and the average age of all of the students. It is not working Thanks. #include <iostream> #include <iomanip> #include <fstream> #include <vector> #include <algorithm> using namespace std; struct Student { string firstName; char middleName; string lastName; char collegeCode; int locCode; int seqCode; int age; }; struct sort_by_age { inline bool operator() (const Student& s1, const Student& s2) { return (s1.age < s2.age); // sort...

  • Please help me do the java project For this project you will be reading in a...

    Please help me do the java project For this project you will be reading in a text file and evaluating it in order to create a new file that represents the Class that will represent the properties of the text file. For example, consider the following text file: students.txt ID              Name                              Age                    IsMale           GPA 1                Tom Ryan                       22                       True              3.1 2                Jack Peterson                31                       True              2.7 3                Cindy LuWho                12                       False             3.9 When you read in the header line, you...

  • Files given in this assignment (right-click on the file to download) Assignment7.cpp (need to complete) Student.h...

    Files given in this assignment (right-click on the file to download) Assignment7.cpp (need to complete) Student.h (Given. Just use it, don't change it!) Student.cpp (Partially filled, need to complete) 1. Assignment description In this assignment, you will write a simple class roster management system for ASU CSE100. Step #1: First, you will need to finish the design of class Student. See the following UML diagram for Student class, the relevant header file (class declaration) is given to you as Student.h,...

  • Please!!! need help asap!!!! write a C++program to analyze a small subset of the data that...

    Please!!! need help asap!!!! write a C++program to analyze a small subset of the data that has been collected. See file universities.txt .Use precisely seven parallel arrays: one for name of university, one for state, one for city, one for yearly tuition, one for enrollment, one for average freshman retention, and one for the percent of students who graduate with in six years. Note that the percentage of student accepted is not stored.An output file is opened in main() and...

  • Hello, I need to implement these small things in my C++ code. Thanks. 1- 10 characters...

    Hello, I need to implement these small things in my C++ code. Thanks. 1- 10 characters student first name, 10 characters middle name, 20 characters last name, 9 characters student ID, 3 characters age, in years (3 digits) 2- Open the input file. Check for successful open. If the open failed, display an error message and return with value 1. 3- Use a pointer array to manage all the created student variables.Assume that there will not be more than 99...

  • c++ write a program that reads all values from a text file "data.txt" and stores them in ID array valuesl I. The input process from the file should be terminated when a negative value is detec...

    c++ write a program that reads all values from a text file "data.txt" and stores them in ID array valuesl I. The input process from the file should be terminated when a negative value is detected. (An example of such a file is shown below). Also, the program should copy from values[ 1 any value which has even sum of digits and its index (location) to two new arrays evenArr 1 and idxArrl I, respectively. In addition, the program must...

  • i need to make a simple hash function for an id in my size_t function it...

    i need to make a simple hash function for an id in my size_t function it works it need to print out numeric numbers and it has to be six numbers i think i need a loop here what it print out input.txt bob 4517898 102 tell rd gill 4787456 103 hmm rd output.txt 126990 bob 4517898 102 tell rd 126990 gill 4787456 103 hmm rd #ifndef __CUSTOMER_H__ #define __CUSTOMER_H__ #include #include struct customer {    std::string name;    std::string...

  • I need only one  C++ function . It's C++ don't write any other language. Hello I need...

    I need only one  C++ function . It's C++ don't write any other language. Hello I need unzip function here is my zip function below. So I need the opposite function unzip. Instructions: The next tools you will build come in a pair, because one (zip) is a file compression tool, and the other (unzip) is a file decompression tool. The type of compression used here is a simple form of compression called run-length encoding (RLE). RLE is quite simple: when...

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