Welcome to Tech Support Forum home to more then 136,000 problems solved. Issues have included: Spyware, Malware, Virus Issues, Windows, Microsoft, Linux, Networking, Security, Hardware, and Gaming Getting your problem solved is as easy as:
1. Registering for a free account
2. Asking your question
3. Receiving an answer

Registered members:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* See fewer ads.
* And much more..

 





Want to know how to post a question? click here Having problems with spyware and pop-ups? First Steps
Go Back   Tech Support Forum > The Conversation Pit > Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read

Programming A discussion forum for programs and programming used in tech-related businesses.

Reply
 
Thread Tools
Old 04-28-2008, 04:06 AM   #1 (permalink)
Registered User
 
Join Date: Apr 2008
Posts: 1
OS: XP sp2


Problem with user-defined functions

I am getting multiple errors when I try to run the program without debugging and I have no clue how to fix them. Any help would be appreciated.

These are the errors:
Code:
1>------ Build started: Project: Assign5, Configuration: Debug Win32 ------
1>Linking...
1>Assign5 code.obj : error LNK2019: unresolved external symbol "void __cdecl process_student(class std::basic_ofstream<char,struct std::char_traits<char> > &,class std::basic_ifstream<char,struct std::char_traits<char> > &)" (?process_student@@YAXAAV?$basic_ofstream@DU?$char_traits@D@std@@@std@@AAV?$basic_ifstream@DU?$char_traits@D@std@@@2@@Z) referenced in function _main
1>Assign5 code.obj : error LNK2019: unresolved external symbol "void __cdecl outfile_header(class std::basic_ofstream<char,struct std::char_traits<char> > &)" (?outfile_header@@YAXAAV?$basic_ofstream@DU?$char_traits@D@std@@@std@@@Z) referenced in function _main
1>Assign5 code.obj : error LNK2019: unresolved external symbol "void __cdecl out_file(class std::basic_ofstream<char,struct std::char_traits<char> > &)" (?out_file@@YAXAAV?$basic_ofstream@DU?$char_traits@D@std@@@std@@@Z) referenced in function _main
1>Assign5 code.obj : error LNK2019: unresolved external symbol "void __cdecl print_file(void)" (?print_file@@YAXXZ) referenced in function "void __cdecl process_student(class std::basic_ifstream<char,struct std::char_traits<char> > &,class std::basic_ofstream<char,struct std::char_traits<char> > &,int &,char &,float &,float &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &)" (?process_student@@YAXAAV?$basic_ifstream@DU?$char_traits@D@std@@@std@@AAV?$basic_ofstream@DU?$char_traits@D@std@@@2@AAHAADAAM4AAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@5@Z)
1>C:\Documents and Settings\My Documents\Visual Studio 2008\Projects\Assign5\Debug\Assign5.exe : fatal error LNK1120: 4 unresolved externals

and this is the actual code

Code:
#include <iomanip>
#include <string>
#include <fstream>
#include <iostream>

using namespace std; 

void open_file(ifstream & fin);
void out_file (ofstream & fout);
void outfile_header(ofstream & fout);
void print_header();
char grade_it (float &average);
float find_average(ifstream & fin);
void process_student (ofstream & fout, ifstream &fin);
void print_file ();

void main ()
{
	ifstream fin;
	ofstream fout;

	print_header();
	open_file(fin);

	if (fin)
	{
		out_file(fout);
		outfile_header(fout);
		process_student(fout, fin);



		outfile_header(fout);

		fin.close();
		fout.close();

	}

}


void open_file(ifstream & fin)
{
	string input_file;
	cout << "Please enter input file name: ";
	getline (cin, input_file) ;
	fin.open(input_file.c_str());
	if(fin.fail())
	{
		cout <<endl <<"Bad File Name" <<endl;
		//wonder if this will work**************************
	}
	
}//opens the input file and checks it

void out_file(ofstream &, string &output_file)
{
	cout << "Please enter output file name: ";
	getline (cin, output_file); 
}//prompts for a name and creates an output file

void outfile_header(ofstream &fout, string &output_file)
{
		fout.open (output_file.c_str());
		fout << left << fixed;
		fout << setw (25) << "Name";
		fout << setw (15) << "Average";
		fout << setw (6)  << "Grade";
		fout << endl;
		
		fout << right << setfill ('-');

		fout << setw (25) << "              ";
		fout << setw (15) << "       ";
		fout << setw (6)  << "-";
		fout << endl;

		fout << left << setfill (' ');
}//creates the header of the output file

void print_header(void)
{
	cout << "This program will process test scores to provide individuals with \na letter grade report according to the following scale: ";
	cout << "\n\n\t\t 90  < average <=\t100\tA";
	cout << "\n\t\t 80  < average <=\t90\tB";
	cout << "\n\t\t67.7 < average <=\t80\tC";
	cout << "\n\t\t 55  < average <=\t67.5\tD";
	cout << "\n\t\t  0  < average <=\t55\tF";
}

char grade_it(float &average)
{
	char grade;

	if (average > 90 && average <= 100)
		grade = 'A';
	else if (average > 80 && average <= 90)
		grade = 'B';
	else if (average > 67.5 && average <= 80)
		grade = 'C';
	else if (average > 55 && average <= 67.5)
		grade = 'D';
	else 
		grade = 'F';

	return (grade);
}//Grades the test average

float find_average(ifstream & fin)
{
	string firstname;
	float counter = 0,	sum = 0, score, average;

	cout << "======================================================================";
	cout << "\n\nTest scores for " << firstname << "are: ";

	do
		{
			fin >> score;

			if (score >= 0)
			{
				sum+=score;
				counter++;
				cout << score << " ";
			}//close if

		}//close do
	while (score >= 0);

	average = sum/counter;
	return (average);

}

void process_student(ifstream & fin, ofstream & fout, int &check, char &grade, float &average, float &counter, string &firstname, string &lastname)
{
	check = 0;

	fin >> firstname;
	while (!fin.eof())
	{

		check++;
		fin >> lastname;

		average = find_average(fin);
		grade = grade_it(average);
		if (check = 0)
			cout << "***Empty File***";
		else
		{
			if (counter = 0)
			{
				cout << "\n\nGrade report for " << firstname << ' ' << lastname << ':';
				cout << " There is no score entered for " << firstname << ' ' << lastname;
				cout << ", average and grade is not calculated.";
			}
			else
			{
				cout << "\n\nGrade report for " << firstname << ' ' << lastname << ':';
				cout << "The average of " << counter << " tests is " << setprecision (1) << average;
				cout << setprecision (0) << " and the letter grade is " << grade << ".";
			}
		

			print_file();
		

		}//closes while
	}
	
}

void print_file (ofstream &fout, int &check, float &counter, float &average, char &grade, string &firstname, string &lastname)
{

	if (check=0)
		fout << "***Empty File***";
	else 
	{
		fout << left << fixed;
		fout << endl << setw (25) << lastname << ", " << firstname;
		
		if (counter = 0)
			fout << "No Scores";
		else
			fout << setprecision (1) << setw (15) << average << setprecision (0) << setw (6) << grade;

	}
}
D2nate is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -7. The time now is 06:49 AM.



Copyright 2001 - 2008, Tech Support Forum

Search Engine Friendly URLs by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81