Graalians

Graalians (https://www.graalians.com/forums/index.php)
-   Technology (https://www.graalians.com/forums/forumdisplay.php?f=54)
-   -   Coding in C++ (https://www.graalians.com/forums/showthread.php?t=26365)

Motrox 11-11-2014 11:20 PM

Coding in C++
 
Not really sure if this is the place to put this or if anyone here knows c++ but..
I've been trying to learn it recently in hopes of becoming fluent one day as my first computer language.
Here's an unoriginal calculator I made.

PHP Code:

// By Mustafa 
#include <iostream>
using namespace std;

float addition (float number1,float number2)
{
 return 
number1 number2;
}

float subtraction (float number1,float number2)
{
 return 
number1 number2;
}

int main(){
    
        
float number1number2;
        
int choice;
       
cout << " Choice your operation. Addition for 1 and Subtraction for 2.";
       
cout << " Choice: ";
       
cin >> choice;
       if (
choice==1) {
           
           
// Addition
      
cout << "\n Add the first number of your choice  ";
      
cin >> number1;
      
cout << "\n Add the second number of your choice  ";
      
cin >> number2;
      
cout << "\n The answer to the addtion problem is  " << number1 number2;
 
       }
       else {
           
           
       } if (
choice==2)
       {
           
// Subtraction
    
cout << "\n Add the first number of your choice  ";
    
cin >> number1;
    
cout << "\n Add the second number of your choice  ";
    
cin >> number2;
    
cout << "\n The answer to the subtraction problem is  " << number1 number2;
       }
     
system ("Pause");
    
}





Ghettoicedtea 11-12-2014 04:08 PM

Im pretty sure GS2 is based off of java c++ so you might have some help here

Fysez 11-12-2014 04:53 PM

Quote:

Posted by Motrox (Post 516374)
Not really sure if this is the place to put this or if anyone here knows c++ but..
I've been trying to learn it recently in hopes of becoming fluent one day as my first computer language.
Here's an unoriginal calculator I made.

PHP Code:

// By Mustafa 
#include <iostream>
using namespace std;

float addition (float number1,float number2)
{
 return 
number1 number2;
}

float subtraction (float number1,float number2)
{
 return 
number1 number2;
}

int main(){
    
        
float number1number2;
        
int choice;
       
cout << " Choice your operation. Addition for 1 and Subtraction for 2.";
       
cout << " Choice: ";
       
cin >> choice;
       if (
choice==1) {
           
           
// Addition
      
cout << "\n Add the first number of your choice  ";
      
cin >> number1;
      
cout << "\n Add the second number of your choice  ";
      
cin >> number2;
      
cout << "\n The answer to the addtion problem is  " << number1 number2;
 
       }
       else {
           
           
       } if (
choice==2)
       {
           
// Subtraction
    
cout << "\n Add the first number of your choice  ";
    
cin >> number1;
    
cout << "\n Add the second number of your choice  ";
    
cin >> number2;
    
cout << "\n The answer to the subtraction problem is  " << number1 number2;
       }
     
system ("Pause");
    
}





Great learning experience.
We did this assignment in my first year Computer Programming class in HighSchool. Next, we edited the calculator code to work with strings (using delimiters in Java, substrs in C++).

I'd give you the reference assignment, and code (if needed) but unfortunately, everything is on my class desktops and I won't have access to them or the syllabus until tomorrow.

Glad you're learning, we need more programmers in the world.

Downsider 11-12-2014 05:16 PM

amazing thumb up

hosler 11-12-2014 06:07 PM

I like how you made some functions but didn't use them

Fysez 11-12-2014 06:55 PM

Quote:

Posted by hosler (Post 516480)
I like how you made some functions but didn't use them

Haha, good eye. I didn't even notice that

Hugop 11-12-2014 07:41 PM

Quote:

Posted by hosler (Post 516480)
I like how you made some functions but didn't use them

lol

Tricxta 11-12-2014 07:54 PM

Next step, start parsing strings. Also notice how your code is duplicated for both choice inputs? You should avoid that since as the product grows, future code maintenance efforts become harder as a result. For example, what if you want to change your input source.

Please continue posting your code, it's good to see someone making an effort.

Motrox 11-13-2014 01:05 AM

Quote:

Posted by hosler (Post 516480)
I like how you made some functions but didn't use them

I took them out and the program still worked!
I thought you had to add the functions on top of the main for some reason.


Quote:

Posted by Fysez (Post 516471)
Great learning experience.
We did this assignment in my first year Computer Programming class in HighSchool. Next, we edited the calculator code to work with strings (using delimiters in Java, substrs in C++).

I'd give you the reference assignment, and code (if needed) but unfortunately, everything is on my class desktops and I won't have access to them or the syllabus until tomorrow.

Glad you're learning, we need more programmers in the world.

I regret not taking programming courses earlier in high school..
If you could send me the reference that would be great.

Quote:

Posted by Tricxta (Post 516492)
Next step, start parsing strings. Also notice how your code is duplicated for both choice inputs? You should avoid that since as the product grows, future code maintenance efforts become harder as a result. For example, what if you want to change your input source.

Please continue posting your code, it's good to see someone making an effort.

Thanks for the tips. What's parsing strings?
I'll try and keep this updated frequently :)

Tricxta 11-13-2014 08:16 AM

Quote:

Posted by Motrox (Post 516535)
Thanks for the tips. What's parsing strings?
I'll try and keep this updated frequently :)

I suppose parsing strings was super vague, what I meant is your calculator should take as input a single string and process it.
For example parsing "1 + 4 - 2". While this can become arguably complicated it can start off quite basic and grow to a great degree depending on the complexity you'd like to achieve, for example implementing brackets.

Also I'll give you a hint, using a stack based implementation will probably be the best way to go with this problem. Familiarise yourself with queues, stacks, and other common data structures and have a think about that.

Motrox 11-24-2014 04:39 AM

Quote:

Posted by Tricxta (Post 516559)
I suppose parsing strings was super vague, what I meant is your calculator should take as input a single string and process it.
For example parsing "1 + 4 - 2". While this can become arguably complicated it can start off quite basic and grow to a great degree depending on the complexity you'd like to achieve, for example implementing brackets.

Also I'll give you a hint, using a stack based implementation will probably be the best way to go with this problem. Familiarise yourself with queues, stacks, and other common data structures and have a think about that.

I watched a couple tutorials today on parsing strings and strings in general today! Also I finished the calculator works nicely.

I felt a bit mischievous today aha.
So I made file remover. Using the stealth function to hide the window once executed.
It basically just deletes anything I specify before I compile it once the person opens it up.
Nothing really useful except to mess with people lol.
I'll try to get a mod to rename my thread as well..

PHP Code:

//// By Mustafa

  #include <stdio.h>
  #include <iostream>
  #include<windows.h>

  
using namespace std;

  
void Stealth(); // Declaration of Stealth.

int main ()
{
    
Stealth(); // Stealth Call.
  
if( remove"C:/Users/Owner/Desktop/2.txt" ) != )
    
perror"Failure" );
  else
    
puts"The file has been removed." );
  
cin.get();
  return 
0;
}

