-
[C++] A project for beginners
C++
No GUI
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.
-
re: [C++] A project for beginners
Are you talking about php? Tell us what kind of coding you are planning on doing.
-
re: [C++] A project for beginners
Indeed, is it a c kind of language, java, php.
BEcuase most of the functions are doable in more languages.
But looking at cin and cout i'm thinking of a c based language?
-
re: [C++] A project for beginners
Its a c based language considering the cin and couts.
-
re: [C++] A project for beginners
-
re: [C++] A project for beginners
Use different methods to learn different things more in-depth. ex, make a calculator to practice math operations, learn different ways to type code to get the same result, etc.
-
re: [C++] A project for beginners
im actually hoping people could give me ideas for something specific that takes a little time. Like i already made a game out of what i know so something a little harder but not that much harder to that i can learn a little more.
-
Re: a project for beginner
Make them do a basic GUI calculator, or a GUI tic-tac-toe game.
Better yet, let them do Snake and Ladders.
-
Re: [C++] A project for beginners
hmm i guess i forgot to put in my first post that i don't want to do GUI.
-
Re: [C++] A project for beginners
Here is a small simple calculator I posted on GzP.
Has; Addition, subtraction, multiplication, and division with remainder.
Code:
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
string myStrng;
string multiply;
string divide;
string subtract;
string addition;
int number1;
int number2;
unsigned int number3;
unsigned int number4;
int answer;
loop1:
cout << "Type 'Help' for a list of commands: ";
getline(cin, myStrng);
{
if(myStrng == "multiply" || myStrng == "Multiply")
{
cout << "Enter number1: ";
cin >> number1;
cout << "\nEnter number2: ";
cin >> number2;
answer = number1 * number2;
cout << "\n\nThe answer is " << answer << "!";
Sleep(4000);
}
else if(myStrng == "divide" || myStrng == "Divide")
{
cout << "Enter number1: ";
cin >> number1;
cout << "\nEnter number2: ";
cin >> number2;
answer = number1 / number2;
cout << "\n\nThe answer is " << answer << " with a remainder of " << number1 % number2 << "!";
Sleep(4000);
}
else if (myStrng == "subtract" || myStrng == "Subtract")
{
cout << "Enter number1: ";
cin >> number3;
cout << "\nEnter number2: ";
cin >> number4;
answer = number3 - number4;
cout << "\n\nThe answer is " << answer << "!";
Sleep(4000);
}
else if (myStrng == "addition" || myStrng == "Addition")
{
cout << "Enter number1: ";
cin >> number1;
cout << "\nEnter number2: ";
cin >> number2;
answer = number1 + number2;
cout << "\n\nThe answer is " << answer << "!";
Sleep(4000);
}
else if (myStrng == "Help" || myStrng == "help")
{
cout << "\n\nType 'Addition' or 'addition' for adding.\n";
cout << "Type 'Subract' or 'subtract' for subtracting.\n";
cout << "Type 'Divide' or 'divide' for division.\n";
cout << "Type 'Multiply' or 'multiply' for multiplication.\n\n";
Sleep(5000);
goto loop1;
}
else
{
cout << "You did not enter a valid choice! ";
Sleep(3500);
cout << "\n\n";
goto loop1;
return 0;
}
}
}
-
Re: [C++] A project for beginners
Quote:
Originally Posted by
Tman151
Here is a small simple calculator I posted on GzP.
Has; Addition, subtraction, multiplication, and division with remainder.
Code:
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
string myStrng;
string multiply;
string divide;
string subtract;
string addition;
int number1;
int number2;
unsigned int number3;
unsigned int number4;
int answer;
loop1:
cout << "Type 'Help' for a list of commands: ";
getline(cin, myStrng);
{
if(myStrng == "multiply" || myStrng == "Multiply")
{
cout << "Enter number1: ";
cin >> number1;
cout << "\nEnter number2: ";
cin >> number2;
answer = number1 * number2;
cout << "\n\nThe answer is " << answer << "!";
Sleep(4000);
}
else if(myStrng == "divide" || myStrng == "Divide")
{
cout << "Enter number1: ";
cin >> number1;
cout << "\nEnter number2: ";
cin >> number2;
answer = number1 / number2;
cout << "\n\nThe answer is " << answer << " with a remainder of " << number1 % number2 << "!";
Sleep(4000);
}
else if (myStrng == "subtract" || myStrng == "Subtract")
{
cout << "Enter number1: ";
cin >> number3;
cout << "\nEnter number2: ";
cin >> number4;
answer = number3 - number4;
cout << "\n\nThe answer is " << answer << "!";
Sleep(4000);
}
else if (myStrng == "addition" || myStrng == "Addition")
{
cout << "Enter number1: ";
cin >> number1;
cout << "\nEnter number2: ";
cin >> number2;
answer = number1 + number2;
cout << "\n\nThe answer is " << answer << "!";
Sleep(4000);
}
else if (myStrng == "Help" || myStrng == "help")
{
cout << "\n\nType 'Addition' or 'addition' for adding.\n";
cout << "Type 'Subract' or 'subtract' for subtracting.\n";
cout << "Type 'Divide' or 'divide' for division.\n";
cout << "Type 'Multiply' or 'multiply' for multiplication.\n\n";
Sleep(5000);
goto loop1;
}
else
{
cout << "You did not enter a valid choice! ";
Sleep(3500);
cout << "\n\n";
goto loop1;
return 0;
}
}
}
wow hmm, wow! there are alot of things you did wrong that shouldn't be used. for instance instead of using goto loops try using while commands to get you back to the beginning. Secondly you might want to try using switches and cases they save alot of time versus else if's. let me try to revise the code for you.
try
Code:
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int num1;
int num2;
int op;
cout << "Please type two numbers you wish to add, subtract, multiply, or divide:\n";
cin >> num1;
cin >> num2;
system("pause");
cout << "Please type the operation you wish to use:\n1 addition\n2 subtraction\n3 multiplication\n4 division:";
cin >> op;
switch(op)
{
case 1: // addition
{
cout << num1 << " + " << num2 << " = " << endl;
cout << num1 + num2<< endl;
system("pause");
}
break;
case 2: // subtraction
{
cout << num1 << " - " << num2 << " = " << endl;
cout << num1 - num2<< endl;
system("pause");
}
break;
case 3: // multiplication
{
cout << num1 << " * " << num2 << " = " << endl;
cout << num1 * num2<< endl;
system("pause");
}
break;
case 4: // division
{
if(num2 > 0 || num2 < 0)
{
cout << num1 << " / " << num2 << " = " << endl;
cout << num1 / num2 << endl;
system("pause");
}
else
{
cout << "The second number must be either greater than or less than 0 for this operation\n";
system("pause");
}
}
break;
default:
{
cout << "You did not enter a proper number\n";
system("pause");
}
}
}
i was able to save about 22 lines from your code by using the code i wrote.
-
Re: [C++] A project for beginners
1) I use goto for small projects that I couldn't really care less about.
2) I very rarely do switch statements.
If I am working on a project for the server I work for, I will keep care of my code.
I only wrote this so I could do a daily project.
Quote:
Originally Posted by ShortyManT
Edit: Here is a calculator I wiped up. Yea, I used the goto function, and ignored using switch statements. O' well.
-
Re: [C++] A project for beginners
Switch statements are faster (instead of many else-if statements) and goto statements spaghettisize your code ;-)
-
Re: [C++] A project for beginners
So does anyone have any other ideas of something i can do? please
-
Re: [C++] A project for beginners
Here's something: you give the program a website address, and it will output all the URL's (or whatever other type of easily recognizable strings) on it.
Areas of practice: network connection basics, some more memory management and string parsing. Should take a little while, too.
-
Re: [C++] A project for beginners
hmm, and that is something i could learn in a couple days? xP
I don't mean that to sound impatient but i want to lean things at maybe 1-2 items at a time not 4-5 unless they are all simple things because i am still learning.
-
Re: [C++] A project for beginners
The networking part probably requires a pretty specific tut and would have you copy & paste too much for much benefit. Let's skip that thought for now.
Let's study data structures a bit!
* The program asks for an integer n and then builds a tree structure so that n times a child node is added to any of the previously added nodes (randomly chosen where), the program begins with one ready root node.
* Asks for two integers, these are two ID's for nodes in the tree, and will search the tree to find out how closely they are related (ie. how many levels up the tree you have to go to find the first common parent node).
For this "homework assignment" I recommend at least: struct for each node, new keyword for dynamically creating those new items, pointers to parent & children from each node, some data structure to store pointers to every node so that you can find them by indexing (vector, set..).
-
Re: [C++] A project for beginners
so what exactly do you want me to do?
-
Re: [C++] A project for beginners
Do you mean you didn't understand my program description? Which part? It's not a very visual or interactive program, but introduces some very essential concepts.
-
Re: [C++] A project for beginners
i mostly didn't understand any of it. :P
-
Re: [C++] A project for beginners
Ok, let's make it a little more "practical"...
The program keeps record of a family tree. It recognizes two commands:
A <personA> <personB> : Adds personA as personB's child
O <person> : Outputs the names of person's parent and all children
In order to make it a legit tree structure, every new child must have a parent, except at startup there is only 1 person named alex, who has no parent. Obviously, the first child then must have alex as their parent. The next can have either alex or the one first created. There must be no limit to how many persons can be added, or how many children a person can have.
Plus points for implementing extra commands for saving and restoring a family tree!
For this program, making a child only takes one parent, but don't let it bother you. :)
-
Re: [C++] A project for beginners
Quote:
Originally Posted by
Negata
For this program, making a child only takes one parent, but don't let it bother you. :)
wow that makes me feel kinda bad.
anyways, what areas of coding would i need to learn?
-
Re: [C++] A project for beginners
It's essentially the same program as my previous suggestion, so look up from there.
-
Re: [C++] A project for beginners
Basically he's saying practice the concept of linkedlists :) so you may want to take a look at that