The Official Programming Thread

Shary Bhallu TC

Bhallu is dead, legacy remains
Jun 2, 2009
16,491
692
129
30
Karachi.
This same thing happens in games as well! For example if I am unable to beat a difficult ass Dark Souls 2 boss for hours, then sleep for a few hours, I see that I am able to beat that boss pretty easily. I think our brain does far more than just sleep when we're sleeping. :D
 

MegamanEXE

Well-known member
Dec 7, 2007
1,958
1
43
28
Islamabad
Poori raat beth k banaya, nahi bana.
Subah uth ker 5 minute socha, foran ban gya XD.

Wtf is this sorcery?
Get used to it. This will happen more times than you'll like to admit.

So, if you're stuck for over an hour or 2 using the PC. Leave it, do other stuff, the solution will come as an epiphany! Trust me, happened to me a hundred times. Quoting someone on Quora:
"Programming" is thinking, not typing. Most of programming is spent sleeping, walking around, staring out the window, or doing anything else that helps you relax and think."
 

Shary Bhallu TC

Bhallu is dead, legacy remains
Jun 2, 2009
16,491
692
129
30
Karachi.
Yes my bro said the same thing. One time he was stuck on a problem at his job for 2 days, working 12 hours a day to no avail. He couldn't get his code to work. Then he took a day off from work because he was very tired. After sleeping for almost half of the day, he stumbled upon the solution as soon as he woke up. Called his boss, went to work despite his day off, and his code worked.

Our brains do indeed work while we sleep. Sometimes I've noticed that sleeping for 4-5 hours after studying will help you retain the information you digested just prior to sleeping. I used this technique in the previous hellish semester. It helped me a lot :D!
 

EternalBlizzard

Lazy guy :s
Moderator
Oct 29, 2011
2,732
1,195
129
Attractor Field Beta
Human brain keeps on finding a solution to the problem even while asleep :D That's pretty much a fact now
It keeps on finding a pattern through your problems or so as they say :s A scary thing it is right :D
 
Last edited:

puppet

Well-known member
Sep 30, 2013
2,169
0
42
^^ thats why before coding anything i just make up my mind before designing algo :p
 

Priori

New member
Sep 22, 2014
1
0
1
Hello, I'm looking to learn a new programming language. I have some experience with Android Application Development.

My target is to learn Unity 3D. Can anyone point me to a decent learning resource for beginners or give me any tips etc?
 

puppet

Well-known member
Sep 30, 2013
2,169
0
42
Hello, I'm looking to learn a new programming language. I have some experience with Android Application Development.

My target is to learn Unity 3D. Can anyone point me to a decent learning resource for beginners or give me any tips etc?
c#...... !
 

Benighted

Night is the new day
May 28, 2009
2,476
2
44
31
Tartarus
I've never had those moments of epiphany. I've only ever been able to break down challenging problems by persistent mental effort. And I've only ever done pretty basic programming.
 

Hassan

lethargic procrastinator
Jun 20, 2009
6,520
0
41
3 miles from the nearest bus stop
Can anyone solve this question for me?
Spoiler: show
Create a class called shape using a Header containing only class member functions prototypes (not Definition’s). Store your program in 3 separate files named as Class_Name .h Class definition only function prototypes Class_Name .cpp Class member functions definitions File_Name.cpp Main program for operation
Create a class called shape using a Header containing only class member
functions prototypes (not Definition’s). Store your program in 3 separate files
named as
Class_Name .h  Class definition only function prototypes
Class_Name .cpp  Class member functions definitions
File_Name.cpp  Main program for operation

Your Output should appear as:
Enter your choice (T) for Triangle and (R) for Rectangle and (E) to Exit
T
Enter Value for x 6
Enter Value for y 7
Triangle
Values entered are 6 and 7
Area is 21
Enter your choice (T) for Triangle and (R) for Rectangle and (E) to Exit
R
Enter Value for x 7
Enter Value for y 6
Rectangle
Values entered are 7 and 6
Area is 42
Enter your choice (T) for Triangle and (R) for Rectangle and (E) to Exit
E
Exiting



My poor try with loads of errors
Code:
#include<iostream>
#include<string>
usingnamespacestd;
 
class shape 
{
private:
       inta,b;
public:
       shape()
       {
       a = b = 0;
       }
      
       voidsetvalues()
       {
       cout<<"Enter the values for breath and height:"<<endl;
       cin>> a; cin>> b;
    }
 
       floatarea_r()
       {
       float arear = (a*b);
       return arear;
       }
 
       floatarea_t()
       {
       floatareat = (a*b) / 2;
       returnareat;
       }
 
       voidgetvalues(int x, int y)
       {
       x=a;
       y=b;
       }
 
};
 
