-
July 29th, 2009, 07:33 PM
#1
a project for beginner
Is there a project for beginners that could take a little bit of time that would teach them alot about coding? Maybe give some ideas so i know what i can do and plan it out. Right now i have learned:
cin
cout
if
case
switch
system
variables
strings/chars
fstream
while loops
messageboxes
error fixes
putting it together
some other things i cant remember.
If you have anything i can learn to do that would be greatly appreciated.
-
July 29th, 2009, 11:38 PM
#2
Re: a project for beginner
Look for programming contest question.
Thanks for your help.
-
July 29th, 2009, 11:49 PM
#3
Re: a project for beginner
eh im not good enough for contests besides, the contests require alot more knowledge than i have. that is why i need someone to give me an idea for something to make with the little that i know.
-
July 30th, 2009, 02:58 AM
#4
Re: a project for beginner
Do you know how to use std::vector and std::string? How open a notepad, create a text file with some numbers in it and then save it.
Code:
13
24
5
4
674
23
456
Now write a program to read in these numbers and reverse the order of them. Output the result to screen. You may want to use:
www.cppreference.com/wiki
for reference material.
Last edited by PredicateNormative; July 30th, 2009 at 03:00 AM.
-
July 30th, 2009, 07:05 AM
#5
Re: a project for beginner
I hate cppreference. They tell you about the function, but not where to find it. I can't tell you how many times I needed a function, googled it, found how to use it on cppreference, then spent another half an hour searching online to figure out what header file to include. I recommend buying a good C++ book instead.
-
July 30th, 2009, 07:47 AM
#6
Re: a project for beginner
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
-
July 30th, 2009, 08:18 AM
#7
Re: a project for beginner
Originally Posted by ninja9578
I hate cppreference. They tell you about the function, but not where to find it. I can't tell you how many times I needed a function, googled it, found how to use it on cppreference, then spent another half an hour searching online to figure out what header file to include. I recommend buying a good C++ book instead.
They tell you exactly where to find it. For example, here is the list of standard C++ algorithms.
http://www.cppreference.com/wiki/stl/algorithm/start
If you click on, say accumulate, you will end up on this page
http://www.cppreference.com/wiki/stl...thm/accumulate
In the syntax box you will see
Code:
#include <numeric>
TYPE accumulate( iterator start, iterator end, TYPE val );
TYPE accumulate( iterator start, iterator end, TYPE val, BinaryFunction f );
which not only shows you the interface, but also that accumulate is in the numeric include.
For containers, e.g. list:
http://www.cppreference.com/wiki/stl/list/start
click on the Constructors link:
http://www.cppreference.com/wiki/stl...t_constructors
and it then look in the syntax box, and you will see that it shows you where to find list:
Code:
#include <list>
list();
list( const list& c );
list( size_type num, const TYPE& val = TYPE() );
list( input_iterator start, input_iterator end );
~list();
I must admit, I have never had the problem that you are describing.
-
July 30th, 2009, 02:47 PM
#8
Re: a project for beginner
Don't know std::vector but i do know std::string. i can make a file save it and open it i just would have to think about how to make it do it in reverse order. It would probably be something like
Code:
#include <iostream>
#include <fstream>
using namespace std;
int num1;
int num2;
int num3;
int num4;
int num5;
ofstream file("file.txt");
int main()
{
cout << "Please intput 5 numbers with either a space or a new line between each" << endl;
cin >> num1;
cin >> num2;
cin >> num3;
cin >> num4;
cin >> num5;
file << num1;
file << num2;
file << num3;
file << num4;
file << num5;
system("pause");
system("cls");
cout << "Your numbers backwords were:" << endl;
ifstream file("file.txt");
cout << num5 << endl;
cout << num4 << endl;
cout << num3 << endl;
cout << num2 << endl;
cout << num1 << endl;
file.close();
system("pause");
return 0;
}
-
July 31st, 2009, 03:05 AM
#9
Re: a project for beginner
The std::vector is a wonderful container, you can for example, declare it with a particular size:
Code:
//#include <vector>
std::vector<T> vec(size);
where T represents the type you want to vector to hold, and size is the size you want the vector to be, e.g. the following:
Code:
std::vector<int> intvec(100);
declares a vector called intvec that holds 100 elements of type int. You can now access those 100 elements just like a standard array if you like:
Code:
for(int i(0); i<100; i++)
{
intvec[i] = i;
}
The above loop doesn't test how big the vector is, so if I made the vector 1 element bigger by pushing a value onto the back (end) of the array
Code:
intvec.push_back(0); //The vector now holds 101 elements
and then ran the loop, the loop would still only assign 100 elements. You can create a loop that assigns the number of elements in the vector by checking its size:
Code:
for(int i(0); i<intvec.size(); i++)
{
intvec[i] = i;
}
If you compile the above loop you will most likely get a compiler warning for the part highlighted in red, and the warning will be telling you that there is a type mismatch in that vector<T>::size() returns a size_t type (not necessarily true, but has been on all implementations that I have tried), and you are comparing this against an int (the variable i), therefore there is a possible loss of data if the loop is looping over a very large number of elements. Since that isn't going to be a problem for reading a handful of elements from a file, you can tell the compiler that you know about the problem and are ok with it, by adding in a static cast.
Code:
for(int i(0); i<static_cast<std::vector<int>::size_type>(intvec.size()); i++)
{
intvec[i] = i;
}
Anyway, back to the std::vector. You can create one without any elements and then use push_back to insert elements at the end of the vector.
You should never attempt to access a vector location that is greated than size()-1, as the element will not exist and it attempting to make the access will yeild undefined behaviour.
The nice thing about std::vector is that you do not need to worry about memory allocation - it handles that for you. Now, to read the integers from a file (in the format described in the first of my posts in this thread) using vector you could do:
Code:
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm> //for std::copy
#include <iterator> //for std::ostream_iterator
int main()
{
//open a file called "file.txt" that contains integers
std::ifstream infile("file.txt");
std::vector<int> vec;
int tmp(0);
//Read the contents into the vector
while(infile>>tmp)
{
vec.push_back(tmp);
}
//Print the contents of the vector
std::copy(vec.begin(), vec.end(), std::ostream_iterator<int>(std::cout, "\n"));
}
Now all you need to do is figure out how to re-order the elements.
-
July 31st, 2009, 06:02 AM
#10
Re: a project for beginner
Originally Posted by PredicateNormative
If you compile the above loop you will most likely get a compiler warning for the part highlighted in red, and the warning will be telling you that there is a type mismatch in that vector<T>::size() returns a size_t type (not necessarily true, but has been on all implementations that I have tried)
What is guaranteed is that std::vector<int>::size_type is an unsigned integer type but int is a signed integer type.
Originally Posted by PredicateNormative
you can tell the compiler that you know about the problem and are ok with it, by adding in a static cast.
Yes, except that the code example demonstrates casting from std::vector<int>::size_type back to std::vector<int>::size_type. Your intention would be to cast to int:
Code:
for (int i(0); i < static_cast<int>(intvec.size()); ++i)
{
intvec[i] = i;
}
-
July 31st, 2009, 06:46 AM
#11
Re: a project for beginner
Originally Posted by laserlight
What is guaranteed is that std::vector<int>::size_type is an unsigned integer type but int is a signed integer type.
That's good to know.
Originally Posted by laserlight
Yes, except that the code example demonstrates casting from std::vector<int>::size_type back to std::vector<int>::size_type. Your intention would be to cast to int:
Code:
for (int i(0); i < static_cast<int>(intvec.size()); ++i)
{
intvec[i] = i;
}
Whoops
-
July 31st, 2009, 01:28 PM
#12
Re: a project for beginner
maybe a different example of a project i can do because i just got confused ><
-
July 31st, 2009, 03:56 PM
#13
Re: a project for beginner
Text based hangman,
Text based poker,
In the mid to late 70's there was a common set of games like lunar lander, trek and slots.
Dice oriented games.
Of course, really simple (almost nonsense) tests of looping from 0 to something to see how fast the computer could count. In the 70's we were using BASIC, so 500 integer increments per second was about the fastest we'd see.
In assembler we might get 50 to 100 thousand per second.
If my post was interesting or helpful, perhaps you would consider clicking the 'rate this post' to let me know (middle icon of the group in the upper right of the post).
-
July 31st, 2009, 04:01 PM
#14
Re: a project for beginner
Originally Posted by JVene
Of course, really simple (almost nonsense) tests of looping from 0 to something to see how fast the computer could count. In the 70's we were using BASIC, so 500 integer increments per second was about the fastest we'd see.
In assembler we might get 50 to 100 thousand per second.
I have already done that it is on the ragezone website. I am actually looking for something that has a purpose. Games are pretty useless when text based.
-
July 31st, 2009, 04:23 PM
#15
Re: a project for beginner
Ok, how far into the ambitious side of things do you want to go?
3D animation? Space simulation? Something that requires some awareness of linear algebra (you don't really have to be a mathematician, but you have to be aware of it).
Some GUI application - graphics oriented board games, drawing programs....what's your interest?
If my post was interesting or helpful, perhaps you would consider clicking the 'rate this post' to let me know (middle icon of the group in the upper right of the post).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|