Please find and correct the error in my c++ program. "Linker Error: Undefined symbol _main in module c0.ASM"
The program is for transfering content of one file to another.

#include<fstream.h>
#include<iostream.h>
#include<conio.h>
class student
{
int rollno;
char name[20];
int tm;
public:
void input();
void transfer();
void output();
}
obj;
void student::input()
{
char ch='y';
ofstream outf;
outf.open("mark.dat");
while(ch=='y')
{
cout<<"Enter rollno, name and mark";
cin>>rollno>>name>>tm;
outf.write((char*)&obj,sizeof(obj));
cout<<"wish to enter more(Y/N)";
cin>>ch;
}
outf.close();
}
void student::transfer()
{
ofstream outf;
ifstream inf;
inf.open("mark.dat");
inf.open("trans.dat");
while(inf)
{
inf.read((char*)&obj,sizeof(obj));
outf.write((char*)&obj,sizeof(obj));
}
outf.close();
inf.close();
}
void student::output()
{
ifstream inf;
inf.open("trans.dat");
while(inf)
{
inf.read((char*)&obj,sizeof(obj));
cout<<"Rollno"<<rollno;
cout<<"Name"<<name;
cout<<"Total"<<tm;
}
getch();
inf.close();
}

The error i get is
compiling 10.cpp
linking ...\OUTPUT\10.EXE
.Linker Error: Undefined symbol _main in module c0.ASM

I think the error is due to the missing of void main. But i don't know where i should put it.

Edited 2 Years Ago by Dani: Formatting semi-fixed

think i got this from my friend

void main()
{
    student obj;
    obj.input();
    obj.transfer();
    obj.output();
    getch();
}

He told to put it at last but hwo do i do that?

Edited 2 Years Ago by Dani: Formatting fixed

I found the error and corrected it.

#include<fstream.h>
#include<iostream.h>
#include<conio.h>
class student
{
int rollno;
char name[20];
int tm;
public:
void input();
void transfer();
void output();
}
obj;
void student::input()
{
char ch='y';
ofstream outf;
outf.open("mark.dat");
while(ch=='y')
{
cout<<"Enter rollno, name and mark";
cin>>rollno>>name>>tm;
outf.write((char*)&obj,sizeof(obj));
cout<<"wish to enter more(Y/N)";
cin>>ch;
}
outf.close();
}
void student::transfer()
{
ofstream outf;
ifstream inf;
inf.open("mark.dat");
inf.open("trans.dat");
while(inf)
{
inf.read((char*)&obj,sizeof(obj));
outf.write((char*)&obj,sizeof(obj));
}
outf.close();
inf.close();
}
void student:utput()
{
ifstream inf;
inf.open("trans.dat");
while(inf)
{
inf.read((char*)&obj,sizeof(obj));
cout<<"Rollno"<<rollno;
cout<<"Name"<<name;
cout<<"Total"<<tm;
}
inf.close();
}
void main()
{
student obj;
obj.input();
obj.transfer();
obj.output();
getch();
}

Edited 2 Years Ago by Dani: Formatting fixed. Please indent your code.

I still have another problem. That is when the while loop asks continue(y/n)
When i enter n it just stuck there.

I need to make the program error free urgently. Please reply with solution. I use borland turbo c++ 3

char str[] = 'stop';
if (isupper (str) =="STOP")
exit(0);

Edited 6 Years Ago by Nick Evan: Added code-tags

Comments
Over a year to bump a dead thread with untagged incorrect code? Trying to demonstrate you're a poor programmer?

area calculator program linker error C++
Reply Watch this Article Start New Discussion
Member Avatar
dstaner
Newbie Poster
5 posts since Nov 2010

0

3 Years Ago

Hello, I'm just learning C++ and I'm getting an error with a program that is driving me nuts, and I'm not exactly sure how to resolve it. Can anyone help me?

AreaCalculator.obj : error LNK2019: unresolved external symbol "double __cdecl AreaOfTriangle(double,double)" (?AreaOfTriangle@@YANNN@Z) referenced in function _main
\\.psf\Home\Documents\Visual Studio 2008\Projects\AreaCalculator\Debug\AreaCalculator.exe : fatal error LNK1120: 1 unresolved externals

