473,396 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Having following errors error C2064: term does not evaluate to a function and C4291

Hi,

I am getting above mentioned errors. Checked msdn, read the comments but I fail to implement it. Please help.

Error is regarding using the new and delete operators. Although I do write both, the compiler is not matching them and I guess there is a memory leak.

Program hangs after main returns, thats weired to me.

Thanks for all the help. Really appreciate it.

// 139_6_class.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "demography.h"

int main(int argc, char* argv[])
{
//User interface

printf("\nHomework-1 COP 3530 Summer 2007: by Anjana Patil\n");
printf("****************************************** ***********************************\n");
printf("\nThis program determines the population of each of the 3 regions\nwho's data is represented in an array of 3x3.");
printf("\n\nNOTE: This program doesn't have the ability of sizing the array.\n");
printf("\n**************************************** *************************************\n");

printf("\nThe array is 3 x 3 as shown below:\n\n");
printf("\t\tUrban\tSuburban\tExurban\n");
printf("Urban\t\t*\t+\t\t+\n");
printf("Suburban\t+\t*\t\t+\n");
printf("Exurban\t\t+\t+\t\t*\n");

printf("\n * internal growth rate and + annual migration in percentage\n\n");
printf("\nNOTE: User requires to key-in data for 3 arrays\n\n");

/////////////////////////////////////////////////////////////////////////////////////////
//nothrow version of new
//////////////////////////////////////////////////////////////////////////////////////////
Demograph* pObjDemograph = 0;
pObjDemograph = new(std::nothrow) Demograph();//Default Constructor is called
if (pObjDemograph == 0)
{
printf("\nAllocation failed");
exit(1);
}
else
{
pObjDemograph->set_score_array(); //User populates the score_array
pObjDemograph->set_zero_population(); //User populates the zeroth_population array
}

//////////////////////////////////////////////////////////////////////////////////////////

//pObjDemograph->set_score_array(); //User populates the score_array
pObjDemograph->display_score_array(); //Displays the array
//pObjDemograph->set_zero_population(); //User populates the zeroth_population array

pObjDemograph->population_size(); //Displays the final results

delete pObjDemograph;
pObjDemograph=0;

return 0;
}

//demography.h
//Header File for demography.cpp

//************************************************** **
//Array size is not specified at run-time.
//Built-in array size is specified at compile time.
//************************************************** **


#include <iostream>
#include <new>
#include <stdio.h>
#include <math.h>

using namespace std;
#define MAX_NUM 3

class Demograph
{
public:

Demograph();//Default constructor.

//***No argument constructor, since the class data member is an array. Arrays are constructed only using the default constructor. ***//

// Other member functions

void set_score_array(); //User populates the array
void display_score_array(); //Displays the contents of an array
void set_zero_population();//User inputs the initial population
void population_size(); //Calculates the population growth rate and their size in 'N' years

private:
//Data members

double score_array[MAX_NUM][MAX_NUM];
double zeroth_year[MAX_NUM]; //Population value at zeroth year*
Demograph* pObjDemograph;

}; //end of class declaration

#include "stdafx.h"
#include "demography.h"


/////////////////////////////////////////////////////////////////////////////////////////////
//Default constructor.

//Precondition: Array(1): size 3x3, Name: score_array[], stores demographic data for 3 regions.
// Array(2): size 1x3, Name: zeroth_year[], stores initial population in 3 regions.
//The arrays are not initialized.

//Postcondition:Both Array(1) and Array (2) are initialized to 0.0.
/////////////////////////////////////////////////////////////////////////////////////////////


Demograph::Demograph()
{
cout << "Default constructor is called. score_array[] and zeroth_year[]" << endl << "are initialized to zero.";
for (unsigned int i=0;i<MAX_NUM;i++)
for (unsigned int j=0;j<MAX_NUM;j++)
score_array[i][j]=0.0;

for (i=0;i<MAX_NUM;i++)
zeroth_year[i]=0.0;
}

///////////////////////////////////////////////////////////////////////////////
//Storing the keyed-in values to score_array[].

//Precondition: score_array[], cannot be initialized to data given in the problem.
//The array is not an empty set but it's initialized to zero.

//Postcondition: score_array[], is populated by the user.
///////////////////////////////////////////////////////////////////////////////

void Demograph::set_score_array()
{
cout << endl << endl << "First Input: ***Key-in their 9 data values to score_array[].***" << endl << endl;
for (unsigned int i=0;i<MAX_NUM;i++)
for (unsigned int j=0;j<MAX_NUM;j++)
{
cout << "Keyin score_array[" << i << "][" << j << "]=";
cin >> score_array[i][j];
}
}

//////////////////////////////////////////////////////////////////////////////
//Storing the keyed-in values to zeroth_year[].

//Precondition: zeroth_year[], cannot be initialized to data given in the problem.
//The array is not an empty set but it's initialized to zero.

//Postcondition: zeroth_year[], is populated by the user.
///////////////////////////////////////////////////////////////////////////////
void Demograph::set_zero_population()
{
cout << endl << "***Second Input: Key-in initial population of 3 regions to zeroth_year[].***" << endl;

for (unsigned int i=0;i<MAX_NUM;i++)

{
cout << "Key-in population in zeroth_year[" << i << "]=";
cin >> zeroth_year[i];
}
}

///////////////////////////////////////////////////////////////
//Displaying values from the score_array[]

//Precondition: The score_array[] is populated.

