Thread: Is anyone smart enough to complete this or tell me what it means

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    6

    Is anyone smart enough to complete this or tell me what it means

    Your program will read two data files, set up in the same folder as was done for the first assignment. These data files are called input2a.dat and input2b.dat.
    You program should have the following steps:

    1. Read the team member’s family names from the first data file and store them (wherever your program design says it is best to do so). There will be 16 names. You may then close the first file.

    2. Sort the above into alphabetical order.

    3. Read the second data file until end-of-file. The data in this file will consist of a name followed by a number of runs (integer) followed by a character that will designate how the batman was “out”. The characters used will be b, l, c, s, r, o, and n (for notout). It will also be possible for this file to be empty.

    4. For each data set, find the correct batter in your list, add in the number of runs, and record how the batter was “out” (a counter for each type of “out”).

    5. Calculate the averages of all players.

    6. Produce an alphabetically ordered list of the players and their performances. Use an output format that will right-justify the name.

    7. Sort the list into decreasing order of batting average.

    8. Produce a similar list of results to the one above.
    Observation: While it is possible to complete this assignment using a number of parallel arrays, your design will be better and easier to work with, if you define your own structured type (it is best to use our naming convention of structname_t), and then have a single array of these objects. Your design will also benefit from having a number of functions. A solution that does not have well designed functions to perform major tasks, will be marked down significantly.

    OUTPUT:
    Output should be produced along the following guidelines:
    Name should be right-justified as stated above, Number of Innings and Number of Not-Outs are 3 digit integers, Number of Runs is up to 5 digits long, average should allow for a range from 0.00 to 999.99. Use headings as appropriate to display the data as a table. E.g.
    Team Batting - Alphabetical Order How Out
    Name Inn NO Runs Avge B L C S R O
    ---------------------------------------------------------
    Beer 0 0 0 0.00 0 0 0 0 0 0
    Clarke 3 0 96 32.00 0 1 2 0 0 0
    Copeland 2 1 35 35.00 0 0 1 0 0 0
    ………… etc.

    Note that alphabetical order does not include the leading spaces that are part of the right-justification of the output of the name.

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Hahahahahahahahaha

    I love how you also chose a girly username. That usually works.

  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    6
    yeah i thought it might, but i forgot people on here are smarter than the average bear

  4. #4
    spaghetticode
    Guest
    Extra points for honesty.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Anyway, what do you think it means?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Oct 2011
    Posts
    6
    I have a vague idea and i'm working through it but my university does not provide a very good computer class for us mech eng students so i'm more or less looking for someone to tell me where i can get information. I found some now and it seems to be working for me, sorry for wasting time

  7. #7
    ‡ †hë Ö†hÈr sîÐè ‡ Nor's Avatar
    Join Date
    Nov 2001
    Posts
    299
    You should realy start paying more attenchion in class. - i can't spell.


    Quote Originally Posted by jasminn View Post
    Your program will read two data files, set up in the same folder as was done for the first assignment. These data files are called input2a.dat and input2b.dat.
    you will have to read to files, so declare to file input handles. lets say
    Code:
    fstream input1, input2
    Quote Originally Posted by jasminn View Post
    You program should have the following steps:

    1. Read the team member’s family names from the first data file and store them (wherever your program design says it is best to do so). There will be 16 names. You may then close the first file.
    You should really have some information on the file format being used. but lets asume that the names are the very first part of each line in the file

    Quote Originally Posted by jasminn View Post
    2. Sort the above into alphabetical order.
    Please see std::list sort(), or int memcmp(const void*, const void*, size_t length);

    Quote Originally Posted by jasminn View Post
    3. Read the second data file until end-of-file. The data in this file will consist of a name followed by a number of runs (integer) followed by a character that will designate how the batman was “out”. The characters used will be b, l, c, s, r, o, and n (for notout). It will also be possible for this file to be empty.
    This is where you should pay attention more. b,l,c,s,r,o,n all have indivisual meanings.
    n = player is not out,
    b = player is current batter?
    l = ??? etc, etc, etc...

    Quote Originally Posted by jasminn View Post
    4. For each data set, find the correct batter in your list, add in the number of runs, and record how the batter was “out” (a counter for each type of “out”).
    Store some information to your player objects.
    Quote Originally Posted by jasminn View Post
    5. Calculate the averages of all players.

    6. Produce an alphabetically ordered list of the players and their performances. Use an output format that will right-justify the name.
    hint: << std::setprecision

    Quote Originally Posted by jasminn View Post
    7. Sort the list into decreasing order of batting average.
    Code:
    for( std::list<players_t>::iterator it = players.begin(); it != players.end(); it++){
        for( std::list<players_t>::iterator next = players.begin(); next != players.end(); next++){
            if( next->average > it->average )
                players.swap( it, next );
        }
    }

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Nor View Post
    Please see std::list sort(), or int memcmp(const void*, const void*, size_t length);
    There is also std::sort which may be more appropriate.
    Furthermore, what do you intend for the OP to use memcmp for? It's usually a bad thing in C++, so do expand on why you think it's a good idea.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    ‡ †hë Ö†hÈr sîÐè ‡ Nor's Avatar
    Join Date
    Nov 2001
    Posts
    299
    Quote Originally Posted by Elysia View Post
    what do you intend for the OP to use memcmp for?
    if (s)he does not want to use a predefined sort algriumthim....errr spelling
    but instead make his/her own. memcmp is an easy way to do it
    Code:
    #include <iostream>
    #include <string>
    
    //This function will output 10 elements to the user.
    void output_array_to_user(std::string * pointer){
    	int x = 10;
    	std::cout << "Output: ";
    	do{
    		std::cout << pointer->c_str() << " ";
    		x--;
    		pointer++;
    	}while( x );
    	std::cout << std::endl;
    }
    
    //This function will swap elements in the array
    void swap_array_elements( std::string* a, std::string* b){
    	std::string tmp;
    	tmp = *a;
    	*a = *b;
    	*b = tmp;
    }
    
    int main(int argc, char* argv){
    	/*This is our array of words that will be sorted.
    	  This could easly be ANY type of data */
    	std::string words[10] = 
    		{ "apples", "are", "fun", "to", "eat", "and", "keep", "the", "doctor", "away" };
    
    	//Display array to user
    	output_array_to_user( words );
    
    	//These loops will sort the array.
    	for( int x = 0; x < 10; x++ ){
    		for( int y = 0; y < 10; y++){
    			//When comparing two different words, size matters.
    			//Always remimber not to compare more than is there.
    			if( words[x].size() == words[y].size() ){
    				if(	memcmp(words[y].c_str(), words[x].c_str(), words[x].size() ) > 0 )
    					swap_array_elements( &words[x], &words[y] );
    			}
    			if( words[x].size() > words[y].size() ){
    				if(	memcmp(words[y].c_str(), words[x].c_str(), words[y].size() ) > 0 )
    					swap_array_elements( &words[x], &words[y] );
    			}
    			if( words[x].size() < words[y].size() ){
    				if(	memcmp(words[y].c_str(), words[x].c_str(), words[x].size() ) > 0 )
    					swap_array_elements( &words[x], &words[y] );
    			}
    		}
    	}
    
    	output_array_to_user( words );
    
    	return 0;
    }
    Try to help all less knowledgeable than yourself, within
    the limits provided by time, complexity and tolerance.
    - Nor

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    This is just bad programming. std::string already implements an operator < for easy sorting.
    In fact, any container where it makes sense for it to be "less" than something else, implements this as well.
    What you are doing is wrong. You are circumventing the container's pre-defined mechanisms.
    Furthermore, if you don't know how to use memcmp properly, you could end up hurting yourself.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    ‡ †hë Ö†hÈr sîÐè ‡ Nor's Avatar
    Join Date
    Nov 2001
    Posts
    299
    Quote Originally Posted by Elysia View Post
    You are circumventing the container's pre-defined mechanisms.
    Yes mam, I am, and it is bad programming practice.
    it would be much better to use template structer to define the sort.
    but i'm trying to keep the reply as simple as possible.

    Quote Originally Posted by Elysia View Post
    Furthermore, if you don't know how to use memcmp properly, you could end up hurting yourself.
    Yes, the key word being 'if'. Please read the notes on line 36.

    here is the above code done properly. The output of these two programs are the same, as well as all the logic involved in sorting them
    Code:
    #include <iostream>
    #include <string>
    #include <vector>
    #include <algorithm>
    
    //This function will output 10 elements to the user.
    void output_array_to_user(std::vector<std::string> &array){
    	std::cout << "Output: ";
    	int x = 0;
    	do{
    		std::cout << array[x].c_str() << " ";
    		x++;		
    	}while( x != array.size() );
    	std::cout << std::endl;
    }
    
    int main(int argc, char* argv){
    	/*This is our array of words that will be sorted.
    	  This could easly be ANY type of data */
    	std::vector<std::string> words;
    
    	words.push_back( "apples" );
    	words.push_back( "are" );
    	words.push_back( "fun" );
    	words.push_back( "to" );
    	words.push_back( "eat" );
    	words.push_back( "and" );
    	words.push_back( "keep" );
    	words.push_back( "the" );
    	words.push_back( "doctor" );
    	words.push_back( "away" );
    	//Display array to user
    	output_array_to_user( words );
    
    	//Sort the array
    	std::sort( words.begin(), words.end() );
    
    	//display the array to the user
    	output_array_to_user( words );
    
    	return 0;
    }
    Try to help all less knowledgeable than yourself, within
    the limits provided by time, complexity and tolerance.
    - Nor

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Nor View Post
    Yes mam, I am, and it is bad programming practice.
    it would be much better to use template structer to define the sort.
    but i'm trying to keep the reply as simple as possible.
    You just have used str1 < str2 directly. No need for memcmp or anything else to determine which string is before the other.
    There was no need for complexities, nor any memcmp.

    Yes, the key word being 'if'. Please read the notes on line 36.
    Yeah, I didn't say it was wrong. I said it was dangerous.
    I didn't test your code, but it looks right. Albeit it is, however, a lot more complicated than it needs to be.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what does ROL means
    By bubblegum in forum C Programming
    Replies: 0
    Last Post: 03-08-2008, 09:20 AM
  2. What does the following means?
    By EeeK in forum C Programming
    Replies: 2
    Last Post: 10-27-2003, 10:15 PM
  3. Anyone know what this means?
    By bigblack in forum C++ Programming
    Replies: 1
    Last Post: 04-15-2002, 07:19 PM
  4. Does anyone know what this means
    By killerasp in forum C++ Programming
    Replies: 3
    Last Post: 02-08-2002, 01:41 AM
  5. What this SQL means ?
    By manova in forum C++ Programming
    Replies: 2
    Last Post: 12-16-2001, 02:02 PM