What did I do wrong in OOP in C++

Miel

I code my programe for showing student profile

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    int array_size = 500;
    char * array = new char[array_size];
    int position = 0;

    ifstream fin("data.txt");

    if(fin.is_open())
    {
        while(!fin.eof() && position < array_size)
        {
            fin.get(array[position]);
            position++;
        }
        array[position-1] = '\0';

        for(int i = 0; array[i] != '\0'; i++)
        {
            cout << array[i];
        }
    }
    else
    {
        cout << "File could not be opened." << endl;
    }
    return 0;
}

and here is data.txt

Name : Napat Naraprapang
ID : 45608

Subject                             Credit      Grade

Thai                                 1.0          4 
Mathematics                          1.0          4
Social Studies                       1.0          4
Health and Physical Education        0.5          4
Thai Dance                           0.5          3
Vocational Education and Tecnology   0.5          4
English                              1.0          4
Advance Mathematics                  2.0          4
Physics                              1.5          3.5       
Chemistry                            1.5          3
Biology                              1.5          4
Handball                             0.5          4
Computer Project                     1.0          4
English Reading Analysis             1.0          4
English for Information              0.5          4

I want to calculate gpa and show it below, should I do? Actually, first time I created function to calculate gpa before

for(int i = 0; array[i] != '\0'; i++)
            {
                cout << array[i];
            }
        }
        else

And when I complied it, everything was lose, I dont know what did I do wrong? and what should I do? Thank you for your all replies!

shauryachats
  1. Firstly, /n is not a single character. \n is the newline character which you require.
  2. getline(myfile.line) is an invalid statement, as myfile, a , an object of ifstream, has no member line.

    Change it to:

    std::getline(myfile,line);
    

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

What did I do wrong with mxGetPr

What did i do wrong in this JavaScript code

What did I do wrong when I installed this theme?

Java 8 times faster with arrays than std::vector in C++. What did I do wrong?

What did I do wrong with parsing MNIST dataset with BinaryReader in C#?

What did I do wrong in my dual drive partitioning?

It always says Correct! What did I do wrong?

While (true) problems, what did i do wrong?

My quickSort is not working correctly. What did I do wrong?

Project Euler: Largest palindrome (Python). What did I do wrong?

What did I do wrong with my 301 redirects?

What did I do wrong ....? ( calculating the amount of cupcakes per person )

program does not work, what did I do wrong?

What did I do wrong? UPDATE with condition and LIKE postgres

I created cpt in WP and did not show the taxonomy, what did I do wrong?

button triggers frame.repaint() even when I did not tell it to. What did I do wrong?

What's wrong with the smarty arithmetic I did?

Post in python. What I did wrong? :(

Anyone knows what I did wrong in this program?

I was trying to access "UserController@edit" but it doesn't found, what did i do wrong?

Hello, I request assistance with my code and i don't know what i did wrong c#

My rust code compiled to wasm is slower than js, what did i do wrong?

Simple WebRTC Example! But why it didn't work & what did I do wrong?

Installing jQuery-UI is missing all style sheets, what did I do wrong?

In school and trying to create the classic guess a number game. What did I do wrong?

git still shows files as untracked despite .gitignore and rm -r --cached. What did I do wrong?

Uploading file, axios works but fetch API doesn't, what did I do wrong?

webscrape script is outputting data 3 times. What did I do wrong?

What did I do wrong? Trying to get user to enter numeric values for different variables