Current location: Hot Scripts Forums » Programming Languages » C/C++ » I am having Problems compiling and running programs with C++


I am having Problems compiling and running programs with C++

Reply
  #1 (permalink)  
Old 09-27-09, 05:45 PM
janine6192 janine6192 is offline
New Member
 
Join Date: Sep 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
I am having Problems compiling and running programs with C++

Hi im janine.
I have been given three programming assignments to be completed this wednesday. I am really in need of help. Please for any assistance.

The 1st program is to
1.) Create a class called DigitSeparator. This class will only have one function called separator. Function separator will have ONE parameter of type long int which will be used to accept a six-digit number. Function separator will take the number passed to the parameter and separate it into its individual digits, multiply each separated digit by 2 and then print the digits separated from one another by three spaces each. (Hint: use a combination of integer division and modulus division to split the number into digits.) Create a driver program that will contain a main function that will create a DigitSeparator object and then call its separator function. Function main should ask the user for a number, and then pass this number to the function separator. For example, if the user types in 423339 then function separator should print

8 4 6 6 6 18

Please note that the user will type ONE integer only that has six digits, not six separate integers. Therefore, your program will only cin>> one data object. You should submit 3 files, DigitSepartor.h, DigitSeparator.cpp and DigitDriver.cpp.

Alrite i did all that but it gives me errors when i try 2 run d program. my code for this program is below:

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

#include "DigitSeparator.h"//include the class definition of DigitSeparator

int main()
{

long int number;              //user input

cout<<"Welcome to the Digit Separator Program!\n";//what the user sees on the screen
cout<<"Please enter a six digit number.\n";//prompts user to enter a digit
cin>>number;//input by user is stored in number


DigitSeparator myDigitSeparator;
myDigitSeparator.setSeparator(number);

	 



return 0;

}
Code:
/*Implementations of the DigitSeparator member-function definitions.
  The setSeparator function performs validation.
*/

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

#include "DigitSeparator.h"//include definition of class DigitSeparator

// class DigitSeparator definition

class DigitSeparator
{
public:
        //constructor initializes digits with integer supplied as argument
        DigitSeparator(long int number)
        {
			setSeparator(number)

        }//end DigitSeparator constructor

                
        //function to set the digit
        void setSeparator(long int number)
        {
                Separator = number;//store the digit in the object

        /*Declaration of variables used for:
          Integer Division and Modulus Operations
        */
                int     num1;
                int b;
                int     num2;  
                int d;
                int num3;
                int f;
                int num4;
                int h;
                int num5;
                int num6;

        //Below is the Integer and Modulus Operations

                num1 = Separator/100000;             
                b = Separator%100000;                     
                num2 = b/10000;                          
                d = b%10000;                        
                num3 = d/1000;          
                f = d%1000;                          
                num4 = f/100;                       
                h = f%100;              
                num5 = h/10;
                num6= h%10;

        //Calculations for outputting final answer

                num1 = num1 * 2
                num2 = num2 * 2
                num3 = num3 * 2
                num4 = num4 * 2
                num5 = num5 * 2
                num6 = num6 * 2

                
                cout<<num1<<" "<<num2<<" "<<num3<<" "<<num4<<" "<<num5<<" "<<num6;
        }
	}
}; //Ends the DigitSeparator class
Code:
/*DigitSeparator class definition presents the publice interface 
 of the class. Member-function definitions appear in DigitSeparator.cpp.
*/

//DigitSeparator class definition

class DigitSeparator
{
public:
        DigitSeparator();//constructor that initializes a DigitSeparator object
        void setSeparator(long int); //function that sets the Separator




};//end class DigitSeparator
The program compiles but when it tries 2 run it states:

DigitDriver.obj : error LNK2001: unresolved external symbol "public: void __thiscall DigitSeparator::setSeparator(long)" (?setSeparator@DigitSeparator@@QAEXJ@Z)
DigitDriver.obj : error LNK2001: unresolved external symbol "public: __thiscall DigitSeparator:igitSeparator(void)" (??0DigitSeparator@@QAE@XZ)
Debug/DigitDriver.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

DigitDriver.exe - 3 error(s), 0 warning(s)


The 2nd program is to :
Create a class called NumberFun. This class will contain 6 functions and 1 constructor (a total of 7 functions). It will also have 4 data members of type int called num1, num2, num3 and num4 respectively. Your constructor must have 4 parameters of type int because it will use these to initialize the class’s 4 data members. Your constructor will take the values it receives and pass it to function, setValues. Function setValues will therefore also have 4 parameters to accept the values being passed to it. It will then assign each of those parameters to each data member. The other functions and what they do are described below:
Function sum: will add all the data members and return their sum.
Function average: will compute and return the average of all the data members.
Function product: will compute and return the product of all the data members.
Function smallest: will determine and return data member that has the smallest value.
Function largest: will determine and return data member that has the largest value.