#include <iostream>  //for using cin and cout
#include <conio.h>   //for using getch()
#include <cmath> //for using pow
using namespace std;
double AreaOfRectangle(/* in */ double length, //length of rectangle
/* in */ double width); //width of rectangle
//Purpose: Calculate the area of a rectangle
//Precondition:
// length and width are assigned the length and width of the rectangle.
// length > 0 and width > 0
//Postcondition:
// Returns the area of the rectangle
double AreaOfCircle(/* in */ double radius); //radius of circle
//Purpose: Calculate the area of a circle
//Precondition:
// radius is assigned the radius of the circle.
// radius > 0
//Postcondition:
// Returns the area of the circle.
double AreaOfTriangle (/* in */ double base, //length of triangle base
/* in */ double height); //height of triangle
//Purpose: Calculate the area of a triangle
//Precondition:
// base and height are assigned the base and height of the triangle
// base > 0 and height > 0
//Postcondition:
// Returns the area of the triangle.
int main()
{
double radius;  //radius of circle
double length;  //length of rectangle
double width;   //width of rectangle
double base;    //base length of triangle
double height;  //height of triangle
int number; //number entered to indicate user's selection
//display a heading
cout << "*** Calculation of area ***\n\n\n";
//Ask user to enter 1 or 2 and read the number
cout << "Enter 1 to calculate the area of a rectangle, \n";
cout << " 2 to calculate the area of a circle, or\n";
cout << " 3 to calculate the area of a triangle.\n\n";
cout << "Please enter 1, 2, or 3: ";
cin >> number;
cout << endl;
//calculate area of rectangle or area of circle
if (number == 1)    //for calculating the area of rectangle
{
//prompt for and read the length and width of rectangle
cout << "Enter the length of the rectangle in inches: ";
cin >> length;  
cout << "Enter the width of the rectangle in inches: ";   
cin >> width;   
//Call function to calculate area of rectangle, and display the area
cout << endl << "Area of rectangle is: " << AreaOfRectangle(length,width)
<< " square inches.\n\n"; 
}
else if (number == 2 )  //for calculating the area of circle
{
//prompt for and read the radius of circle
cout << "Enter the radius of the circle in inches: ";
cin >> radius;
//Call function to calculate area of circle, and display the area
cout << endl << "Area of circle is " << AreaOfCircle(radius) << " square inches.\n\n";  
}
else if (number == 3)   //for calculating the area of a triangle
{
//prompt for and read the base and height of the triangle
cout << "Enter the base of the triangle in inches: ";
cin >> base;
cout << "Enter the height of the triandgle in inches: ";
cin >> height;
//Call the function to calculate the area of a triangle, and display the area
cout << endl << "Area of triangle is " << AreaOfTriangle(base,height) << "square inches.\n\n";
}
else
cout << "Invalid number entered. \n\n"; //number other than 1 and 2 entered
_getch();   //to hold the screen for viewing
return 0;
}
//-----------------------------------------------------------------------------------
double AreaOfRectangle(/* in */ double length, //length of rectangle
/* in */ double width ) //width of rectangle
{
double areaRect;    //area of rectangle
//calculate the area
areaRect = length * width;
return areaRect;
}
//-------------------------------------------------------------------------------------
double AreaOfCircle(/* in */ double radius ) //radius of circle
{
const double PI = 3.14159;
double areaCirc; //area of circle
//calculate area of circle
areaCirc = PI * pow(radius,2.0); //note the use of the predefined function pow
return areaCirc;
}
//--------------------------------------------------------------------------------------
double AreaOfTrianglw(/* in */ double base, //length of base of triangle
/* in */ double height) //height of triangle
{
double areaTri; //area of triangle
//calculate area of triangle
areaTri = (base * height) / 2;
return areaTri;
}

area calculator program linker error C++
Reply Watch this Article Start New Discussion
Member Avatar
dstaner
Newbie Poster
5 posts since Nov 2010

0

3 Years Ago

Hello, I'm just learning C++ and I'm getting an error with a program that is driving me nuts, and I'm not exactly sure how to resolve it. Can anyone help me?