void Stealth()
{
  
HWND Stealth;
  
AllocConsole();
  
Stealth FindWindowA("ConsoleWindowClass"NULL);
  
ShowWindow(Stealth,0);



OneUseAccount 11-24-2014 09:10 AM

Quote:

Posted by Tricxta (Post 516559)
I suppose parsing strings was super vague, what I meant is your calculator should take as input a single string and process it.
For example parsing "1 + 4 - 2". While this can become arguably complicated it can start off quite basic and grow to a great degree depending on the complexity you'd like to achieve, for example implementing brackets.

Also I'll give you a hint, using a stack based implementation will probably be the best way to go with this problem. Familiarise yourself with queues, stacks, and other common data structures and have a think about that.

We did this in university class in python, stack and queues are really simple to create yourself.

Tricxta 11-24-2014 11:04 AM

Quote:

Posted by Motrox (Post 519750)
I watched a couple tutorials today on parsing strings and strings in general today! Also I finished the calculator works nicely.

I felt a bit mischievous today aha.
So I made file remover. Using the stealth function to hide the window once executed.
It basically just deletes anything I specify before I compile it once the person opens it up.
Nothing really useful except to mess with people lol.
I'll try to get a mod to rename my thread as well..

PHP Code:

void Stealth()
{
HWND Stealth;
AllocConsole();
Stealth FindWindowA("ConsoleWindowClass"NULL);
ShowWindow(Stealth,0);



Coder level = ub3r l33t h@k3r

Jatz 11-24-2014 11:05 AM

Quote:

Posted by OneUseAccount (Post 519791)
We did this in university class in python, stack and queues are really simple to create yourself.

There's a difference between a python stack, and an efficient, memory leak free c++ one.

hosler 11-24-2014 04:45 PM

Are you saying the prebuilt python stacks are flawed?


All times are GMT. The time now is 04:28 PM.

Powered by vBulletin/Copyright ©2000 - 2026, vBulletin Solutions Inc.