You will now create a driver program that will create a NumberFun object and test all its functions. You should submit a total of 3 files.

Alrite i did that. my code is:
Code:
// main.cpp
#include <iostream>
using std:: cout;
using std:: cin;
using std:: endl;
#include <iostream>
using std:: cout;
using std:: cin;
using std:: endl;

#include "NumberFun.h"

int main()
{
    int value1, value2, value3, value4;

cout << "Welcome to the Number Fun Program!" << endl;
cout << "Please enter a number. " << endl;
cin >> value1;
cout << "Please enter a number. " << endl;
cin >> value2;
cout << "Please enter a number. " << endl;
cin >> value3;
cout << "Please enter a number. " << endl;
cin >> value4;

NumberFun myNumberFun(value1 , value2 , value3 , value4);
myNumberFun.calculateSum();
myNumberFun.calculateAverage();
myNumberFun.calculateProduct();
myNumberFun.determineSmallestNumber();
myNumberFun.determineLargestNumber();


return 0;


}
Code:
// NumberFun.cpp
#include <iostream>
using std:: cout;
using std:: cin;
using std:: endl;

#include "NumberFun.h"

NumberFun::NumberFun(int value1 , int value2 , int value3 , int value4)
{
setValues(value1 , value2 , value3 , value4 );
}

void NumberFun::setValues(int value1 , int value2 , int value3 , int value4)
{
{
num1 = value1;
num2 = value2;
num3 = value3;
num4 = value4;

cout << "\nThe number you inputted are: " << endl;
cout << num1 << ", " << num2 << ", " << num3 << ",and " << num4 << endl;
}
}


void NumberFun::calculateSum()
{
{
int sum;
sum = num1 + num2 + num3 + num4;

cout << "\nThe sum of the numbers are: " << sum << endl;
}
}


void NumberFun::calculateAverage()
{
{
int sum = 0;
int average = 0;
sum = num1 + num2 + num3 + num4;
average = sum / 4;

cout << "The average of the numbers are: " << average << endl;

}
}

void NumberFun::calculateProduct()
{
{
int product = 0;
product = num1 * num2 * num3 * num4;

cout << "The product of the numbers are: " << product << endl;
}
}

void NumberFun::determineSmallestNumber()
{
if(num1 < num2)// determine if the first number inputted by user is the smallest number
{
if (num1 < num3)
if (num1 < num4)
cout << "The smallest number is " << num1 << endl;
}

else if (num2 < num1)// determine if the second number inputted by user is the smallest number
{
if (num2 < num3)
if (num2 < num4)
cout << "The smallest number is " << num2 << endl;
}

else if(num3 < num1)// determine if the third number inputted by user is the smallest number
{
if (num3 < num2)
if (num3 < num4)
cout << "The smallest number is " << num3 << endl;
}
else if(num4 < num1)// determine if the third number inputted by user is the smallest number
{
if (num4 < num2)
if (num4 < num3)
cout << "The smallest number is " << num4 << endl;
}
}

void NumberFun::determineLargestNumber()
{
if(num1 > num2)
{
if (num1 > num3)
if (num1 > num4)
cout << "The largest number is " << num1 << endl;
}

else if (num2 > num1)
{
if (num2 > num3)
if (num2 > num4)
cout << "The largest number is " << num2 << endl;
}

else if(num3 > num1)
{
if (num3 > num2)
if (num3 > num4)
cout << "The largest number is " << num3 << endl;
}
else if(num4 > num1)
{
if (num4 > num2)
if (num4 > num3)
cout << "The largest number is " << num4 << endl;
}
}
Code:
// NumberFun.h
#include <iostream>
using std:: cout;
using std:: cin;
using std:: endl;


class NumberFun
{
public:
NumberFun(int , int , int , int);
void setValues(int , int , int , int);
void calculateSum();
void calculateAverage();
void calculateProduct();
void determineSmallestNumber();
void determineLargestNumber();
private:
int num1;
int num2;
int num3;
int num4;
};
it states these following errors when running :
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/NumberFun.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

NumberFun.exe - 2 error(s), 0 warning(s)

my final program is to :
Create a class called Table. Class Table will only have one function called displayTable. Using only the techniques you learned THUS FAR, make function displayTable CALCULATE (and this means you cannot simply hardcode the values in print statements, you must calculate and then print the calculated result) the squares and cubes of the numbers from 0 to 10 and uses tabs to print the following table of values. If you use techniques that were not covered in class, half your points will be deducted. The diagram below illustrates what function displayTable should produce. Create a driver program that tests the Table class.