AreaCalculator.obj : error LNK2019: unresolved external symbol "double __cdecl AreaOfTriangle(double,double)" (?AreaOfTriangle@@YANNN@Z) referenced in function _main
\\.psf\Home\Documents\Visual Studio 2008\Projects\AreaCalculator\Debug\AreaCalculator.exe : fatal error LNK1120: 1 unresolved externals

#include <iostream>  //for using cin and cout
#include <conio.h>   //for using getch()
#include <cmath> //for using pow
using namespace std;
double AreaOfRectangle(/* in */ double length, //length of rectangle
/* in */ double width); //width of rectangle
//Purpose: Calculate the area of a rectangle
//Precondition:
// length and width are assigned the length and width of the rectangle.
// length > 0 and width > 0
//Postcondition:
// Returns the area of the rectangle
double AreaOfCircle(/* in */ double radius); //radius of circle
//Purpose: Calculate the area of a circle
//Precondition:
// radius is assigned the radius of the circle.
// radius > 0
//Postcondition:
// Returns the area of the circle.
double AreaOfTriangle (/* in */ double base, //length of triangle base
/* in */ double height); //height of triangle
//Purpose: Calculate the area of a triangle
//Precondition:
// base and height are assigned the base and height of the triangle
// base > 0 and height > 0
//Postcondition:
// Returns the area of the triangle.
int main()
{
double radius;  //radius of circle
double length;  //length of rectangle
double width;   //width of rectangle
double base;    //base length of triangle
double height;  //height of triangle
int number; //number entered to indicate user's selection
//display a heading
cout << "*** Calculation of area ***\n\n\n";
//Ask user to enter 1 or 2 and read the number
cout << "Enter 1 to calculate the area of a rectangle, \n";
cout << " 2 to calculate the area of a circle, or\n";
cout << " 3 to calculate the area of a triangle.\n\n";
cout << "Please enter 1, 2, or 3: ";
cin >> number;
cout << endl;
//calculate area of rectangle or area of circle
if (number == 1)    //for calculating the area of rectangle
{
//prompt for and read the length and width of rectangle
cout << "Enter the length of the rectangle in inches: ";
cin >> length;  
cout << "Enter the width of the rectangle in inches: ";   
cin >> width;   
//Call function to calculate area of rectangle, and display the area
cout << endl << "Area of rectangle is: " << AreaOfRectangle(length,width)
<< " square inches.\n\n"; 
}
else if (number == 2 )  //for calculating the area of circle
{
//prompt for and read the radius of circle
cout << "Enter the radius of the circle in inches: ";
cin >> radius;
//Call function to calculate area of circle, and display the area
cout << endl << "Area of circle is " << AreaOfCircle(radius) << " square inches.\n\n";  
}
else if (number == 3)   //for calculating the area of a triangle
{
//prompt for and read the base and height of the triangle
cout << "Enter the base of the triangle in inches: ";
cin >> base;
cout << "Enter the height of the triandgle in inches: ";
cin >> height;
//Call the function to calculate the area of a triangle, and display the area
cout << endl << "Area of triangle is " << AreaOfTriangle(base,height) << "square inches.\n\n";
}
else
cout << "Invalid number entered. \n\n"; //number other than 1 and 2 entered
_getch();   //to hold the screen for viewing
return 0;
}
//-----------------------------------------------------------------------------------
double AreaOfRectangle(/* in */ double length, //length of rectangle
/* in */ double width ) //width of rectangle
{
double areaRect;    //area of rectangle
//calculate the area
areaRect = length * width;
return areaRect;
}
//-------------------------------------------------------------------------------------
double AreaOfCircle(/* in */ double radius ) //radius of circle
{
const double PI = 3.14159;
double areaCirc; //area of circle
//calculate area of circle
areaCirc = PI * pow(radius,2.0); //note the use of the predefined function pow
return areaCirc;
}
//--------------------------------------------------------------------------------------
double AreaOfTrianglw(/* in */ double base, //length of base of triangle
/* in */ double height) //height of triangle
{
double areaTri; //area of triangle
//calculate area of triangle
areaTri = (base * height) / 2;
return areaTri;
}

This is from line 023 double AreaOfTriangle
This is from line 102 double AreaOfTrianglw

Notice anything wrong? Also dont hijack and old thread with a new problem. Start a thread instead.

Edited 2 Years Ago by NathanOliver

This question has already been answered. Start a new discussion instead.