//Postcondition: score_array[] values are displayed using printf
///////////////////////////////////////////////////////////////
void Demograph::display_score_array()
{
cout << endl << "You entered the following score_array[] values." << endl;
for (unsigned int i=0;i<MAX_NUM;i++)
for (unsigned int j=0;j<MAX_NUM;j++)
{
cout << "Value of score_array[" << i << "][" << j << "]=";
cout << score_array[i][j] << endl;
}
}

////////////////////////////////////////////////////////////////////////////////////////////////////
//Calculating population

//Precondition: score_array[] and zeroth_year[] are populated.
//The years for which the population size is to be estimated is to set to a 1D array, nth_year[].

//Post condition: Net rate of population growth is calculated and displayed in array, net_rate[].
//Estimated population size for years as said in the array (nth_array) is stored in array, popu_size[].
/////////////////////////////////////////////////////////////////////////////////////////////////////

void Demograph::population_size()
{
int nth_year[5]={10, 20, 30, 40, 50}; //Number of year for which population is to be calculated*
int response;

double net_rate[MAX_NUM]; //net annual growth rate of a region
static double popu_size[MAX_NUM][5];//Final answer is stored here.

cout << endl << "Key in 1 to input the years, for which you want to estimate the population size.";
cout << endl << "Key in 2 to test the data provided in the problem.";
cin >> response;
if (response == 1)
{
cout << endl << "***Third Input: Key in 5 values for the years, you want to estimate" << endl << "the population size.***";
for (int i=0;i<5;i++)
{
cout << endl << "Key in nth_year[" << i << "] = ";
cin >> nth_year[i];
}
}


//Following two "for" loops calulate the net_rate of population growth for each region.
//First "for" loop subtracts the outgoing population
//Second "for" loop adds the incoming population

double temp=0;
double sum=0;

for (int i=0; i<MAX_NUM; i++)
{
for (int j=0; j<MAX_NUM; j++)
{
if (i == j)
temp = score_array[i][j];
else
temp = -score_array[i][j]/100; //Non diagonal values are divided by 100 since they are %

sum += temp;
}
net_rate[i]=sum;
sum=0;
}

for (int j=0; j<MAX_NUM; j++)
{
for (int i=0; i<MAX_NUM; i++)
{
if (i!=j)
{
temp = score_array[i][j]/100; //Non diagonal values are divided by 100 since they are %
net_rate[j] = net_rate[j] + temp;
}
}
printf("net_rate of region[%d] is %f \n\n", j, net_rate[j]);
}
printf("\n**************************************** *************************************\n");
//This "for" loop calulates and displays the population size

try
{
for (i=0; i<MAX_NUM; i++)
{
for (int j=0; j<5; j++)
{
popu_size[i][nth_year[j]] = zeroth_year[i]*pow((net_rate[i]),nth_year[j]); // Population size = zeroth year pouplation * (net_rate)^year
printf("Population of %d %d-th year: %e \n", i, nth_year[j], popu_size[i][nth_year[j]]);
}

}

}
catch(const out_of_range& ex)
{
cout << endl << "out_of_range exception caught" << ex.what();
}

printf("\n0-th region is Urban, 1-th region is Suburban, 2-th region is Exurban");
printf("\n**************************************** *************************************\n");
printf("\nThank you and have a nice day\n");

}
May 30 '07 #1
1 1935
weaknessforcats
9,208 Expert Mod 8TB
I don't get your compiler errors with Visual Studio.NET 2005.

However, the hang at the return of main() is due to an uncaught Win32 exception.

Sorry I can't spend the time to debug the entire thing.
May 30 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: CAFxX | last post by:
i wrote this code that is meant to check if the client browser generates an error when executing the blendtrans statement. unfortunately it's not working as i wished. this page is called check.asp...
1
by: Skavenger | last post by:
Hi, I'm attempting to use a class member function pointer to call a relevant function. This is done like this.... typedef void(SampleA::*SAMPLEAFUNC)(void); class SampleA { public:...
7
by: Abhi | last post by:
Hi all, I am using .net for C++ and I would like to write some variable values to some files. I will be using that file in many member functions of the class. So I declared the file variable...
8
by: swathky | last post by:
I've tried mutiple things but no go -- (sorry this is so long) I'm collecting a 5 digit number in an input box function and all works fine until a number is passed that doesn't exist in the...
8
by: Simon Willison | last post by:
Hi all, I have an API design question. I'm writing a function that can either succeed or fail. Most of the time the code calling the function won't care about the reason for the failure, but...
3
blackstormdragon
by: blackstormdragon | last post by:
I keep getting this error when building my code. error C2064: term does not evaluate to a function taking 1 arguments. #include<iostream> #include<cmath> using namespace std; double...
1
by: prads | last post by:
Hello, I found this waitbar functioning pgm in a forum which does the same work as a matlab waitbar. However this pgm has an error and i cudnot figure it out. Can anyone pls correct it. Thanks,...
1
by: George2 | last post by:
Hello everyone, Here is the code, and if I change line from static wchar_t* p = {PREFIX((wchar_t*)_TEXT("FOO"))}; to static wchar_t* p = {PREFIX(_TEXT("FOO"))};
15
by: Lawrence Krubner | last post by:
Does anything about this script look expensive, in terms of resources or execution time? This script dies after processing about 20 or 25 numbers, yet it leaves no errors in the error logs. This is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.