voiddisp(int, int, float);
 
int main()
{
       shapevar;
       intm,n;
       stringt,r,e,c;
 
       cout<<"Enter your choice (T) for Triangle and (R) for Rectangle and (E) to Exit:"<<endl;
       getline (cin,c);
      
       do
       {
             
              if (c==t)
              { var.setvalues(); var.area_t(); var.getvalues(m,n); disp(m,n, var.area_t());}
      
 
       elseif (c==r)
              {var.setvalues(); var.area_r(); var.getvalues(m,n); disp(m,n, var.area_r()); }
      
 
       } while (c!=e);
 
       system("PAUSE");
 
return 0;
}
 
voiddisp(inta,int b, float c)
{
       cout<<"The values entered are:"<<endl;
cout<< a << b;
       cout<<"The area is:"<<endl;
       cout<< c;
}
Creating a header file and defining its function in another file is easy. I need help regarding the logic which is to be made.
 

MegamanEXE

Well-known member
Dec 7, 2007
1,958
1
43
28
Islamabad
Can anyone solve this question for me?
Spoiler: show
Create a class called shape using a Header containing only class member functions prototypes (not Definition’s). Store your program in 3 separate files named as Class_Name .h Class definition only function prototypes Class_Name .cpp Class member functions definitions File_Name.cpp Main program for operation
Create a class called shape using a Header containing only class member
functions prototypes (not Definition’s). Store your program in 3 separate files
named as
Class_Name .h  Class definition only function prototypes
Class_Name .cpp  Class member functions definitions
File_Name.cpp  Main program for operation

Your Output should appear as:
Enter your choice (T) for Triangle and (R) for Rectangle and (E) to Exit
T
Enter Value for x 6
Enter Value for y 7
Triangle
Values entered are 6 and 7
Area is 21
Enter your choice (T) for Triangle and (R) for Rectangle and (E) to Exit
R
Enter Value for x 7
Enter Value for y 6
Rectangle
Values entered are 7 and 6
Area is 42
Enter your choice (T) for Triangle and (R) for Rectangle and (E) to Exit
E
Exiting



My poor try with loads of errors
Code:
#include<iostream>
#include<string>
usingnamespacestd;
 
class shape 
{
private:
       inta,b;
public:
       shape()
       {
       a = b = 0;
       }
      
       voidsetvalues()
       {
       cout<<"Enter the values for breath and height:"<<endl;
       cin>> a; cin>> b;
    }
 
       floatarea_r()
       {
       float arear = (a*b);
       return arear;
       }
 
       floatarea_t()
       {
       floatareat = (a*b) / 2;
       returnareat;
       }
 
       voidgetvalues(int x, int y)
       {
       x=a;
       y=b;
       }
 
};
 
voiddisp(int, int, float);
 
int main()
{
       shapevar;
       intm,n;
       stringt,r,e,c;
 
       cout<<"Enter your choice (T) for Triangle and (R) for Rectangle and (E) to Exit:"<<endl;
       getline (cin,c);
      
       do
       {
             
              if (c==t)
              { var.setvalues(); var.area_t(); var.getvalues(m,n); disp(m,n, var.area_t());}
      
 
       elseif (c==r)
              {var.setvalues(); var.area_r(); var.getvalues(m,n); disp(m,n, var.area_r()); }
      
 
       } while (c!=e);
 
       system("PAUSE");
 
return 0;
}
 
voiddisp(inta,int b, float c)
{
       cout<<"The values entered are:"<<endl;
cout<< a << b;
       cout<<"The area is:"<<endl;
       cout<< c;
}
Creating a header file and defining its function in another file is easy. I need help regarding the logic which is to be made.
Firstly, there are issues with your spaces.

As for making multiple files, what you make in the .h files are interfaces, not definitions. If you remove all the definitions, you'll be left with a clean list of functions from which you can guess what a class does. In your case, it'd be something like.

Code:
class shape
{
private:
int a,b;
public:
shape();
float area_r();
float area_t();
void getValues(); //It's better to use a constructor for this

}'
Then you make the defintions in the .CPP file. And you need to use header guards(#ifndef and #def ), especially if you there is more than 1 file. In the .cpp file, you'll define
Code:
shape::shape() {\\stuff}

float shape::area_r(){\\definition}

float shape::area_t(){\\definition}
If your code is working in a single file, cut-pasting the definitions to the .cpp file shouldn't be an issue, make sure to include the .h file at the top. You might have to include iostream and using namespace std again as well depending on the situation.
 
General chit-chat
Help Users
We have disabled traderscore and are working on a fix. There was a bug with the plugin | Click for Discord
  • No one is chatting at the moment.
    NaNoW NaNoW: ....