Click here to Skip to main content
15,923,273 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Arrays Pin
David Crow25-Apr-06 6:22
David Crow25-Apr-06 6:22 
AnswerRe: Arrays Pin
David Crow25-Apr-06 6:08
David Crow25-Apr-06 6:08 
QuestionWhy is this C++ Exception unhandled ? Pin
Defenestration25-Apr-06 5:55
Defenestration25-Apr-06 5:55 
AnswerRe: Why is this C++ Exception unhandled ? Pin
includeh1025-Apr-06 6:50
includeh1025-Apr-06 6:50 
AnswerRe: Why is this C++ Exception unhandled ? Pin
Stephen Hewitt25-Apr-06 13:44
Stephen Hewitt25-Apr-06 13:44 
GeneralRe: Why is this C++ Exception unhandled ? Pin
Defenestration25-Apr-06 15:41
Defenestration25-Apr-06 15:41 
Questionvalidating user/pass inputs Pin
Kharfax25-Apr-06 5:35
Kharfax25-Apr-06 5:35 
QuestionProject for class Pin
JarethAshaer25-Apr-06 5:25
JarethAshaer25-Apr-06 5:25 
Doing a random project for school. blah. Been fighting with it and I'm sure I'm missing some little problem and my buddies who usually read over my code for me are out of town for the week. Yay for procrastination! Anyway, if anyone can spare 5 minutes to look it over. It's about 90% done, couple bools need to be made useful, but I need to figure out the following errors :
error C2228: left of '.append' must have class/struct/union type line 25
error C2228: left of '.chop' must have class/struct/union type line 35
error C2228: left of '.print' must have class/struct/union type line 45

Main file
#include <iostream>
#include "class.h"

using namespace std;
void main ()
{
int n;
int elem;
int pointedArray[10];
int *array = 0;
bool completion = false;
elem = 10;
for (n = 0; n < elem; n++)
{
cout << "Enter value for element " << n+1 << " of the array : ";
cin >> pointedArray[n];
}
array = &pointedArray[0];
Array ar1 (int array[], int elem);
completion = ar1.append();
if (completion == true)
{
cout << "Append successful!" << endl;
}
else
{
cout << "Append Unsuccessful!!" << endl;
}
completion = false;
completion = ar1.chop();
if (completion == true)
{
cout << "Chop successful!" << endl;
}
else
{
cout << "Chop Unsuccessful!!" << endl;
}
completion = false;
completion = ar1.print();
if (completion == true)
{
cout << "Print successful!" << endl;
}
else
{
cout << "Print Unsuccessful!!" << endl;
}
completion = false;
system ("pause");
}

Header File
#include <iostream>
using namespace std;
int i;
class Array
{
private:
int element;
int *pArray;
bool extend();
bool contract();
public:
Array ( );
Array (int array[]);
Array (int elem);
Array (int array[], int elem);
~Array () {}
bool append();
bool chop();
bool print();
bool success;
};
/* Default Constructor
-Pre none
-Post *pArray set to 0
*/
Array :: Array ( )
{
pArray = 0;
}

/* Secondary Constructor
Initializes pointer to input
-Pre *array set to a value
-Post *pArray set to *array
*/
Array::Array (int array[])
{
pArray = &array[0];
}

/* Secondary Constructor
Sets element to elem
-Pre elem set to a value
-Post *pArray initialized to zero and element set to elem
*/
Array::Array (int elem)
{
pArray = 0;
element = elem;
}

/* Secondary Constructor
Sets element to elem and *Array to *array
-Pre elem and *array set to values
-Post *pArray set to *array and element set to elem
*/
Array::Array (int array[], int elem)
{
pArray = &array[0];
element = elem;
}

bool Array :: append()
{
success = extend();
cout << "Please input new element value: ";
cin >> pArray[10];
return (true);
}
bool Array:: extend()
{
int temp[11];
for(i = 0; i < (element); i++)
{
pArray[i] = temp[i];
}
pArray = &temp[0];
return (true);
}
bool Array :: chop()
{
success = contract();
return (true);
}
bool Array:: contract()
{
int temp2[9];
for(i = 0; i < (9); i++)
{
pArray[i] = temp2[i];
}
element -= 1;
pArray = &temp2[0];
return (true);
}
bool Array :: print()
{
for (i = 0; i < element; i++)
{
cout << "The value of element " << i << " is " << pArray[i] << endl;
}
return (true);
}

With modifications per request

-- modified at 12:33 Tuesday 25th April, 2006


AnswerRe: Project for class Pin
David Crow25-Apr-06 6:21
David Crow25-Apr-06 6:21 
AnswerRe: Project for class Pin
Bob Flynn25-Apr-06 6:48
Bob Flynn25-Apr-06 6:48 
GeneralRe: Project for class Pin
JarethAshaer25-Apr-06 7:15
JarethAshaer25-Apr-06 7:15 
GeneralRe: Project for class Pin
Bob Flynn25-Apr-06 7:23
Bob Flynn25-Apr-06 7:23 
GeneralRe: Project for class Pin
JarethAshaer25-Apr-06 7:27
JarethAshaer25-Apr-06 7:27 
GeneralRe: Project for class Pin
Bob Flynn25-Apr-06 7:40
Bob Flynn25-Apr-06 7:40 
GeneralRe: Project for class Pin
JarethAshaer25-Apr-06 7:52
JarethAshaer25-Apr-06 7:52 
Questionwhat are the differences between .dll and .lib file?eg. gdi32.dll and gdi32.lib Pin
rotorcli25-Apr-06 5:12
rotorcli25-Apr-06 5:12 
AnswerRe: what are the differences between .dll and .lib file?eg. gdi32.dll and gdi32.lib Pin
Chris Losinger25-Apr-06 5:16
professionalChris Losinger25-Apr-06 5:16 
GeneralRe: what are the differences between .dll and .lib file?eg. gdi32.dll and gdi32.lib Pin
rotorcli25-Apr-06 5:46
rotorcli25-Apr-06 5:46 
GeneralRe: what are the differences between .dll and .lib file?eg. gdi32.dll and gdi32.lib Pin
Chris Losinger25-Apr-06 6:16
professionalChris Losinger25-Apr-06 6:16 
GeneralRe: what are the differences between .dll and .lib file?eg. gdi32.dll and gdi32.lib Pin
rotorcli25-Apr-06 6:27
rotorcli25-Apr-06 6:27 
QuestionProblem compiling with VC++ 2005 Pin
Defenestration25-Apr-06 5:06
Defenestration25-Apr-06 5:06 
AnswerRe: Problem compiling with VC++ 2005 Pin
Cedric Moonen25-Apr-06 5:10
Cedric Moonen25-Apr-06 5:10 
GeneralRe: Problem compiling with VC++ 2005 Pin
Defenestration25-Apr-06 5:21
Defenestration25-Apr-06 5:21 
GeneralRe: Problem compiling with VC++ 2005 Pin
Defenestration25-Apr-06 5:26
Defenestration25-Apr-06 5:26 
QuestionAFX_INCLUDE() Pin
longdt925-Apr-06 3:54
longdt925-Apr-06 3:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.