Question:
CAN ANYONE HELP ME PLEASE? PROGRAMMING IN CPP?
armando
2014-03-15 06:30:00 UTC
I have a program writing in c++ but I want to link the program to run it, In know how to do it in Ubuntu using the following command g++ newfilename file.cpp testfile.cpp ./newfilename. I want to run it in windows but its not working.
please help!!!!

#include
using namespace std;

class Rectangle
{
public:
Rectangle(float= 1, float= 1);
void setWidth(float W);
float getWidth();
void setLength(float Le);
float getLength();
void perimeter();
void area();
private:
float length, width;
};

#include
#include "rectangle.h"

using namespace std;
Rectangle Rectangle (float x, float y)
{
lenght = x;
width = y;
}
void setWidth(float W){
if(W<0.0)
{
width = 0.0;
}
else if(W>20.0){
width = 20.0;
}
else{
width = W;
}
}
float getWidth(){

return width;
}
void setLength(float Le)
{
if(Le<0.0)
{
length=0.0;
}
else if(Le>20.0){
length=20.0;
}
else{
length=Le;
}
}

float getLength()
{
return length;
}

void perimeter(){
float b;
b = 2 * getLength + 2 * getWidth;
}

void area(){
float a;
a = getLength * getWidth;
}

#include
#include "rectangle.h"
using namespace std;

int main()
{
Rectangle myRectangle(5.0, 2.0);
cout<<"the perimeter is:"< cout<<"the area is:"<
return 0;
}
Three answers:
?
2014-03-15 07:08:12 UTC
Which compiler are you using?



If you are using an old one, you may have to do following changes in the code.

1.change iostream to iostream.h

2.remove "using namespace std"

3. add paranthesis(brackets) to rectangle.h

4. remove " return 0"
?
2014-03-15 17:05:22 UTC
Windows does not ship with any compiler installed.



You will need to get one.

If you've never used Windows, you probably learn to dislike it rather quickly.



You should get Microsoft's Visual Studio. It's one of the best IDE's out there; it handles all this stuff for you.

If you want to suffer through using the command line on Windows, get CYGWIN and install g++ through that, or download & install mingw, which is a G++ port.



You may also consider getting MSYS.



If this is not your problem (i.e., you're using g++)

try

1: CD to your source directory

2: set %PATH% to the 'bin' folder of your minGW (e.g., set %PATH% C:/mingw/bin/)

3: gcc.exe -o output.exe --language=c++ --std=c++11 [Source file names, space-separated] && output.exe
Kit
2014-03-15 15:51:33 UTC
I'm not sure I'm following, if you want to compile it on Windows using g++, use Cygwin or mingw, otherwise if you're using Visual Studio then there shouldn't be anything to set up, as long as your files are added in the solution file, it should be fine. If you want to link to a library though you'd have to set that up in the options or use pragma comment.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...