Alex Edwards 321 Posting Shark

Whip up some code?

Give me a break X_X

You should try putting in some effort, then we might help! =)

Alex Edwards 321 Posting Shark

Eh that's not exactly what I meant. I'm going to write a specific question, please answer if you can, thanks.

Q. Is there a c++ dictionary of inputs I can use?

That is the only question I can think of because I'm so confused about how programming works.

(Note: I can follow along with lessons in books but I never learn anything that I can use to work on my own projects.

There is a Standard Library of predefined classes if that's what you're asking for.

If you're asking for different ways of doing something, you're better off searching MSDN or simply experimenting and finding out the hard way.

http://www.sgi.com/tech/stl/table_of_contents.html (I'm sure you know about this)

http://msdn.microsoft.com/en-us/library/3bstk3k5.aspx (Another kind of reference to C++, with some Microsoft-specific implementations )

http://www.cprogramming.com/reference/ (syntax reference)


As for learning something to use for your own projects, you might be better off studying C++ and then reading a dictionary to understand the terms of things in a human-readable way. Then it might be easier to create programs that are easy to understand and relate to.

Alex Edwards 321 Posting Shark

You should probably sift around on google, and especially wikipedia to answer those questions.

Programming

C Programming Language

Forth

Compiler

-Alex

Alex Edwards 321 Posting Shark

You can take advantage of a Ternary statement by doing a comparison and returning a value based on the condition, all on the same line.

#include <iostream>

using std::cin;
using std::cout;
using std::endl;
using std::flush;

const char* result(bool);

int main(){

   int x = 3;
   int y = 4;
   cout << "Is X < Y ? " << result( (x < y) ) << endl;
   int z = (y < x) ? x : y;
   cout << z << endl;
   cin.ignore();
   cin.get();
   return 0;
}

const char* result(bool condition){
    return (condition) ? "TRUE" : "FALSE"; 
}
Alex Edwards 321 Posting Shark
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

class Student{
    public:
        Student (string = "Mary", double = 100.0, double = 99.0, double = 88.0, int = 1);
        void getInfo();
        void showInfo();
        
    private:
        string name;
        double test1, test2, test3;
        int idNum;
};

Student::Student (string n, double t1, double t2, double t3, int i){
    name = n;
    test1 = t1;
    test2 = t2;
    test3 = t3;
    idNum = i;
}

void Student::getInfo(){
    cout<<"Enter name, three tests grades and ID ";
    cin>>name>>test1>>test2>>test3>>idNum;
}
void Student::showInfo(){
    cout<<fixed<<setprecision(2)<<name<<"\t\t\t"
        <<idNum<<"\t\t\t"<<test1<<"\t\t\t"<<test2
        <<"\t\t\t"<<test3<<"\t\t\t" <<(test1*test2*test3)/3<<endl;
}

int main(){
    Student s1;
    Student s2;
    Student s3;
    s2.getInfo();
    s3.getInfo();
    s1.showInfo();
    s2.showInfo();
    s3.showInfo();
    return 0;
}
Alex Edwards 321 Posting Shark

First of all... when posting something like this, you should be explicit as to what type of errors you're getting. It will help for faster problem analysis and problem solving.

Second, please indent your code so it's easier to follow.

Lastly, it does help to tell us what compiler you're using when you post a question.

class Student{
public:
Student (Mary, 100, 99, 88, 1);
void getInfo();
void showInfo();
private:
string name;
double test1, test2, test3;
int idNum;
};
Student::Student (string n, double t1, double t2, double t3, int i)
{
name = n;
test1 = t1;
test2 = t2;
test3 = t3;
idNum = i;
}

Student::getInfo(){
cout<<"Enter name, three tests grades and ID ";
cin>>name>>test1>>test2>>test3>>idNum;
}
Student::showInfo(){
cout<<fixed<<setprecision(2)<<name<<"\t\t\t"<<idNum<<"\t\t\t"<<test1<<"\t\t\t"<<test2<<"\t\t\t"<<test3<<"\t\t\t" <<(test1*test2*test3)/3<<endl;
}

I can see a few issues with your code.

First of all, in your class Student, why is it that your Constructor prototype in your class definition has values instead of the actual storage types that a Student object should take?

Secondly, what does your definition of your getInfo and showInfo methods return?

Those were obvious problems, but there may be more to this picture than what meets the eye...

Edit: Located another problem, in main--

int main()
{
 Student s1, s2, s3;
s2.getInfo();
s3.getInfo();
s1.showInfo();
s2.showInfo();
s3.showInfo();
 return 0;
}

How can you place Student object on the stack without giving them values first?

You have to give the appropriate arguments to your declared Student objects in main, …

Alex Edwards 321 Posting Shark

http://java.sun.com/javase/6/docs/api/java/math/BigInteger.html

import java.math.BigInteger;

public class TestingBigInteger{


	public static void main(String... args){

		BigInteger first = new BigInteger("50");

		BigInteger second = new BigInteger(first.toString());

		System.out.println(first);
		System.out.println(second);

	}
}

Have fun! =)

Alex Edwards 321 Posting Shark

Is this really a fair comparison?

With C# you are using the CLR to indirectly use your OS and in C++ you are directly using the OS.

If you want this to be a fair comparison, try running the code using the CLR in C++ also.

Alex Edwards 321 Posting Shark

> This should be an easy project

You have seriously got to be joking...

> Also executing packaged-classes might be a bit tricky.

Take a look at how Ant handles such things.

I meant creating the GUI layout would be easy.

It will be hard to create plug-ins for the IDE, but depending on the scope of the assignment plugins can be an optional addition to the IDE.

If its a simple IDE that is dedicated to interfacing with a java compiler and runtime (or even certain components of a JDK) then it shouldn't be too bad.

But this is obviously an assumption. Not enough information of the scope of the assignment is given, and if the scope is bigger than I assumed then I agree that this assignment will not be as easy as I originally thought.

Edit: Actually the OP needs the IDE to interface with a c compiler, not java, though the way it would be done is not too different.

Alex Edwards 321 Posting Shark
int array1[4], array2[4] = {3, 6, 9, 12};
array1 = array2;

and this one:

void showValues (int nums [4][])
{
  for (rows = 0; rows < 4; rows++)
    for (cols = 0; cols < 5; cols++) // is this the line of error? cols is not declared for a size.
        cout << nums[rows][cols];
}

In your first chunk of code, you could omit the 4 from the declaration of array2.

But the real issue is that array2 is a reference variable that cannot hold a variable amount of addresses. It cannot play the role of a pointer.

Although C++ treats arrays as pointers, they are more or less pointer * const types.
For example...

int val[4]; // array declared on the stack - cannot point to another address
int* const val2 = val; // declares a pointer thats contents can be modified but can only point to one address

in your second chunk of code, neither rows nor cols are declared inside your method, but they are assigned and used. I guess this is fine if they are global variables, but it isn't a best practice.

Alex Edwards 321 Posting Shark

This should be an easy project, until you have to create a command for executing an applet instead of a standalone application.

Also executing packaged-classes might be a bit tricky.

It will help if you ran some batch files (or possibly even shells for a UNIX box) to see what it takes to execute a java class file, or compile a .java file into a .class file.

Running from the command line gives similar results, but it may be easier to see mistakes or organize your commands by using the above method.

Once you've figured that out, look up the Runtime API

http://www.javadocexamples.com/java_examples/java/lang/Runtime/


-- some executions by example--

http://www.javadocexamples.com/java/lang/Runtime/exec(String%20command).html


-- a reference for executing applets from the command line--

http://www.cs.colostate.edu/helpdocs/JavaInDOS.html


-- the brute-force method of executing an applet (using main)--

http://www.linuxtopia.org/online_books/programming_books/thinking_in_java/TIJ316_006.htm

BestJewSinceJC commented: Gave all the necessary pieces to make the puzzle. +1
Alex Edwards 321 Posting Shark

SIZE might be a defined macro for something, so try to undefine it--

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

#ifdef SIZE
#undef SIZE
#endif

const SIZE= 101;//0 to 100 set containing 101 elements
// ...

EDIT: Scratch that. You forgot to declare a storage type for SIZE. It's const, but const what?

int?
unsigned int?
double?
etc?


I'd suggest unsigned int since your size will never be negative--

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

const unsigned int SIZE= 101;//0 to 100 set containing 101 elements
// ...

-- some implementations of C++ will allow you to declare an identifier without a storage type in which it will automatically make it an int if there's an assignment. That confused the hell out of me when I used a really old compiler and the Dev IDE when first learning C++.

It's wrong to make something an assumed type. Take better control of your program and be explicit ( yet concise ) about everything possible.

Alex Edwards 321 Posting Shark

Actually, the smarter solution would be to return an iterator of the Queue and traverse through it and get the output of the data inside.

Alex Edwards 321 Posting Shark

Have you tried copying your Queue into a temporary Queue, and printing the data of the temporary Queue instead?

Alex Edwards 321 Posting Shark

This is a post on blackboard from a class-mate of mine--

/**
 * Posted by 'Gregg'
 */

 ptr_practice1.cpp  (3.139 Kb)

When you create a 2 dimensional array on the stack, both the row and column values must be known at compile time, which is why you must use either literals or const variables as array size parameters.  So if you want to make both the rows and columns of an array be allocated dynamically in the heap memory at runtime, there's a couple of ways to go about it. The first is to create a new dynamic1D array like we did in class with scores array, just make the number of elements needed rows * columns:

int maxRows, maxColumns;

Use cin to get the max rows and columns from the user.

int* scores = new int[maxRows * maxColumns];

To access the elements, you can use either array or pointer notation. So to access row 2, column 3 (remember, arrays are 0 based):

whatsAtRow2Col3 = scores[((row -1) * maxColumns) + (column - 1)];

or

whatsAtRow2Col3 =*(scores + ((row - 1) * maxColumns) + (column - 1));

Another way to make multi dimensional arrays is using a concept known as pointer to pointers. Like Ron was saying on thursday, most of think of a 2D array like a spreadsheet with rows and columns (which is just fine), but 'under the hood', C++ is using ptr to ptrs. First, you start off with creating a base pointer. Next, allocate an array of …
Alex Edwards 321 Posting Shark

Java Reference Guide from Informit

Javadocs by example

In regards to the javadoc examples...

Did you remake some of the old API listings with new and improved ones that consist of examples of function usage? O_O

Even if it isn't you... it really must've taken said individual(s) quite some time @_@

Alex Edwards 321 Posting Shark

Here's something I managed to whip up thanks to your logic--

#include <iostream>
#include <string>
#include <vector>

using std::cout;
using std::cin;
using std::endl;
using std::flush;
using std::string;
using std::vector;

bool isPalindrome(const string&);
const char* result(bool);

int main(){

    vector<string> values;

    values.push_back("mom");
    values.push_back("ffaff");
    values.push_back("dad");
    values.push_back("nonPalindrome");
    values.push_back("blah");
    values.push_back("A");
    values.push_back("");

    for(vector<string>::iterator i = values.begin(); i != values.end(); i++)
        cout << (*i) << " is a Palindrome? - " << result(isPalindrome((*i))) << endl;

    cout << "\n\nEnter a word to be determined as a palindrome" << endl;

    values[0].clear();
    cin >> values[0];
    cout << values[0] << " is a Palindrome? - " << result(isPalindrome(values[0])) << endl;

    cin.ignore();
    cin.get();
    return 0;
}

/**
 * Returns true if the argument string is a palindrome, returns false otherwise
 */
bool isPalindrome(const string& arg){

    /*
     * LOGIC:
     *      -If string length is 0 or 1
     *          -string is a palindrome, so return true
     *      -Else
     *          -If first and last indice of said string have the same char
     *              -generate a new string that is a substring of this string
     *               discluding the first and last indice of the previous string
     *          -Else
     *              -return false
     */
    string temp (arg);

    if(temp.length() == 0 || temp.length() == 1)
        return true;
    else{
        if(temp[0] == temp[temp.length() - 1]){
            string next = temp.substr(1, temp.length() - 2); // substring from indice 1 and up to (length() - 2) from 1
                                                             // i.e. - ffaff, f is at [1] and length is 5, so from 1 go up to 2+1
                                                             // because even though length() - …
Alex Edwards 321 Posting Shark

http://www.sscnet.ucla.edu/geog/gessler/borland/strings.htm

Also "LPCTSTR" or "LPTSTR" Looks like 'Long Pointer (const) to String' and 'Long Pointer to String'

Since CreateProcess is defined in windows.h, I'd assume that STR is referring to a char*, or c-style string.

You could create your own custom method for converting an AnsiString into a c_string--

Something along the lines of this--

#include <iostream>
#include <SysUtils.hpp>

using std::cin;
using std::cout;
using std::endl;
using std::flush;
using std::size_t;

const char* extractCString(const AnsiString&);

int main(){

    AnsiString temp ("Testing...");
    const char* myCString = extractCString(temp); // convert temp into a c_string
    delete myCString;
    cin.ignore();
    cin.get();
    return 0;
}

/**
 * Returns a new c_string based on the contents of the AnsiString
 */
const char* extractCString(const AnsiString& arg){

    /*
     * LOGIC:
     *      // Assume arg.Length() is 4, so length is 5
     *      -Dynamically create a new char* that spans length times sizeof(char) bytes in memory
     *      -For length - 1 (4) iterations, with i being our number for iteration, and repeat process while i < (length - 1) (i < 4), and increment i
     *          -Assign data[i] with the value stored in arg[i]
     *      -Assign a null terminator to the last value to make the last byte of the char array contain a null terminator, making it an official c_string
     *      -return the address of the first byte of the array
     */
    size_t length = arg.Length() + 1; // assign arg.Length() + 1 to variable length
    char* data = new char[length]; // assign address of a …
Alex Edwards 321 Posting Shark

This makes me slightly curious...

Why is there assembly code for the string class of C++?

page    ,132
        title   strlen - return the length of a null-terminated string
;***
;strlen.asm - contains strlen() routine
;
;       Copyright (c) Microsoft Corporation. All rights reserved.
;
;Purpose:
;       strlen returns the length of a null-terminated string,
;       not including the null byte itself.
;
;*******************************************************************************

        .xlist
        include cruntime.inc
        .list

page
;***
;strlen - return the length of a null-terminated string
;
;Purpose:
;       Finds the length in bytes of the given string, not including
;       the final null character.
;
;       Algorithm:
;       int strlen (const char * str)
;       {
;           int length = 0;
;
;           while( *str++ )
;                   ++length;
;
;           return( length );
;       }
;
;Entry:
;       const char * str - string whose length is to be computed
;
;Exit:
;       EAX = length of the string "str", exclusive of the final null byte
;
;Uses:
;       EAX, ECX, EDX
;
;Exceptions:
;
;*******************************************************************************

        CODESEG

        public  strlen

strlen  proc \
        buf:ptr byte

        OPTION PROLOGUE:NONE, EPILOGUE:NONE

        .FPO    ( 0, 1, 0, 0, 0, 0 )

string  equ     [esp + 4]

        mov     ecx,string              ; ecx -> string
        test    ecx,3                   ; test if string is aligned on 32 bits
        je      short main_loop

str_misaligned:
        ; simple byte loop until string is aligned
        mov     al,byte ptr [ecx]
        add     ecx,1
        test    al,al
        je      short byte_3
        test    ecx,3
        jne     short str_misaligned

        add     eax,dword ptr 0         ; 5 byte nop to …
Alex Edwards 321 Posting Shark

You should probably change entry's data type from char to int and see if you get better results.

-Alex

Alex Edwards 321 Posting Shark

Note: I'm not near a C++ compiler, but hopefully the below logic will be helpful to you.

Create an interface that has two options for every subclass of its type--

class DoSomething{
 
    public:
        DoSomething(){}
        virtual void option1() const = 0;
        virtual void option2() const = 0;
};

-- then create some subclasses--

class DoNothing : public DoSomething{

    public:
        DoNothing(){}
        virtual void option1() const {}
        virtual void option2() const {}

};

Then change your function to (by default) do nothing if no parameter is given,
or when an appropriate DoSomething object is given it will perform the action--

void YesorNofunc(const DoSomething& action = DoNothing() )
{
    cout << "Are you sure?\n\n"
            << "[1] Yes\n"
            << "[2] No\n\n";
     char YesorNo;
     cin >> YesorNo;
     if(YesorNo == 1)
     {
           action.option1();
     }else if(YesorNo == 2)
     {
           action.option2();
     }else {
         cout << "Invalid; Try Again.";
     }
}

-- hopefully this will give you an idea of what to do to make your method reusable. Have fun =)

Edit: Just got to a compiler, here's a running example--

#include <iostream>

using std::cin;
using std::cout;
using std::endl;
using std::flush;

class DoSomething{
 
    public:
        DoSomething(){}
        virtual void option1() const = 0;
        virtual void option2() const = 0;
};

class DoNothing : public DoSomething{

    public:
        DoNothing(){}
        virtual void option1() const {}
        virtual void option2() const {}

};

class Speak : public DoSomething{

	public:
		Speak(){};
		virtual void option1() const {
			cout << "Whoo! O_O" << endl;
		}

		virtual void option2() const {
			cout << "Oh …
Alex Edwards 321 Posting Shark

I thought I had the specs right until you said down-right instead of up-right in your 2nd paragraph.

Maybe a picture will be helpful?

Also, what are you using to graphically display your program? Is it a Console program or are you using some kind of GUI API? This question is merely out of curiosity.

Alex Edwards 321 Posting Shark

> Don't be shy! Share some information for my Survey! %_%

OK, here is an interesting fact for your survey; I don't have a credit card. :-)

Gah >_<

Looks like the polls need to include an "I don't own a Credit Card" option >_<

Alex Edwards 321 Posting Shark

Hey I know plenty of other people use the Geek's Lounge! XD

Don't be shy! Share some information for my Survey! %_%

I'm hoping to merge this with my offline Survey. I managed to get a response from 30 people (mostly classmates but I'm hoping for more people >_< ).

Alex Edwards 321 Posting Shark

To the above posters--

Not everyone is a prodigy XD

-- =P

Alex Edwards 321 Posting Shark

A lot of complicated terminology being thrown around here but a few points:

> A static member of a class is a shared location in memory between objects of that class.

Don't mix concepts and implementation details when explaining. From the JLS:


> static values are resolved at compile time, before objects are created.

A compile time constant expression when assigned to a static field[or not] is evaluated at compile time; a static field is incarnated when the class is initialized. There is no *static value*.

> Notice that in main of a different class file, I didn't need to create an object of MyClass in
> order to access sharedInt - the address of the reference-variable sharedInt is resolved at
> Compile Time and all MyClass objects have access to it.

`sharedInt' is a variable of Primitive Type and not Reference Type.

> If q is not a static member, then although each C class object has q, they have their own
> individual address for their reference variable and therefore

Each instance created has its own set of the state/member variables. There is no *individual address for their reference variables*.

> to access q you need to give a hint to the compiler (or runtime) of which particular C
> object you want to qualify q with to access the appropriate value of q for whatever
> purpose you need to access it for

There is no *hinting* or *forcing*; the …

Alex Edwards 321 Posting Shark

Ok, I got the Size function working.

I changed the code a bit, after reading through your logic some.

The problem was in Size, where you attempted to initialize countPtr to be the rear and compare it to the front.

You're traversing from the low end of the list and further towards lower parts without ascending upwards, so the loop is infinite and will never reach frontPtr.


Here are the changes I made--

#ifndef TEMPLATEQ_H

#define TEMPLATEQ_H

#include <iostream>
#include <new>
#include <cstddef>

using namespace std;

class FullTemplateQ								// Exception class
{};  


class EmptyTemplateQ								// Exception class
{};  


template<class SomeType>	   				// Node template class
struct QueueNode
{
  SomeType  data;									// Data stored in queue node

  QueueNode<SomeType>*  nextPtr;				// Pointer to next queue node
};


template<class SomeType>	   				// Circular queue template class
class TemplateQ
{
  private:
    QueueNode<SomeType>*  rearPtr;			// Pointer to rear of queue

	QueueNode<SomeType>*  frontPtr;			// Pointer to front of queue

    void PrintNext(QueueNode<SomeType>* tempPtr) const; // Print trailing items
	
  public:
	TemplateQ();									// Default constructor

	~TemplateQ();									// Destructor deallocates every node

	void Enqueue(SomeType newData);			// Adds newdata node to rear of queue

	SomeType Dequeue();							// Removes data node from front of queue,
                                          // returning the stored data

	bool IsFull() const;							// Returns true if queue is full, 
                                          // false otherwise

	bool IsEmpty() const;						// Returns true if queue is empty, 
                                          // false otherwise

	int Size() const;								// Returns the number of items in queue

    void ForwardPrint() const;             // Prints queue, front to rear

    void …
Alex Edwards 321 Posting Shark

I ran the program (unchanged from the original) in MS Visual C++ 2008 and I got a run-time error where countPtr is being used when it hasn't been initialized.

Try initializing it to null and see if that removes your run-time warning. I'll keep investigating with debug on to see what else I can sift out.

Edit: Ok now I see why you are assigning countPtr to be rearPtr then assigning countPtr to be countPtr->nextPtr

It's because you want to give countPtr a valid address before calling countPtr->rearPtr.

Alex Edwards 321 Posting Shark

the variable q is not declared in the class A and I dont want to declare it. Is there anyway this can be done? I tried that and it says "non-static variable cannot be referenced from a static context" If also someone could share with me what this means. Thanks alot

static values are resolved at compile time, before objects are created.

A static member of a class is a shared location in memory between objects of that class.

Because static values are resolved at compile time before an object is created, and all objects of the class share the value, you have the right [with the appropriate access modifier] to access that shared address between objects of the class without needing an actual object to qualify the member to access the member.

For example...

public class MyClass{
    static int sharedInt = 0; // package accessible for enclosing classes of MyClass
}
public class Main{

    public static void main(String... args){

        System.out.println(MyClass.sharedInt); // legal if class MyClass and Main are in the same package 

    }
}

Notice that in main of a different class file, I didn't need to create an object of MyClass in order to access sharedInt - the address of the reference-variable sharedInt is resolved at Compile Time and all MyClass objects have access to it.

When you call C.q the compiler is forced to believe q is a static member in class C, but if it does not see the static …

Alex Edwards 321 Posting Shark
template<class SomeType>
void TemplateQ<SomeType>::Enqueue(SomeType newData)
{
	if (IsFull())
		throw FullTemplateQ();
	else if(IsEmpty())
	{
		QueueNode<SomeType>* nextQueueLocation;

		nextQueueLocation = new QueueNode<SomeType>;
		nextQueueLocation->data = newData;
		nextQueueLocation->nextPtr = NULL;
		if(rearPtr == NULL)
			frontPtr = nextQueueLocation;
		else
			rearPtr->nextPtr = nextQueueLocation;
		rearPtr = nextQueueLocation;
	}
}

I'm not quite sure how you want your implementation of a queue to work but...

You only Enque if the list is either empty or full, so after the first Enque the list is no longer empty and unless you're working in a very small heap, or some exception occurs, the IsFull method will return false, so successive calls to Enque will simply do nothing.

One value is stored in your queue and when you call Size I suppose the segmentation fault is caused because you're attempting to indirectly call rearPtr->next when rearPtr points to NULL and the address that its pointing to doesn't belong to your program so an exception occurs and it shuts down.

You need to add another case in your Enque so that when you call it, it can add an element even if its not empty or not full.

Also it might help to code more defensively to prevent a segmentation fault from occurring.

Edit: This statement is confusing--

while(countPtr != frontPtr)
	{
		countPtr = rearPtr->nextPtr; // why is this needed if you're going to reassign countPtr?
		countPtr = countPtr->nextPtr;
		numberOfChars ++;
	}
	return numberOfChars;
Alex Edwards 321 Posting Shark

Since i'm new on programming java:

(1) i need a compiler so i could learn how to program in java applet

Since in our group choose java applet to make an online game (that includes client + server) for our course project so:

(2) i need the right software to support our project

am confused with all the software or compilers to use such as Eclipse and JDK 6 so me and my group need help

you mean IDE = compiles + run :S ??? whats the difference between JDK 6 and Eclipse???

An IDE is just an integrated development environment. Some IDE's come with a compiler, but they aren't really compilers. Eclipse simply uses a javac and JRE supplied by a JDK.

You can compile Java programs without Eclipse. People typically use TextPad (5 and higher) but its also possible to use a java compiler (javac.exe) from the command line.

Since javac (the Java compiler) is an executable, it can take parameters. It takes a file name as a parameter then compiles that file. If the file does not have valid data in it to be compiled, the compiler will throw errors and it will not generate a .class file.

If you can compile a program successfully, a .class file is generated which can be run on any JRE provided the appropriate JRE is installed for the appropriate Operating System.

Alex Edwards 321 Posting Shark

How many of you carry your Credit card on you when you walk out the door?

(It's a survey I have to do for a class %_%)

I'm also going to do an offline survey, but the online survey is just as important! =)

-Alex

Alex Edwards 321 Posting Shark

Templated classes denote incomplete types and you can specialize a particular case to have a completely different definition than the general case.

What's the guarantee that long double isn't a specialized case in the vector class that doesn't have an inner iterator class?

I'm not sure when it is resolved (most likely at compile time) but when typename is used, like Narue stated you are telling the compiler it is a type that exists within the case of vector<long double>.

Alex Edwards 321 Posting Shark

SOLUTION:
TWO files: myClass.h main.cpp

//
// myClass.h

#ifndef MYCLASS_H_
#define MYCLASS_H_

template <class element_type>
class myClass
{
public:
	myClass();

	~myClass();
};

template <class element_type>
myClass<element_type>::myClass()
{

}


template <class element_type>
myClass<element_type>::~myClass()
{

}

#endif /* MYCLASS_H_ */
//
// main.cpp


#include "myClass.h"

int main()
{
	myClass<int> classOBJ;


	return 0;
}

That's one way of doing it, but you could also use eager-inclusion.

// file.h
#ifndef MYHEADER_H
#define MYHEADER_H

/*Declaractions*/
#include "file.cpp"

#endif
// file.cpp
#ifdef MYHEADER_H


#endif
#include "file.h"

int main(){

   return 0;
}

And also instead of eager inclusion you can simply add the .cpp file later in the driver file, and include the header file in the driver file.

chococrack commented: Good point! +1
Alex Edwards 321 Posting Shark

It may be possible that Java won't support an image-type in future releases and therefore not provide Serialization support for it but that depends on what it is.

I remember getting warning pertaining to images of a specific class and that class might be the culprit but I can't completely confirm this @_@. It's just a possibility >_<

-Alex

Alex Edwards 321 Posting Shark

Programming is my passion =)

I want to die typing at the keyboard trying to solve problems and improve my ability of insight =)

I want my life to be absorbed by programming, because I used to write stories and also had a knack for mathematical problems. I tried putting both together and ended up making un-imaginative scripts of people yelling at each other because someones numbers weren't accurate enough @_@

Yes I know its lame >_<

Hopefully I'll become a good programmer some day, but I'd like to expand my imagination at the same time so I can produce my own kind of art through programming =)

-Alex

Ancient Dragon commented: I think you need to get a life and a gf :) +36
scru commented: It's not just lame. It's mega-lame. +4
Alex Edwards 321 Posting Shark

Since it's too late to edit, I'll post what I think is a solution to your problem though I might be a bit off.

// Account.h

#ifndef ACCOUNT_H
#define ACCOUNT_H
/*
***********************************************
*	Creating class prototypes, and declaring  *
*	functions.								  *
***********************************************
*/

/*
***********************************************
*		 Class Declaration and Definition	  *
***********************************************
*/
class Account{
	//Declaring class member variable
	char customer[251];			//251 including null byte
	char accountNumber[16];		//16 including null byte
	int balance;
	void _init();
	/*
	***********************************************
	*	  Function Declaration and Definition	  *
	***********************************************
	*/
	public:
		Account();								//Default Constructor 
		Account(char c[], char num[], int b);	//Constructor with 3 arguments
		~Account();
		void init(char c[], char num[], int b);
		int changeCustomerInfo(char c[]);
		void changeAccountNumber(char num[]);
		void changeBalance(int b); 
		void getLastName(char st[]);   
		void getFirstName(char st[]); 
		void getCity(char st[]);
		void getPhoneNumber(char st[]);
		const char* getCustomer() const; // returns const char*, no arguments
		const char* getAccountNumber() const; // returns const char*, no arguments
		const char* (Account::*cus_ptmf)() const; // ptr to Account member function that returns const char* and accepts 0 args
		const char* (Account::*acc_ptmf)() const; // ptr to Account member function that returns const char* and accepts 0 args
		int getBalance() const; 
};

#include "Account.cpp"

#endif
// Account.cpp

#ifdef ACCOUNT_H

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

Account::Account(){
	_init();
}

Account::~Account(){}

void Account::_init(){

	cus_ptmf = &Account::getCustomer;
	acc_ptmf = &Account::getAccountNumber;

}


//declaring char* getCustomer()
const char* Account::getCustomer() const{
	cout << "getCustomer() method called O_O!" << endl;
	return customer;
}



//declaring char* getAccountNumber()
const char* Account::getAccountNumber() const{
	cout << "getAccountNumber() method called $_$!" …
Alex Edwards 321 Posting Shark

Whoops, my last post was pretty retarded.

I think I see the issue now.

Your header file and implementation file aren't speaking the same language.

You have to modify your header file such that your function declares a ptmf that returns a const char and accepts zero arguments.

Since it is a ptr, you shouldn't try to initialize it outside of the scope of the class, but during preinitialization before the an object of type Account is even created.

Alex Edwards 321 Posting Shark

Disregard this post.

Alex Edwards 321 Posting Shark

Umm, your code?

Exactly my thoughts.

From what I understand, malloc can fail if you've run out of heap-space your program is using for dynamic allocation or if you are attempting to allocate memory to a location that is in use by another process. size=2097152 Your heap should be (by default) 512 MB, which is (depending on how "Mega" and "Kilo" are interpreted) 1024 * 512 Kilobytes and 1024 * 1024 * 512 bytes.

So you should have enough space (by default, not saying this isn't expandable), but the question is what object (or hopefully struct) are you trying to allocate memory for using a C-style mem allocator? I believe some structures have a limit on the amount of memory they can hold, but a professional would have to confirm that.

Alex Edwards 321 Posting Shark

Well I read both the links and have a better idea about them.

Iv updated my code as well but I get an error which basically says that it can't find the prototype or the variable being returned.

const char Account::*getData() const{
	return data;
}

Post all of your code please so we can investigate the issue @_@

Alex Edwards 321 Posting Shark

Warning! O_O

Delete does not really delete!

Delete frees dynamically-requested memory that the C++ program obtained from the OS at run-time.

Delete does NOT actually delete anything! Do not use it freely, unless you really want to screw up your program or cause your OS to flag an error to whatever program attempted to tell the OS to unallocate memory that never belonged to the provoking application to begin with @_@.

Alex Edwards 321 Posting Shark

In otherwords there isn't a way to easily make your own character in C++

That seems like the truth!

Especially since C++ is just a tool that interfaces with other systems, I suppose there's no direct way c++ itself could create a character the system would recognize! It would probably have to be the other way around (make some kind of program that the OS can use to map numbers to additional characters then make a C++ implementation that makes the mapping easier?).

It's just a theory, but that's the way I'd assume it would work out.

Alex Edwards 321 Posting Shark

Ive been looking for the right compiler that i can use with java applet to create an online game so does any one know the best compiler for java applet? and where i can find it in a free download from a website? or a list of compilers that i can find free downloads??.

Note: Since its a course project so i have to choose the right compiler carefully so i won't change it after if i face an error cause i heard some compilers like Eclipes gives limitation on java applet.

Can some one help me?

Are you sure you mean compiler and not runtime, or potentially a JDK that supports a compliant version of both?

Are you seeking some "limitations" for your project? O_O

Your question grants a curious eye. I believe you're referring to the run-time, but to solve both problems you can go to Sun's website and download a stable JDK that provides both a JRE and updated javac.

I strongly suggest SE 6.0 (supplies the JDK 6.0).

http://java.sun.com/javase/downloads/index.jsp

Alex Edwards 321 Posting Shark

That is not it. I want A to be able to use a method in B..Is that possible

I think Object creation might shed some light on this issue...

If you create an Object of type A, A is at least of its class and additionally any other class it inherits from.

A cannot, at runtime, extend its static capabilities. Inheritance is resolved at compile time, so when A is defined and its super classes are known, objects of type A will not be able to do magical things like call methods (within the scope of A) that exist in a subclass that A isn't even aware of.

B on the other hand is at least of type B and additionally any other class it inherits from. B inherits from A so B can call methods that exist within the A class it is derived from.

If you want dynamic behavior where A can call B-like methods, you shouldn't rely on inheritance to do the trick and instead use a Pattern to solve the problem--

public class BaseClass{

	public void doSomething(){
		System.out.println("Do Something! O_O");
	}

}
public class DerivedClass extends BaseClass{

	public void moreWorkToDo(){
		System.out.println("Whoo! More work >_<");
	}

}
public class ModularClass extends BaseClass{

	public BaseClass myDynamicA = new BaseClass();

	@Override public void doSomething(){
		myDynamicA.doSomething();
	}

	public void setRef(BaseClass theRef){
		myDynamicA = theRef;
	}

	// I know this is sloppy, but it is an effective panacea for the situation
	public void callDerivedMethod(){ …
Alex Edwards 321 Posting Shark
// ...

		System.out.println(" Beverage				Number of Votes			Percentage");
		System.out.println("-------------------------------------------------------------------------------------");
		System.out.println();
		System.out.println("Coffee                	"+choice1+ "			    "+perc1);
		System.out.println("Tea								"+choice2+"					 "+perc2);
		System.out.println("Orange Juice 				"+choice3+"					 "+perc3);
		System.out.println("Lemonade						"+choice4+"					 "+perc4);

Use tabs instead of trying to space things out and match them up manually =/

Alex Edwards 321 Posting Shark

i didn't ask anyone to do the whole thing .. wat i wanted is if anyone had sth similar to wat i need he/she cld share with me so i cld have an idea abt it ... cuz i already started working on it and i got stuck in some parst

mr. Salem
just for ur info .. yeah it is right that i have to submit it by 2day but the doctor extended the subbmission for tmw :) thank u for being polite .. i guess i made a mistake by joining this forum !

Lighten up daddio! O_O

What Salem is saying is that you should literally show us your script! Show us what you've written so we can help you.

Geeze, it's not like we're going to steal your assignment X_X

-Alex

Alex Edwards 321 Posting Shark

An idea? Use JDBC to store book information then retrieve it later.

Files are ok, but it might be easier to query necessary information than try to make a dozen different methods for obtaining books in certain order, or certain books period.

Alex Edwards 321 Posting Shark

I believe your Instructor is looking for you to do the following--

// templateq.h

#ifndef TEMPLATEQ_H

#define TEMPLATEQ_H

#include <iostream>
#include <new>
#include <cstddef>

using namespace std;

class FullTemplateQ								// Exception class
{};  


class EmptyTemplateQ								// Exception class
{};  


template<class SomeType>	   				// Node template class
struct QueueNode
{
  SomeType  data;									// Data stored in queue node

  QueueNode<SomeType>*  nextPtr;				// Pointer to next queue node
};


template<class SomeType>	   				// Circular queue template class
class TemplateQ
{
  private:
    QueueNode<SomeType>*  rearPtr;			// Pointer to rear of queue

	QueueNode<SomeType>*  frontPtr;			// Pointer to front of queue

    void PrintNext(QueueNode<SomeType>* tempPtr) const; // Print trailing items
	
  public:
	TemplateQ();									// Default constructor

	~TemplateQ();									// Destructor deallocates every node

	void Enqueue(SomeType newData);			// Adds newdata node to rear of queue

	SomeType Dequeue();							// Removes data node from front of queue,
                                          // returning the stored data

	bool IsFull() const;							// Returns true if queue is full, 
                                          // false otherwise

	bool IsEmpty() const;						// Returns true if queue is empty, 
                                          // false otherwise

	int Size() const;								// Returns the number of items in queue

    void ForwardPrint() const;             // Prints queue, front to rear

    void ReversePrint() const;             // Prints queue, rear to front
};

#include "templateq.cpp"					// Very Important!!  Do not delete!!

#endif
//templateq.cpp

#ifdef TEMPLATEQ_H

TEMPLATEQ_H

#include <iostream>


template <class someType>
TemplateQ<someType>::TemplateQ()
{
    rearPtr = NULL;
    frontPtr = NULL;
	cout << "Instantiation successful!" << endl; 
}

template <class someType>
TemplateQ<someType>::~TemplateQ(){
	cout << "Destruction successful!" << endl;
}

#endif
// driver program

#include "templateq.h"
#include <iostream>

using std::cin; …
Alex Edwards 321 Posting Shark

according to my instructions #include "template.h" is not supposed to be there.

I'm not sure how you plan on defining the TemplateQ class without implementing the file with the prototype constructor, destructor and methods.

It's like trying to define something out of nothing.

The script you're working in has to have some knowledge of what it is defining.

The statement--

template <class someType>
TemplateQ<someType>::TemplateQ()
{
    rearPtr = NULL;
    frontPtr = NULL;
}

--is equivalent to saying I want to define the default constructor of the class TemplateQ<someType>, but how do you plan on doing that without giving the compiler a hint on the types declared in the class or what the class consists of?

You only include the headers new and cstddef, but not templateq.h

So let me ask you this. If you weren't instructed to add stdio or iostream or some other header that allows you to print to the Console but code is present that clearly shows that you should be implementing a header to allow you to do so, would you be reluctant to add that header?