Hey everyone,

Today i was just studying C++ and i needed to do a simple program with a "GradeBook.h" file, a "GradeBook.cpp" and a "main.cpp".Just to test how class works . I had already wrote all source code for this files, but when it cames to compile nothing appears, i mean the console window opens and closes instantly with no reason :( . I'm using Visual Studio 2010 Ultimate.
I would appreciate your help :)

Recommended Answers

All 14 Replies

may be you'll just need to put a cin.getchar() right before you return from main(), or a suitable breakpoint...


can't tell you more than that without looking at the code...:)

may be you'll just need to put a cin.getchar() right before you return from main(), or a suitable breakpoint...


can't tell you more than that without looking at the code...:)

I had already try that and "error" keeps persisting :( .


GradeBook.h

#include <string> 
using std::string;

// GradeBook class definition
class GradeBook
{
public:
   GradeBook( string ); 
   void setCourseName( string ); 
   string getCourseName(); 
   void displayMessage(); 
private:
   string courseName; 
}; // end class GradeBook

GradeBook.cpp

#include <iostream>
using std::cout; 
using std::endl;

#include "GradeBook.h" 


GradeBook::GradeBook( string name )
{
   setCourseName( name ); 
}


void GradeBook::setCourseName( string name )
{
   courseName = name; 
} 


string GradeBook::getCourseName()
{
   return courseName; 
} 


void GradeBook::displayMessage()
{
   
   cout << "Welcome to the grade book for\n" << getCourseName() 
      << "!" << endl;
}

main.cpp

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
	return 0;
}

#include <iostream>
using std::cout; 
using std::endl;

#include "GradeBook.h" 


int main()
{
   
   GradeBook gradeBook1( "CS101 Introduction to C++ Programming" );
   GradeBook gradeBook2( "CS102 Data Structures in C++" );

   
   cout << "gradeBook1 created for course: " << gradeBook1.getCourseName()
      << "\ngradeBook2 created for course: " << gradeBook2.getCourseName() 
      << endl;
  
   return 0; 
}

That's all i have. I actually didn't find any mistakes here. :S

commented: you are writing organized and neat code...good start for a beginner... +1

firstly delete line no. 4 to 7 in main.cpp

secondly add a #include "stdafx.h" at the top of GradeBook.cpp, if you are getting related errors.

thirdly put this line on line no. 26 in main.cpp

std::cin.get();

see if its working...

firstly delete line no. 4 to 7 in main.cpp

secondly add a #include "stdafx.h" at the top of GradeBook.cpp, if you are getting related errors.

thirdly put this line on line no. 26 in main.cpp

std::cin.get();

see if its working...

Hum. . I tried and it isn't working :( . But the most strange for me is that any errors appear :S, so this leads me to think that all source code is right .
I tried to open via cmd and the screen is like the following:

C:\Debug ->
//then I type myproject.exe and nothing happens, just keep persisting in "C:\Debug ->"

When creating a new project in VS 2010 try creating an empty project when the program asks.

I think you are learning from Deitel's How to Program C++. That is a good book, but have a look at Accelerated C++ and other books whose names can be found in the C++ Books sticky thread here on Daniweb C++ category.

well, i did what i told you to do and it's working for me...try what Tellalca told you...create an empty project and see if it works...


btw, i used Visual Studio 2010 Ultimate as well...

When creating a new project in VS 2010 try creating an empty project when the program asks.

I think you are learning from Deitel's How to Program C++. That is a good book, but have a look at Accelerated C++ and other books whose names can be found in the C++ Books sticky thread here on Daniweb C++ category.

Hum, i tried and now i'm getting two errors :S

Unresolved external symbol_mainCRTStartup
1 unresolved externals

Hum,i have on my pc more than 500 C++ books, but i'm really enjoying this one "How to program in C++". The author explains everything in detail and this is great. My idea was to read this till the end and do all exercises.
Sometimes not finishing a book isn't good, we can get confused!

It seems that this time you don't have the main() function (previously you had two!).
So, add one and see if you get any output.

#include <iostream>
int main()
{
  std::cout << "testing ...\n";
  return 0; 
}

It seems that this time you don't have the main() function (previously you had two!).
So, add one and see if you get any output.

#include <iostream>
int main()
{
  std::cout << "testing ...\n";
  return 0; 
}

Yeah, now i'm getting output "testing . . . " as expected! I'll keep searching for a solution, it should be something that i'm forgetting and probably it's so simple to fix this :)

I think you are not following me...

i told you previously to delete line nos. 4 to 7(according to the daniweb listing) in main.cpp because you had two main() !!
And that (having two main()) is precisely the cause for that error Unresolved external symbol_mainCRTStartup
...

You don't have to search for the solution to a problem that doesn't exist...!!!

Be a bit more careful and you'll get it...:)

I did everything you told me and still didn't work. I tried another example and the got the same errors. .

Header1.h

class Analysis
{
public:
	void processExamResults(); //process 10 students exams results
}; // end of class Analysis

Source1.cpp

#include "stdafx.h"
#include <iostream>
using std::cout;
using std::cin;
using std::endl;


#include "Header1.h"


void Analysis::processExamResults()
{
	//initializing variables in declarations
	int passes = 0;
	int failures = 0;
	int studentCounter = 1;
	int result;

	while (studentCounter <= 10)
	{
		cout << "Enter result (1-pass    2-fail)\n";
		cin >> result;


		if (result == 1)
			passes = passes + 1;
		else 
			if (result == 2)
				failures = failures  + 1;

		//increment student counter so loops can eentually terminate
		studentCounter = studentCounter + 1;
	} //end while loop

	cout << "Passed: " << passes << "\nFailed: " << failures << endl;

	if (passes > 8)
		cout << "Raised tuition";
} //end function processExamResults

Source2.cpp

#include "Header1.h"

int main ()
{
	Analysis application; // create analysis object
	application.processExamResults(); //call function to process results
	return 0;
}

I'm desperating. . . :(

Finally i got it working! I just search on google for a solution and found it quickly :) Thank you all for your help.

so what was the solution??

so what was the solution??

I was doing some ridiculous things :( For example i wasn't saving all files, i mean , i tried to compile even without saving the project. But the worst mistake was in the "Solution Explorer". I didn't add the files in "Source Files" and "Header files", so as it SHOULD be expect the program won't compile.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.