Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8537213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:50:49+00:00 2026-06-11T10:50:49+00:00

I have an assignment, and I’m trying to read a file and count how

  • 0

I have an assignment, and I’m trying to read a file and count how many lines does it has. I’m trying to use classes, but I have no clue on how to declare a string member in the class. Here is the code:

#include<iostream>
#include<cmath>
#include<fstream>
#include<istream>
#include<string>
#include<iomanip>

using namespace std;

// Clase Nodo 
class Nodo {

    Nodo* next;

public:
    Nodo() {};
    string strLinea;
string strAux1; // = "//p.";  
string strAux2; // = "//i.";  
string strAux3; // = "//d.";  
string strAux4; // = "//m.";

void SetVariables(string data)
{
       strLinea = data;
    }

//void SetData(float EPS, float DH)
void SetData(string S)
{ 
    strLinea = S;
};

void SetNext(Nodo* aNext) 
{ 
    next = aNext;
};

String Data() 
{ 
    return(strLinea);
};

Nodo* Next() 
{ 
    return next; 
};
};


class Lista {
    Nodo *head;

public:
    Lista() { head = NULL; };
    void Print();
    void Append(string strLinea);
    void Delete(string strLinea);
};



void Lista::Print() {

// ... Apuntador temporal ...
Nodo *tmp = head;

// ... No hay Nodos ...
if ( tmp == NULL ) {
cout << "EMPTY" << endl;
return;
}

// ... Existe un Nodo in the Lista ...
if ( tmp->Next() == NULL ) {
cout << tmp->Data();
cout << " --> ";
cout << "NULL" << endl;
}
else {
// ... Recorre la lista y la imprime ...
do {
    cout << tmp->Data();
    cout << " --> ";
    tmp = tmp->Next();
}
while ( tmp != NULL );

cout << "NULL" << endl;
}
}


 void Lista::Append(string strLinea){
 // ... Aquí crea a Nodo nuevo ...
 Nodo* newNodo = new Nodo();

 newNodo->SetData(strLinea);
 newNodo->SetNext(NULL);

 // ... Crea un apuntador temporal ...
 Nodo *tmp = head;

 if ( tmp != NULL ) {
 // ... El Nodo está en la Lista ...
 // ... Recorre la Lista ...
 while ( tmp->Next() != NULL ) {
     tmp = tmp->Next();
 }
 // ... El último Nodo de la lista ...
 tmp->SetNext(newNodo);
 }
 else {
 // ... Nuevo Nodo de la lista ...
 head = newNodo;
 }
}


void Lista::Delete(string strLinea){
    // ... Crea un Nodo temporal ...
    Nodo *tmp = head;

   // ... No hay Nodos ...
   if ( tmp == NULL )
      return;

   // ... Último Nodo de la Lista ...
   if ( tmp->Next() == NULL ) {
        delete tmp;
        head = NULL;
   }
   else {
    // ... Recorre los nodos ...
    Nodo *prev;
    do {


     if(tmp->Data() == strLinea) break;

         prev = tmp;
         tmp = tmp->Next();
    } while ( tmp != NULL );

    // ... Ajusta los Nodos ...
    prev->SetNext(tmp->Next());

    // ... Borra el Nodo actual ...
   delete tmp;
   }
  }




 int main(int argc, char* argv[])
 {
        string L;
        int intLineCounter = 0;

        Lista lista;



        ifstream infile;
        infile.open(argv[1], ios::in);
        if(argc != 2)
        {
             cout << "ERROR.\n";
             return 1;
        }
       if(infile.fail())
       {
            cout << "ERROR\n";
            return 1;
       }
       else
       {
            while(!infile.eof())
            {
                   getline(infile,L);
                   intLineCounter++;
                   cout<< L + "\n";
                   lista.Append(L);
            }
            infile.close();
            cout << "Total lines: " << intLineCounter << endl;
           return 0;
      }
   }

The problem is in the class in the declaration String Data(). How to declare it? how to fix it? any ideas ? any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:50:50+00:00Added an answer on June 11, 2026 at 10:50 am

    It should be

    string Data() 
    { 
        return(strLinea);
    };
    

    C++ is a case-sensitive language.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an assignment to read a file and output the average test scores.
I have assignment to work on producer and consumer problem by use thread and
I have an assignment about fftw and I was trying to write a small
I have an assignment to make a Tic-Tac-Toe consol game, but I'm a little
I have an assignment to correct an ambiguous BNF, but I am completely lost.
I have an assignment to use JavaBeans to create an online Banking application. I
I have an assignment, and it has (amongst others) two demands: make an installer
I have an assignment which is to import mpp file into database via ASP.NET
I have an assignment and we have a couple of classes given, one of
I have an assignment about uploading and downloading a file to a server. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.