my code is :
Code:
#include <iostream>
using std:: cout;
using std:: endl;

#include "Table.h"

void Table::displayTableCalculate();
{
public:	
		int numb0;
		int numb1;
		int numb2;
		int numb3;
		int numb4;
		int numb5;
		int numb6;
		int numb7;	
		int numb8;
		int numb9;
		int numb10;

		int squarenumb0;
		int squarenumb1;
		int squarenumb2;
		int squarenumb3;
		int squarenumb4;
		int squarenumb5;
		int squarenumb6;
		int squarenumb7;
		int squarenumb8;
		int squarenumb9;
		int squarenumb10;

		int cubenumb0;
		int cubenumb1;
		int cubenumb2;
		int cubenumb3;
		int cubenumb4;
		int cubenumb5;
		int cubenumb6;
		int cubenumb7;
		int cubenumb8;
		int cubenumb9;
		int cubenumb10;

		numb0 = 0;
		numb1 = 1;
		numb2 = 2;
		numb3 = 3;
		numb4 = 4;
		numb5 = 5;
		numb6 = 6;
		numb7 = 7;
		numb8 = 8;
		numb9 = 9;
		numb10 = 10;

		squarenumb0 = numb0 * numb0; 
		squarenumb1 = numb1 * numb1;
		squarenumb2 = numb2 * numb2;
		squarenumb3 = numb3 * numb3;
		squarenumb4 = numb4 * numb4;
		squarenumb5 = numb5 * numb5;
		squarenumb6 = numb6 * numb6;
		squarenumb7 = numb7 * numb7;
		squarenumb8 = numb8 * numb8;
		squarenumb9 = numb9 * numb9;
		squarenumb10 = numb10 * numb10;

		cubenumb0 = numb0 * numb0 * numb0;
		cubenumb1 = numb1 * numb1 * numb1;
		cubenumb2 = numb2 * numb2 * numb2;
		cubenumb3 = numb3 * numb3 * numb3;
		cubenumb4 = numb4 * numb4 * numb4;
		cubenumb5 = numb5 * numb5 * numb5;
		cubenumb6 = numb6 * numb6 * numb6;
		cubenumb7 = numb7 * numb7 * numb7;
		cubenumb8 = numb8 * numb8 * numb8;
		cubenumb9 = numb9 * numb9 * numb9;
		cubenumb10 = numb10 * numb10 * numb10;


		cout << "number\t" << "square\t" << "cube\t"<< endl;
		cout << numb0 << "\t" << squarenumb0 << "\t" << cubenumb0 << endl;
		cout << numb1 << "\t" << squarenumb1 << "\t" << cubenumb1 << endl;
		cout << numb2 << "\t" << squarenumb2 << "\t" << cubenumb2 << endl;
		cout << numb3 << "\t" << squarenumb3 << "\t" << cubenumb3 << endl;
		cout << numb4 << "\t" << squarenumb4 << "\t" << cubenumb4 << endl;
		cout << numb5 << "\t" << squarenumb5 << "\t" << cubenumb5 << endl;
		cout << numb6 << "\t" << squarenumb6 << "\t" << cubenumb6 << endl;
		cout << numb7 << "\t" << squarenumb7 << "\t" << cubenumb7 << endl;
		cout << numb8 << "\t" << squarenumb8 << "\t" << cubenumb8 << endl;
		cout << numb9 << "\t" << squarenumb9 << "\t" << cubenumb9 << endl;
		cout << numb10 << "\t" << squarenumb10 << "\t" << cubenumb10 << endl;
	}
Code:
#include <iostream>
using std:: cout;
using std:: endl;

class Table
{
public:
	void displayTableCalculate();
};
Code:
#include "Table.h"


int main()
{

Table.displayTableCalculate();

	return 0;





};
its errors are:
C:\Users\jcastillo\Desktop\Table Program\TableDriver.cpp(7) : error C2143: syntax error : missing ';' before '.'
C:\Users\jcastillo\Desktop\Table Program\TableDriver.cpp(7) : error C2143: syntax error : missing ';' before '.'
Error executing cl.exe.

TableDriver.exe - 2 error(s), 0 warning(s)

Last edited by janine6192; 09-27-09 at 05:50 PM.
Reply With Quote
  #2 (permalink)  
Old 09-29-09, 09:53 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
I don't know much about C++, but in the last bit of code, the syntax error comes from this line:
Code:
void Table::displayTableCalculate();
{
... remove the semi-colon.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro for compiling and running Java with Komodoedit 4.4 homstad Everything Java 0 01-28-09 06:47 PM


All times are GMT -5. The time now is 04:40 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.