Keep getting this error message when trying to compile in main1.cpp. Need help figuring out how to make it compile. Thank you for your time.
Error Message:
main.cpp:(.text+0x13): undefined reference to `circle::circle()'
main.cpp:(.text+0x32): undefined reference to `circle::circle(double)'
main.cpp:(.text+0x3e): undefined reference to `circle::getArea() const'
main.cpp:(.text+0x53): undefined reference to `circle::getRadius() const'
main.cpp:(.text+0xb3): undefined reference to `circle::getArea() const'
main.cpp:(.text+0xc8): undefined reference to `circle::getRadius() const'
main.cpp:(.text+0x157): undefined reference to `circle::setRadius(double)'
main.cpp:(.text+0x163): undefined reference to `circle::getArea() const'
main.cpp:(.text+0x178): undefined reference to `circle::getRadius() const'
main.cpp:(.text+0x207): undefined reference to `circle::setRadius(double)'
main.cpp:(.text+0x213): undefined reference to `circle::getArea() const'
main.cpp:(.text+0x228): undefined reference to `circle::getRadius() const'
collect2: error: ld returned 1 exit status
Main1.cpp
#include <iostream>
using namespace std;
#include "circle.h"
int main()
{
circle circle1, circle2;
int radius;
cout<< "Enter Radius for circle 1: ";
cin >> radius;
circle1.setRadius(radius);
cout << "Enter Radius for circle 2: ";
cin>> radius;
circle2.setRadius(radius);
cout<< endl;
cout<< "Radius of Circle 1: " << circle1.getRadius() << endl;
cout<< "Area of Circle 1: " << circle1.calcArea()<< endl;
cout << "Radius of Circle 2: " << circle2.getRadius() << endl;
cout << "Area of Circle 2: " << circle2.calcArea() << endl;
return 0;
}
circle.cpp
#include <iostream>
#include "circle.h"
using namespace std;
const double PI = 3.14159;
circle::circle()
{
radius = 0;
}
circle::circle(int r)
{
if(r < 0)
{
r = 0;
}
radius = r;
}
void circle::setRadius(int r)
{
radius = r;
}
int circle::getRadius()
{
return radius;
}
double circle::calcArea()
{
return PI*radius*radius;
}
circle.h
#ifndef CIRCLE_H
#define CIRCLE_H
class circle
{
private:
int radius;
public:
circle();
circle(int r);
void setRadius(int r);
int getRadius();
double calcArea();
};
#endif
It compiles fine..did you copy whole text along with circle.h like this ?
circle.h
#ifndef CIRCLE_H
#define CIRCLE_H
class circle
{
private:
int radius;
public:
circle();
circle(int r);
void setRadius(int r);
int getRadius();
double calcArea();
};
#endif
Then comment out the first line circle.h like this //circle.h
similarly if you have copied whole text for circle.cpp ,, then comment out circle.cpp at the beginning . Then it should be fine.
//I executed your program and got output as below
Enter Radius for circle 1: 2
Enter Radius for circle 2: 4
Radius of Circle 1: 2
Area of Circle 1: 12.5664
Radius of Circle 2: 4
Area of Circle 2: 50.2654
Keep getting this error message when trying to compile in main1.cpp. Need help figuring out how...
Need some help on this C++ program. Circle - color:String - radius:double +Circle() +Circle(newColor:String, newRadius:double) +setColor(color:String):void +setRadius(radius:double):void +getColor():String +getRadius():double +printCircleInfo():void Create the class using three files - a .h, a .cpp and a main.cpp Create a class called Circle as describe below Constructor with no arguments Sets radius to 1 and color to “black” Constructor with arguments Sets the color and radius to the values passed in Get methods (accessors) return the field that the get refers to Set methods...
Need C++ Code (Please put //comments on there too) 1. Complete the following code: Design a class called Circle. The class should have an integer member variable named radius and three member functions; setRadius, getRadius, calArea; the functions' prototypes should be done inside the class declaration and the functions' definitions should come after the main function #include <iostream> using namespace std; const double PI = 3.14; // fill in the declaration of the class Circle here int main() { Circle...
c++ Please help! i keep getting an error message. I think my
main problem is not understanding the circle calculations function
and how both the area and the circumference is returned from the
function. I know & needs to be used, but I am unsure how to use
it.
Copy the following code and run it. You should break it into the following 3 functions getValidinput - which asks the user to enter the radius and then make sure that...
Extend the code from Lab6.A template is given to you with CircleHeader.h, Circle.cpp and CircleMain.cpp Use the same Circle UML as below and make extensions as marked and as needed. Given below is a UML for the Painting Class. You will need to write PaintingHeader.h and Painting.cpp. The Painting Class UML contains a very basic skeleton. You will need to flesh out this UML and add more instance variables and methods as needed. You do NOT need to write a...
Pure Abstract Base Class Project. Define a class called BasicShape which will be a pure abstract class. The class will have one protected data member that will be a double called area. It will provide a function called getArea which should return the value of the data member area. It will also provide a function called calcArea which must be a pure virtual function. Define a class called Circle. It should be a derived class of the BasicShape class. This...
#include <iostream> using namespace std; class Circle{ // private member variable named radius private: double radius; // get function for radius public: double getRadius(){ return radius; } // set function for radius void setRadius(double rad){ radius=rad; } // returning area = 3.14159 * radius * radius double getArea(){ return (3.14159 * radius * radius); } }; // Sample run int main() { // Declaring object of Circle Circle myCircle; myCircle.setRadius(5); // printing radius of circle cout<<"Radius of circle is: "<<(myCircle.getRadius())<<endl;...
C++ Class and Operator Overloading part 1 The source file contains a C++ program that declares and initializes an array of Circles. The program is using a for loop statement to find the largest circle in the array and display it on the output screen. However, the program is currently not working. The problem is the program uses logical operator ' > ' for comparison of circles and it is not working unless we overload such operator for the class...
I need to implement a program that requests a x,y point and the radius of a circle. then it figures out the area and circumference using an overloaded operation. The full instructions, what I have and the errors I have are below. A point in the x-y plane is represented by its x-coordinate and y-coordinate. Design a class, pointType, that can store and process a point in the x-y plane. You should then perform operations on the point, such as...
PLEASE TYPE OUT IN TEXT (please no pdf or writing) C++ CODE Consider the following program in which the statements are in the incorrect order. Rearrange the statements in the following order so that the program prompts the user to input: The height of the base of a cylinder The radius of the base of a cylinder The program then outputs (in order): The volume of the cylinder. The surface area of the cylinder Format the output to two decimal...
In C++
Amanda and Tyler opened a business that specializes in shipping
liquids, such as milk, juice, and water, in cylindrical containers.
The shipping charges depend on the amount of the liquid in the
container. (For simplicity, you may assume that the container is
filled to the top.) They also provide the option to paint the
outside of the container for a reasonable amount. Write a program
that does the following:
Prompts the user to input the dimensions (in feet)...