Thread: Beginners Contest, Others our Welcome

  1. #16
    Banned
    Join Date
    Jun 2005
    Posts
    594
    #3

    Keep track of money.... enter several amounts and what each
    amount pertains to (what did you buy), out put this in a nice
    format into a file, at the end of the file have a total spent
    where all information is added up.

  2. #17
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    OK, I pm'ed you my solutions. Dunno if the #3 one was what you were looking for, but it's the closest I could approximate based on the requirements you stated
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  3. #18
    Banned
    Join Date
    Jun 2005
    Posts
    594
    Thanks for all those who participated,
    if no one else signs up, winner will be declared
    for contest #2 and #3, and winner of contest #1
    will be decide by a post and poll in the c++
    board.

    Thank You

  4. #19
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    sent mine in for #3 if it's still open.

    edit: and #2

    edit2: this may be a little useless now, but you should also specify which midnight you're talking about... don't forget that midnight hits 24 times over the course of 24-hour period in different spots of the world :P
    Last edited by major_small; 06-27-2005 at 12:46 AM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  5. #20
    Banned
    Join Date
    Jun 2005
    Posts
    594
    Yea good point, midnight eastern time.

  6. #21
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542
    Points.. haha.. the more times I do the task.. the more points i get? Vote for me
    what does signature stand for?

  7. #22
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    Since the contest is over.. here is my source code for entry #1.
    Last edited by The Brain; 06-29-2005 at 12:13 PM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  8. #23
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Weren't there points for having the least lines? Here's mine. Too bad I missed the thing about prompting for the input file name...
    Code:
    #include <fstream>
    #include <string>
    
    int main()
    {
    	std::fstream in("in.txt", std::ios::in), out("out.txt", std::ios::out);
    	std::string str, token;
    	std::getline(in, str, '\0');
    	for(;;)
    	{	//token gets everything up to the first vowel, str is truncated from the beginning to where token starts.
    		str = str.substr((token = str.substr(0, str.find_first_of("aeiouy") + 1)).size());
    		if(!token.size())  //No more vowels, just spit everything to newline.
    			break;
    		out << token.substr(0, token.size() - 1) << '\n' << token[token.size() - 1];
    	}
    	out << str << std::flush;
    }
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  9. #24
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    Code:
    str.find_first_of("aeiouy")
    that.. looks really cool i must say


    suprised you didnt' account for command line arguments.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  10. #25
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Yeah, didn't read the instructions.. classic mistake
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  11. #26
    Banned
    Join Date
    Jun 2005
    Posts
    594
    Well thanks everyone who competed, i will be posting the winners
    for contest #2 and contest #3, soon as possible.

    As for contest #1, i will be posting the highest scoring source
    code in my opinion for a vote in the c++ boards.

    Thanks once again and this contest is offically closed.

  12. #27
    Registered User
    Join Date
    Jun 2005
    Posts
    1
    Man, I thought my code was short, but thats pretty impressive.
    Heres what I did if anyone is interested:
    Code:
    #include <vector>
    #include <iostream>
    #include <string>
    #include <fstream>
    using namespace std;
    void makeVector(string line, vector <string> &Adjust); 
    int main(void){
        vector <string> Storage; 
        string infileName,outfileName, fileLine;
        fstream input_file, output_file; 
        cout << "Enter the filename to read in: ";
        cin >> infileName;
        input_file.open(infileName.c_str(),ios::in);           
        cout << endl << "Enter the filename to read out to: ";
        cin.ignore(80,'\n');
        getline(cin, outfileName);
        output_file.open(outfileName.c_str(), ios::out);   
        if(!input_file.fail()){   
            while(getline(input_file, fileLine)){  
                  makeVector(fileLine, Storage);               
            }
        for(int i=0; i<Storage.size(); i++) output_file << Storage[i] << endl;  
        }
        return 0;
    }
    void makeVector(string line, vector <string> &Adjust){
         string vowels = "aeiouyAEIOUY", tempLine = line; 
         for(int i=0; i<line.length(); i++){              
              for(int j=0; j<vowels.length(); j++){      
                   if(line[i] == vowels[j]){              
                        int line_diff = line.length()-tempLine.length(); 
                        Adjust.push_back(line.substr(line_diff,i-line_diff)); 
                        tempLine = line.substr(i,line.length());  
                   }
              }
         }
         Adjust.push_back(tempLine); 
    }

  13. #28
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Crap. Forgot to account for uppercase vowels too If it's not too late, add AEIOUY to the end of my find_first_of string and it should work OK.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  14. #29
    Banned
    Join Date
    Jun 2005
    Posts
    594
    Contest winner of #3 =
    Major_Smalls

    with this code
    Code:
    /*
     * register.cpp
     *
     * This program is a submission for a contest on the CBoards.  it takes in an
     * unspecified amount of purchase (consisting of items and prices) and holds
     * them all in memory until the person is done.  they indicate this by
     * leaving the item field blank.  it then writes everything to a file and 
     * prints a running total to that file.
     *
     * This work is licensed under the Creative Commons Attribution License.
     * To view a copy of this license, visit 
     *
     * http://creativecommons.org/licenses/by/2.5/ 
     *
     * or send a letter to 
     *
     * Creative Commons, 
     * 559 Nathan Abbott Way, 
     * Stanford, California 94305, USA.
     * 
     * Major_Small
     */
    
    #include<iostream>	//for condole I/O
    #include<fstream>	//for file I/O
    #include<string>	//for string class
    #include<iomanip>	//for I/O manipulation
    
    struct purchase;		//prototyped for linkage in itself
    
    struct purchase
    {
    	std::string item;	//holds item name
    	float price;		//holes price
    	purchase*link;		//links to next purchase
    };	
    
    int main()
    {
    	purchase*head=new purchase;	//create a link to start off with
    	purchase*curr=head;		//make it the head of the list
    	purchase*next=head;		//create and initialize next pointer
    	curr->link=0;			//nullify the pointer
    	float total=0;			//holds running total
    	
    	for(;;)				//semi-inifinite loop
    	{
    		std::cout<<"Enter the Item (enter nothing to exit): ";	//prompt for item
    		std::getline(std::cin,curr->item,'\n');			//take in item name
    			if(curr->item=="")				//make sure it's something
    				break;					//if not end program
    		std::cout<<"Enter the Price: $";			//prompt for price
    		std::cin>>curr->price;					//take in price
    		std::cin.ignore(1);					//ignore '\n'
    		next=new purchase;					//create a new node
    		curr->link=next;					//linkify it
    		curr=next;						//move into it
    		curr->link=0;						//nullify the link
    	}
    
    	curr=head;								//start from the top of the list
    	std::fstream file("register.dat",std::ios::out|std::ios::trunc);	//open the file for output and erase
    	file<<"Your Purchases:\n--------------------------\n";			//output header
    	file<<std::fixed<<std::setprecision(2);					//set formatting for floats
    	while(curr->item!="")						//while there's an item
    	{								//below: outut formatted data (item and price)
    		file<<std::left<<' '<<curr->item<<':'<<std::right<<std::setw(24-curr->item.length())<<curr->price<<std::endl;
    		total+=curr->price;					//add the price to the running total
    		curr=curr->link;					//move down the list
    		head->link=0;						//nullify the link in the previous (just exited) node
    		delete head;						//remove the previous node
    		head=curr;						//mark the current node as the previous
    			
    	}
    	head->link=0;			//nullify the link
    	delete curr;			//delete the last node
    	file<<"--------------------------\nTOTAL:"<<std::right<<std::setw(20)<<total<<std::endl;	//output footer
    	file.close();			//close the file
    
    	std::cout<<"Thank You.\n";	//be nice
    	return 0;			//do it.
    }
    Contest # 2 winner is : Major_Smalls is once again the winner;
    However id like to point out that GoGators code was just as good,
    by Major_Smalls wins for keeping count of the changed characters.

    Code:
    /*
     * alpha.cpp
     *
     * This probram is for submission a contest on CBoard.  it is designed to
     * take input from the user and change each letter to it's corresponding
     * letter in the american alphabet.
     *
     * This work is licensed under the Creative Commons Attribution License.
     * To view a copy of this license, visit
     *
     * http://creativecommons.org/licenses/by/2.5/
     * 
     * or send a letter to
     *
     * Creative Commons,
     * 559 Nathan Abbott Way,
     * Stanford, California 94305, USA.
     * 
     * Major_Small
     */
    
    #include<iostream>	//for console I/O
    #include<fstream>	//for file I/O
    
    void usage();			//prints usage
    void foo(std::istream&in);	//main workings
    
    int main(int argc, char*argv[])	//for command-line args
    {
    	if(argc>2)		//if there's more than one argument
    	{
    		usage();	//print usage guidelines
    	}
    	else if(argc==1)	//if no arguments are passed
    	{
    	std::cout<<"Enter some text (write '~' and press enter) to exit"<<std::endl;
    		foo(std::cin);	//pass console input stream to foo
    	}
    	else			//if file is provided
    	{
    		std::ifstream file(argv[1],std::ios::in);	//open file
    		if(!file)		//if file is invalid
    		{
    			usage();	//pring usage
    			exit(1);	//exit with status 1
    		}
    		foo(file);		//else send file input stream to foo
    		file.close();		//when foo is done close the file
    	}	
    
    	return 0;		//return 0 status to OS
    }
    
    void usage()
    {
    	std::cout<<"USAGE:\n\talpha\n\talpha [filename]\n";	//print usage...
    }
    
    void foo(std::istream&in)
    {
    	char ch;	//hold the characters
    	short int num;	//hold the integers
    	int count=0;	//how many were changed
    
    	std::fstream file("alpha.out",std::ios::out|std::ios::trunc);
    	while(in.get(ch))	//while there's a character to be had
    	{
    		if(ch=='~')	//if it's the deadly term char
    		{
    			break;	//get out of the loop
    		}
    		else if(isalpha(ch))	//if it's in the alphabet
    		{	
    			count++;	//increase count
    			ch=toupper(ch);	//change it to uppercase
    			num=static_cast<short int>(ch)-64;	//use ASCII math
    			file<<num<<' ';	//output the number and a space
    		}
    		else	//if it's not part of the alphabet
    		{
    			file<<ch;	//just throw it into the file
    		}
    	}
    	file<<"\n\n"<<count<<" letters were changed.\n";
    	file.close();		//close the file
    }
    Thanks to all that participated, id also like to say taht though
    Hunter2 code was very compact, and did most of the requirements
    However, it did not meet all the need of the contest.

    To find out winner of contest #1 look in the c++ boards.

  15. #30
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787


    I just made sure my code did what the contest wanted, and that it was commented like the rules said... and that was it... I didn't pay too much attention to compacting my code... readability > shortness anyway :P
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginners Contest #2 For those who wanted more!!
    By ILoveVectors in forum Contests Board
    Replies: 16
    Last Post: 08-12-2005, 12:03 AM
  2. Expression Evaluator Contest
    By Stack Overflow in forum Contests Board
    Replies: 20
    Last Post: 03-29-2005, 10:34 AM
  3. WANTED: Contest Master
    By kermi3 in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-23-2003, 10:15 PM