Question exercise 3.5 Accelerated C++

This is a discussion on Question exercise 3.5 Accelerated C++ within the C++ Programming forums, part of the General Programming Boards category; Hello, Schould I write a programm which only stores the names and the grades of a student. Or must I ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    230

    Question exercise 3.5 Accelerated C++

    Hello,

    Schould I write a programm which only stores the names and the grades of a student. Or must I do some calculation with it.

    For a Dutch person who's don't speak English very well it's a difficult book to follow.

    Roelof

  2. #2
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    905
    Please state the problem.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    230
    Hello,

    The problem is that I think I donīt understand what the exercise wants.

    Roelof

  4. #4
    Registered User
    Join Date
    Mar 2010
    Posts
    109
    I think he meant to state the exercise. Otherwise, we can't help you.

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Surely someone in Holland has written a book for C++ beginners in Dutch? I couldn't find any with google, but then of course I entered "C++ books Dutch" which I think the Dutch word for Dutch has more oo's in it.

    On the other hand, if you're getting into programming, I guess you might as well improve your English reading skills, since it would seem that everyone else who got into programming did not bother later to produce native language docs for their fellows -- big shame IMO.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    230
    Oke,

    The exercise is ;

    Write a program that will keep track of grades for several students at once. The program
    could keep two vectors in sync: The first should hold the student's names, and the second the
    final grades that can be computed as input is read. For now, you should assume a fixed
    number of homework grades.

    Roelof

  7. #7
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Hmmm, I would say then your previous exercise experience will come in handy, because that also used "parallelism" in the vectors.

    So this one will be similar, but slightly more complicated. Rather than a count of the words in the first vector, the second vector will be an average of the grades received by that student. In other words, yes you need to do a calculation: average the grades.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  8. #8
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    MK27: No, actually, the Dutch word for Dutch doesn't have a single O in it :P.

    Let me translate the problem...
    Schrijf een programma die cijfers bijhoudt voor verschillende studenten tegelijkertijd. Het programma zou twee vectoren tegelijkertijd kunnen bevatten: de eerste zou de namen van de studenten bevatten, en de tweede de uiteindelijke cijfers die berekend kunnen worden terwijl de invoer gelezen wordt. Voor deze opgave moet je aannemen dat het aantal huiswerk cijfers van te voren bekend is (dat is, vast staat).

    There. Does it make more sense now..?

  9. #9
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by EVOEx View Post
    (dat is, vast staat).
    Hey look that's my avatar byline! What does it mean? Sounds almost Descartesque to me.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  10. #10
    Registered User
    Join Date
    May 2010
    Posts
    230
    Oke,

    So i have to write a programm which write students name to a vector and another vector who contains the average of that student (the average of the inputted numbers) .

    Thatīs not to difficult or do I still mistaken

    EVEEx , are you a Dutch person.

    Roelof

  11. #11
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by roelof View Post
    EVEEx , are you a Dutch person.
    Pretty sure s/he's from outer space, but you can always "Post Message" here:

    http://cboard.cprogramming.com/member.php?u=33651
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  12. #12
    Registered User
    Join Date
    May 2010
    Posts
    230
    Hello,

    I need your help one more time.
    I have this a code :
    Code:
    #include <algorithm>
    #include <iomanip>
    #include <ios>
    #include <iostream>
    #include <string>
    #include <vector>
    
    using namespace std ;
    
    vector <string> names ;
    vector < double> grades ;
    
    typedef vector<double>::size_type vec_sz;
    vec_sz size ;
    
    typedef vector<double>::size_type vec_sz;
    vec_sz size2 ;
    
    double grade=0  , mid=0 , totaal=0  ;
    
    int teller, teller2, begin, eind ;
    
    int main()
    {
    	// ask for and read the student's name
        cout << "Please enter the first name: ";
        string name;
    
    	while (cin >> name)
    	{
    		cout << "Hello, " << name << "!" << endl;
            names.push_back (name);
    
    
            vector<double> homework;
            double x;
    
           for (teller = 0 ; teller < 5 ; teller++ )
           {
               cout << "Enter the " << teller +1 << "th grade : "  ;
               cin >> grade ;
               grades.push_back(grade) ;
                      }
    
            cout << endl ;
            cout << "Please enter the next name: ";
            string name;
    	}
    
         // compute the average homework grade of student and print it to screen
         size = names.size();
         for (teller=0; teller < size ; teller++)
         {
             begin=teller*5 ;
             eind=begin+4 ;
             for ( teller2 == begin ;  teller2 < eind ; teller2++);
             {
               totaal = totaal + grades[teller2];
               cout << "Cijfer gevonden : " << grades[teller2] << endl ;
               cout << "positie cijfer : " << teller2 << endl ;
               cout << "leerling nummer : " << teller << endl ;
               cout << "begin : " << begin << endl ;
               cout << "einde : " << eind << endl ;
             }
              mid = totaal / 5 ;
              totaal = 0 ;
               cout << "Student " << names [teller] << " has a average of " << mid << endl ;
            }
    
    
      return 0 ;
    }
    I wonder why the numbers don't add up.
    The second for loop looks to start at 4 instead of 0.

    Does anyone see why ??

    Roelof
    Last edited by roelof; 06-19-2010 at 03:57 AM.

  13. #13
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by MK27 View Post
    Hey look that's my avatar byline! What does it mean? Sounds almost Descartesque to me.
    Right... Well... Erm... Okay... Well, I tried to translate "fixed" in the sentence, but I couldn't find a good Dutch word. So I made it "[...] is know (that is, stays the same)". It's not really possible to translate, but basically it is "that is, stays the same" or "that is, is fixed". So yeah, quite Descartesque :P.

    @roelof: Yeah, I'm Dutch. Or at least, it's my task of my alien tribe to learn to live as one, so we can invade it soon... (2012, I believe...)

    Now, seriously:
    Are you using Windows or Linux? In Linux I know EOF is ctrl+D, not ctrl+Z. ctrl+Z in Linux stops the program for a while (until you type either fg or bg or do something else with it). So try Ctrl+D. In Windows, I'm not sure what key combination is EOF...
    But the while condition on your inner loop seems wrong:
    Code:
    teller*5+4
    I'm not sure it will always be true, but it definitely will be most of the time ;-).

    Also, the exercise states it's best to calculate the average as you read it, rather than after pushing all grades into the vector. So first read it, calculate the average, and push only that into the vector. That should make things easier.

    Also, your indentation can be a lot better...


    EDIT: I see you edited your post even before I was able to reply... Please make a new post on updates, as I have no idea what has changed now.

  14. #14
    Registered User
    Join Date
    May 2010
    Posts
    230
    Hello EVOEx,

    So read in 5 numbers by a loop and 5 variables then calculate the average and put this in a vector.

    I will try to change the code for that .

    Roelof

  15. #15
    Registered User
    Join Date
    May 2010
    Posts
    230
    Hello EVOEx,

    What do you think about this code
    Code:
    #include <algorithm>
    #include <iomanip>
    #include <ios>
    #include <iostream>
    #include <string>
    #include <vector>
    
    using namespace std ;
    
    vector <string> names ;
    vector < double> grades ;
    
    typedef vector<double>::size_type vec_sz;
    vec_sz size ;
    
    string name ;
    double grade , totaal, mid;
    int teller ;
    
    int main()
    {
    	// ask for and read the student's name
        cout << "Please enter the first name: ";
    
    	while (cin >> name)
    	{
    	    cout << endl ;
    		cout << "Hello, " << name << "!" << endl;
    		cout << endl ;
            names.push_back (name);
    
            // ask for and read the grades
            totaal = 0 ;
            for (teller=0; teller < 5 ; teller++)
            {
             cout << "Put in the " << teller +1 << "th grade : ";
             cin >> grade ;
             totaal = totaal + grade ;
            }
            // calculate the average of that student
            mid = totaal / 5 ;
            // put these value into the vector
            grades.push_back (mid);
            cout << endl ;
            cout << "Please enter the next name: ";
    	}
    	// print out the data
    	cout << endl ;
    	size = names.size();
    	for (teller=0 ; teller < size ; teller++)
    	{
    	    cout << "Student " << names[teller] << " has a average of " << grades[teller] << endl ;
    	}
        return 0 ;
    }
    Roelof

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question about a question
    By hausburn in forum C++ Programming
    Replies: 3
    Last Post: 04-25-2010, 05:24 AM
  2. SDL buffer channels question
    By TriKri in forum Game Programming
    Replies: 3
    Last Post: 12-09-2009, 04:52 PM
  3. Newbie question, C #
    By mate222 in forum C# Programming
    Replies: 4
    Last Post: 12-01-2009, 05:24 AM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  5. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21