C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 5th, 2004, 05:00 PM
Krazy_Killa Krazy_Killa is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 5 Krazy_Killa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
vectors

does anyone know how to read in student files into a record, and calculate the studen'ts overall mark based on arbitrary ratings for the lastname, firstname, midterm, final, and anywhere up to but not always 15 homework assignments?

Aswell, the person who is running the program will have to enter how much each thing is weighed... eg.
Code:
How much would you like the midterm to weigh?
30
How much would you like the final to weigh?
60
How much would you like the homework assignments to wiegh?
10


Each line in the file that gets read in will be seperated by a space and will always be in the same order like this.....
lastname firstname midterm final HW1 HW2 HW3 ... HW 15


this is how far i got, but i wasn't able to figure out how to use getline to get the entire line, also, i have no idea how to split up the line between the spaces.
Code:
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <vector>

using namespace std;

int main()
{
    ifstream marks(
    struct info;
    {
        string name;
        double mid, final;
        vector<double> homework;
    }; 
    info tempstud;
    while (!marks.eof)
    {   
        getline(marks >> tempstud);
         
        
        vector<info> class1;
        class1.push_back(tempstud);
    
  
  system("PAUSE");	
  return 0;
}


forget about all of the mistakes in the code, i didn't have much time to make this code, i just need help figuring out how to do this.

Reply With Quote
  #2  
Old November 6th, 2004, 06:17 AM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 6
No one here is going to do your homework for you. Have a go yourself and then when you've got specific questions about why certain errors happen or something post those.

-KM-

Reply With Quote
  #3  
Old November 7th, 2004, 09:37 PM
Krazy_Killa Krazy_Killa is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 5 Krazy_Killa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
i don't need anyone to do my homework. i know how to read a file, and i know that it read it line by line. but what i don't understand how, if you would have read properly, is how to getline on a file, and then split up the line where the spaces are.

Reply With Quote
  #4  
Old November 8th, 2004, 07:09 AM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 6
So go read a tutorial. Type what you need into google and you'll find a million and one articles, tutorials and howtos out there. Don't just get stuck and come here straight away.

-KM-

Reply With Quote
  #5  
Old November 8th, 2004, 10:56 PM
Krazy_Killa Krazy_Killa is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 5 Krazy_Killa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
i hate tutorials, everytime i read one, i get cofused.CAN SOMEONE PLEASE HELP ME!!!!!

Reply With Quote
  #6  
Old November 9th, 2004, 04:59 AM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 6
Programming is not easy. If it was then everyone could do it and the skill would be worth nothing. It takes time, patience and dedication to learn how to do things. You can't expect people to hand things to you on a plate. Even if they do then you won't have learnt anything which is the whole point of any course like that.

Find a tutorial, work through it and have a go at writing your own code. If there's part of the tutorial you don't understand then try googling for something about that. Take your time and when you really get stuck walk away for a while. If you still can't figure something out with a clear head then post something on here asking specific questions.

To get you started have a look for tutorials on file I/O for how to get things out of files a line at a time and what the issues are for the various methods. When you have got the lines what you need is a string tokenizer to split the lines up at the spaces. Be *VERY* careful if you use the standard library string tokenizer since it is broken beyond all belief.

-KM-

Reply With Quote
  #7  
Old November 12th, 2004, 11:28 PM
Krazy_Killa Krazy_Killa is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 5 Krazy_Killa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
then can someone please tell me whats wrong with my code right now?

the file that is being read in is as follows.

lastname firstname 80 86 -1
lastname firstname 80 86 76 84 92 75 60 100 72 90 68 -1
lastname firstname 80 86 76 84 92 75 -1
lastname firstname 80 86 76 84 92 75 60 100 72 -1

the numbers will all be different because all the students will get different marks.
the first two numbers are the midterm mark and the final mark.
all the numbers after that are the homework assignments. their can be a max of 10 homework marks, but there can also be no assaignments done. for every assignment with no mark, it should be considered 0. each line ends in -1 to mark the end of the homework assignments.

the code still isn't complete, but it's a start.

Code:
// read in student files into a record

// calculate the student's overall mark based on arbitrary ratings for....
// lastname firstname midterm final| hw 1, hw 2 .... hw 10 -1
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <vector>

using namespace std;

int main()
{
* *ifstream marks("c:/temp/students.txt");
* *struct stud
* *{
*string lastname, firstname;
* * * *float mid, final;
* * * *vector<double> homework;
* *}; 
* *stud tempstud;
* *while (!marks.eof())
* *{ * 
* * * *marks >> tempstud.lastname;
* * * *marks >> temtstud.firstname;
* * * *marks >> tempstud.mid;
* * * *marks >> tempstud.final;
* * * *marks >> tempHW;
* * * *while (tempHW != -1)
* * * *{
* * * * * *homework.pushback(tempHW)
* * * * * *marks >> tempHW;
* * * *} * *
* * * *vector<studinfo> class1;
* * * *class1.push_back(tempstud)
* *} * * * *
*system("PAUSE"); 
*return 0;
}

Reply With Quote
  #8  
Old November 14th, 2004, 01:30 PM
Krazy_Killa Krazy_Killa is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 5 Krazy_Killa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I fixed most of the problems, but i still have three. can someone help me.
Code:
// read in student files into a record

// calculate the studen'ts ove  rall mark based on arbitrary ratings for....
// lastname firstname midterm final| hw 1, hw 2 .... hw 10
#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;
}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > vectors


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT