Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 11-14-2004, 09:45 AM   #1 (permalink)
Androto
Mac Os X User(I hate win)
 
Join Date: Oct 2004
Posts: 138
Androto is on a distinguished road
Sort of same as gamehead

I have to create a code which does the same as gamehead200's code. i did this, and got 2 errors. all i want to know is what i did wrong, i don't need a whole new code, but if you're bored and you want to write your own code from scratch, them by all means, have fun.
Code:
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <vector>

using namespace std;

int main()
{
    ifstream marks("c:/temp/students.txt");
    int tempHW(0);
    struct stud
    {
        string lastname, firstname;
        float mid, final;
        vector<double> homework;
    }; 
    stud tempstud;
    vector<stud> class1;
    while (!marks.eof())
    {   
        marks >> tempstud.lastname;
        marks >> tempstud.firstname;
        marks >> tempstud.mid;
        marks >> tempstud.final;
        marks >> tempHW;
        while (tempHW != -1)
        {
            tempstud.homework.push_back(tempHW);
            marks >> tempHW;
        }    
        class1.push_back(tempstud);
    }
	cout << class1;
  system("PAUSE");	
  return 0;
}
Androto is offline   Reply With Quote
Old 11-14-2004, 01:36 PM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
Code:
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <vector>

using namespace std;

struct stud
{
   string lastname;
   string firstname;
   float mid;
   float final;
   vector<double> homework;
};

int main()
{
    ifstream marks("students.txt");
    int tempHW(0);
    stud tempstud;
    vector<stud> class1;
    while (marks >> tempstud.lastname)
    {
        marks >> tempstud.firstname;
        marks >> tempstud.mid;
        marks >> tempstud.final;
        marks >> tempHW;
        
        while (tempHW != -1)
        {
           tempstud.homework.push_back(tempHW);
           marks >> tempHW;
        }
        
        class1.push_back(tempstud);
    }

   for(unsigned i=0; i != class1.size(); ++i)
   {
      cout<<class1[i].lastname<<" "<<
      class1[i].firstname<<" "<<
      class1[i].final<<" "<<
      class1[i].mid<<" ";
      for(unsigned j = 0; j != class1[i].homework.size(); ++j)
      {
         cout<<class1[i].homework[j]<<" ";
      }
      cout<<endl;
   }

    system("PAUSE");
    return 0;
}
__________________
Valmont is offline   Reply With Quote
Old 11-14-2004, 05:35 PM   #3 (permalink)
Androto
Mac Os X User(I hate win)
 
Join Date: Oct 2004
Posts: 138
Androto is on a distinguished road
thx for the help.
Androto is offline   Reply With Quote
Old 11-16-2004, 02:07 PM   #4 (permalink)
Androto
Mac Os X User(I hate win)
 
Join Date: Oct 2004
Posts: 138
Androto is on a distinguished road
DELETED

Last edited by Androto; 11-19-2004 at 07:54 AM.
Androto is offline   Reply With Quote
Old 11-18-2004, 03:09 PM   #5 (permalink)
Androto
Mac Os X User(I hate win)
 
Join Date: Oct 2004
Posts: 138
Androto is on a distinguished road
nvm, i fixed it.

Last edited by Androto; 11-18-2004 at 04:19 PM.
Androto is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
sorting objects arrays by object properties sde Java 28 08-05-2004 05:51 AM
Need an alphabetic sort algorithm SkittlesAreYum Java 4 05-08-2003 11:02 PM
sort arrays Apodysophilia Java 9 04-04-2003 06:18 AM


All times are GMT -8. The time now is 05:05 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting