436 Posted Topics
Re: [QUOTE]cannot convert parameter 2 from 'LPDIRECTSOUND8' to 'LPDIRECTSOUND8 *'[/QUOTE] This probably means that parameter 2 is an output parameter and needs to be a pointer: [code=cplusplus] HRESULT hr = DirectSoundCreate8(NULL, &ppDS8, NULL); [/code] I do not know much about the DirectSound API, so that is the best I can help … | |
Re: You know how to use 1D arrays, right? 2D arrays are 1D arrays where every item is an array. C has arrays of arrays instead of true multidimensional arrays: [code] int a[5] = {1,2,3,4,5}; [0] -> [1][2][3][4][5] int b[3][2] = { {1, 2}, {3, 4}, {5, 6} }; [0] -> … | |
Re: Your class only allows one name, you need to define an array of 3 names and then use it as an array in the methods: [code=cplusplus] class A { int a[3]; char name[3][20]; public: void read(); void display(); }; void A::read() { cout<<"enter rno name"; for(int i=0;i<3;i++) { cin>>a[i]; cin>>name[i]; … | |
Re: Your inner loop does not account for the name being accepted and there is no way to break out of it without somehow signaling a character that has a value of 0. This will work better: [code=cplusplus] while (!name_accepted && cin.get(ch)) [/code] Otherwise the code works fine. | |
Re: [QUOTE]I need to know how to calculate the standard deviation?[/QUOTE] Do you know what the standard deviation is and how to calculate it on paper? The standard deviation of a set shows how the items in the set are dispersed. If the standard deviation is low, the items tend toward … | |
Re: [QUOTE]I need to display Example 23.4 and display 23 and .4[/QUOTE] One easy way is with the type system. When you cast a floating point value it cuts off the precision. If you subtract that result from the original, you get the precision: [code=c] double d = 23.4; double w … | |
Re: [QUOTE]Could I suppose this is the rules of c++?[/QUOTE] Yes. The methods of a class can see everything in the class regardless of the access level. That is because a class can always see its own privatemost stuff. This is all at the class level, not the object level. When … | |
Re: That error means those are either functions or objects that have been declared but not defined. A common cause is forgetting to give a body to one of your functions: [code=cplusplus] void function(); int main() { function(); // error! } [/code] Another is including the headers for a library but … | |
Re: Can you explain your design? A Frame is an Mp3, but an Mp3 has a list of Frames, so an Mp3 has a list of Mp3s? Why does Frame need to inherit from Mp3? That does not make sense to me, but I admit that I only know enough about … | |
Re: [QUOTE]File:f:\dd\vctools\crt_bld\self_x86\crt\src\[B]fgetc[/B].c Expression: ([B]stream !=NULL[/B])[/QUOTE] This is an easy one. The stream you passed to fgetc is NULL. It means fopen returned NULL because the file could not be opened for some reason. Check the result before using it: [code=cplusplus] FILE* fp = fopen(file, mode); if (!fp) { perror("fopen"); exit(EXIT_FAILURE); } … | |
Re: You do not need to pair isupper and tolower. If the character passed to tolower does not have a lower case equivalent then the same character will be returned: [code=cplusplus] #include <iostream> #include <string> #include <cctype> int main() { using namespace std; string input; cout << "Enter a word: "; … | |
Re: Opening curly braces need to be matched with closing curly braces. The braces keep the stuff inside from falling out and choking the compiler. :D [code=cplusplus] // class definition class MyClass { public: // public stuff private: // private stuff }; // close the definition [/code] [code=cplusplus] // method/function definition … | |
Re: Static methods are called like this: [code=cplusplus] UIClass::GetStatic( IDC_OUTPUT )->SetText( wszOutput ); [/code] Replace UIClass with the name of the class for g_SampleUI. | |
![]() | Re: This is a pretty rough hierarchy. There is still one ambiguity because you do not virtually inherit B in D and F, so there will be two instances of B in H. If you fix that, then H will have one copy of each class all the way up to … ![]() |
Re: [QUOTE]1) to get the range of elements such as .. A list of 10 elements beginning from value 1 to 10. I would like to get the range from element 3 to element 5 and add them to another list. Is it possible?[/QUOTE] Yes, it is possible. A list is … | |
Re: [QUOTE]Is not Turbo C a nd Turbo C++ very outdated?[/QUOTE] Yes, but so is DOS. He wants to write code for DOS 6.x, so Turbo C++ is not as bad a choice as it would be if he were targeting a modern OS. | |
Re: To cut from the right, you can take a substring of a smaller length: [code=csharp] string q = s.Substring(0, s.Length - 2) + somethingElse; // replace "mv" with something else [/code] | |
Re: Array variables are converted to pointers for value operations. You do not need to do anything special if you already have a pointer. The syntax is basically the same as with an array variable except you have more options with pointer arithmetic: [code=c] #include <stdio.h> int main() { int a[] … | |
Re: The errors are telling you that Turbo C++ is almost 20 years old and it is time to move to a newer compiler that does not need a DOS emulator to run your programs in 16 bit mode. ;) Really, there is no point in learning to do graphics with … | |
Re: [QUOTE]So I have two functions, both which have the same name, but based on the TYPE of the parameter passed do two separate things[/QUOTE] You described function [URL="http://en.wikipedia.org/wiki/Method_overloading"]overloading[/URL], not [URL="http://en.wikipedia.org/wiki/Method_overriding_%28programming%29"]overriding[/URL]. Overriding is replacing the implementation of a method with a specialized implementation in a derived class. | |
Re: Not without doing some kind of explicit mapping: [code=cplusplus] #include <iostream> #include <string> enum Color {Red, Blue, Green}; static std::string ToString(Color color) { switch (color) { case Red: return "Red"; case Blue: return "Blue"; case Green: return "Green"; default: return ""; } } int main() { Color color = Red; … | |
Re: Two instances of undefined behavior, three if your compiler does not support void main. [LIST=1] [*]The i variable is uninitialized. Anything could be in that memory space, and you are not allowed even to read it. [*]A sequence point is only guaranteed after all of the function arguments are evaluated. … | |
Re: You can use any sorting algorithm with the right comparison: [code=c] #include <stdio.h> #include <stdlib.h> int compare(void* const a, void* const b) { int const ia = *(int const*)a; int const ib = *(int const*)b; return (abs(ia) % 2) - (abs(ib) % 2); } int main() { int a[] = … | |
Re: There probably will not be a definition of [ICODE]a[/ICODE] like that. If the variable is local, it will probably be defined as an offset on the stack. Look for changes to esp and ebp: [code=c] void Function() { int a; [/code] Might look like this for whatever flavor of assembly … | |
![]() | Re: [QUOTE][CODE]char info; [/CODE][/QUOTE] info is not a string, it is a single char. That explains why you only get the first character of the surname. Change info to an array of 255 like the surname array in the user structure, or change the type to an object of the user … |
Re: If you want to manually refactor, I like to start with a simple function call and cut the code into a new function with that name: [code=cplusplus] void BottomTurn() { a = front[6]; b = front[7]; c = front[8]; front[6] = left[0]; front[7] = left[3]; front[8] = left[6]; left[0] = … | |
Re: [QUOTE]Or loop through the string and check if any char is between the acsii value's of '0' and '9'.[/QUOTE] Or just compare against '0' and '9' because the values have to be contiguous and using the underlying values means your code is tied to ASCII and any other character sets … | |
Re: Your function generates a random number in the range of [0..RAND_MAX), not in the range of [1..5). The easiest trick for fixing the range is the remainder operator: [code=cplusplus] i = rand() % 4 + 1; [/code] The remainder of division from RAND_MAX by 4 will always result in a … | |
Re: I think a property is better because the method has extra syntax that is not needed. But they both do the same thing and are close enough that you should pick the one you like better. [QUOTE]Suppose I want to derive from a Square class, call it a SuperSquare class, … | |
Re: Read them the same way you read ASCII files, but you need to convert each character to the right character set once you read it or any output will be jumbled. There are conversion charts all over the web, and the process is simple. [URL="http://www.simotime.com/asc2ebc1.htm"]Here[/URL] is one of those charts. | |
Re: [QUOTE]It's not because you quickly want to test out some code that you may use bad coding styles. Bad coding styles are considered: bad, so you don't have to use them, under any circumstances.[/QUOTE] That rationalization might work when you preach to the choir, but everyone else needs a better … | |
Re: Please do not roll your own encryption code. It's fine for a homework exercise but anyone who uses that kind of thing in a real application needs to be shot. ;) At the very least, if you do not care about how strong the encryption is, use the libraries offered … | |
Re: fscanf can read 2 digit hex numbers: [code=c] #include <stdio.h> int main() { unsigned char binary[16] = {0}; unsigned int hex; int x, y; for (x = 0; x < 16 && fscanf(stdin, "%2x", &hex) == 1; ++x) binary[x] = (unsigned char)hex; for (y = 0; y < x; ++y) … | |
Re: [QUOTE]Can someone suggest me some way to increase my interest in C by giving examples of some marvellous things that can be done in C and CPP.[/QUOTE] If you need random anonymous people online to help you get interested, you are not interested enough. Maybe another language where you can … | |
Re: You can do it with the KeyPress or KeyDown event for the text box. Both of those have event args that tell you what key was pressed. | |
Re: When the compiler complains about dependent names, it means you need to use the [URL="http://www.comeaucomputing.com/techtalk/templates/#typename"]typename[/URL] keyword to fix an ambiguity: [code=cplusplus] template<typename T> class List { public: class A { }; A begin() const; }; template<typename T> typename List<T>::A List<T>::begin() const { return A(); } [/code] | |
Re: Have you tried opening with FILE_APPEND_DATA instead of GENERIC_WRITE? | |
![]() | Re: infile is local to the if statement and the file gets closed when the if statement ends. Inside the loop, the file is closed, the object pointed to by the pointer is gone and you are not allowed to dereference the pointer anymore. Even if you have a pointer to … ![]() |
Re: Static members of a class still need to be defined outside of the class, and in a file that will not be included multiple times like a header: [code=cplusplus] // globals.h #include <string> struct car { std::string type; std::string brand; std::string manufacturer; std::string engine; int cylinders; std::string tyres; }; public … | |
Re: For a good block cipher the responsible thing to do is change the constraint to expect cipher text length instead of plain text length or change the limit of the plain text to be short enough to meet the current database constraint. If you use a block cipher it is … | |
Re: You can do it, but I think a better way is to have a Clone() method in the Animal class that the child classes override. Then all you need to do is this: [code=csharp] foreach (Animal d in AnimalBufferList) { Add(d.Clone()); } [/code] | |
Re: [QUOTE]Can anyone recommend another book or website that lists all the C++/CLI functions and classes? Perhaps one that just is just a list with maybe one short example each?[/QUOTE] You just described [URL="http://msdn.microsoft.com/en-us/library/aa139615.aspx"]MSDN[/URL]. | |
Re: [QUOTE][CODE] iTemp = inFile >> day[numRecords]; iNew = inFile >> score[numRecords]; [/CODE][/QUOTE] iTemp and iNew are being assigned references to inFile, those values are not meaningful to you. I guess you wanted iTemp to match day[numRecords] and iNew to match score[numRecords]: [code=cplusplus] inFile >> day[numRecords]; inFile >> score[numRecords]; iTemp = … | |
My name is Tommy, and I am a computer consultant/programmer in the USA. C# and C++ are my primary weapons, and most of my work these days is .NET based for data capture, processing, storage, and retrieval. My hobbies are gaming, music, ultimate frisbee, and cooking. My personality type is … | |
Re: Show the login form first, then if the login is successful, open the MDI form from the login form: [code=csharp] void buttonLogin_Click(object sender, EventArgs e) { string user = textBoxUser.Text; string pass = textBoxPass.Text; if (IsValid(user, pass)) { new MainForm().Show(); Hide(); } else { MessageBox.Show("Invalid user name or password"); } … | |
Re: [QUOTE]Is it because my float values are too big?[/QUOTE] Or too small. Or too precise for fixed notation. You can print the usual way with the [ICODE]fixed[/ICODE] manipulator. [code=cplusplus] #include <iostream> using namespace std; int main() { double d = -4.49255e+013; cout << fixed << d << '\n'; } [/code] … | |
Re: [QUOTE]I am not using any features of .NET as I know of. So, why does Visual Studio always ask me to target a Framework in my project.[/QUOTE] Make sure you do not have the /clr switch anywhere in your compiler command line options. C++/CLI compiles native C++ to a CLR … | |
Re: Good OO design is like good code. You know it when you see it, but it is not something that can be taught. There are [URL="http://ootips.org/"]guidelines[/URL] to get started, but the real teacher is experience with what works and what does not. | |
Re: [QUOTE=jephthah;915989]yes, you're right. even though it works for this trivial example, not casting it properly is a bad habit to get into. the correct way to initialize it is: [code]char q[16]; char *p = [color=red][b](char *)[/b][/color]&q; strcpy(q,"abc");[/code][/QUOTE] So you get the wrong type, then cast it to the right type … |
The End.