Friday, July 31, 2009

How to use new operater in a C++ class?

Does anyone know how to use and implement the new operator in a class? I have a test on this in 8 hours and I barely understand classes. I understand pointers a little better. Can someone give me a quick simple demo? Basically my test is going to give me a class and I will have to insert a new operator line to get it to work, it will most likely deal with arrays. I need to pass this test to pass the class, I'm desperate. I use visual C++ 2008, just anything that can compile.

How to use new operater in a C++ class?
The 'new' operator is utilized when you want to declare a dynamic variable. This variable does not have a name; it can only be accessed through the pointer that you declared it with. For example, in your 'main' function you might write:





int *p, *q; // Declare p and q are each int pointers.


p = new int; // Declare that p points to an unnamed variable of type int.


q = new int[10]; // Declare that q points to an unnamed array of 10 variables of type int.





Before the dynamic variable goes out of scope, you need to write:


delete p; // Free the memory for the unnamed int pointed to by p.


delete [ ] q; // Free the memory for the unnamed int array pointed to by q.











Suppose you have already declared and defined a Distance class. In your 'main' function you might write:





Distance *d1, *d2; // Declare d1 and d2 are each Distance pointers.


d1 = new Distance; // Declare that d1 points to an unnamed object of type Distance.


d2 = new Distance[10]; // Declare that d2 points to an unnamed array of 10 objects of type Distance.





Suppose that 'getDistance()' is one of the public member functions that you declared in your definition of the Distance class. To CALL that function (from your 'main' function) for each successive Distance object in the array, you might write:


for (int i=0; i%26lt;10; i++)


d2[i].getDistance();





Before the dynamic variable goes out of scope, you need to write:


delete d1; // Free the memory for the unnamed Distance object pointed to by d1.


delete [ ] d2; // Free the memory for the unnamed Distance array pointed to by d2.








A separate issue: You can declare dynamic variables inside a class. Suppose your Distance class has only pointers as private data members:


class Distance


{


private:


int *ft; // pointer to int


float *in; // pointer to float


public:


Distance(); // constructor


// Declare your other class member functions here:


};





// Define your class constructor:


Distance::Distance()


{ feet = new int; // Declare an unnamed int pointed to by the pointer 'feet'.


*feet = 0; // Initialize variable pointed to by 'feet' to value of zero.


inches = new float; // Declare an unnamed float pointed to by the pointer 'inches'.


*inch = 0.0; // Initialize variable pointed to by 'inches' to value of zero.


}





Or instead, you could declare a Distance class that has a constructor in which the pointers declare an array of 5 ints pointed to by 'feet' and an array of 5 floats pointed to by 'inches'. In that case you would initialize each of the array members using a for loop.





Distance::Distance()


{


feet = new int[5];


inches = new float[5];


for (int i=0; i%26lt;5; i++)


{ feet[i] = 0; inches[i] = 0.0; }


}


What is the point of having a private class for C++? What is also the point in having a public class?

what is the point of having a private class for C++? What is also the point in having a public class? Why do people use a public and private class, also aren't pointers involved somewhere in there?


How can i make a c program function that can delete an allocated structure?

if i will be having a program that has a allocated structure with pointers, how can i make a delete function????





example if the program asked for the address of a person and you would like to delete that particular address...hhow can i make that c program function????????

How can i make a c program function that can delete an allocated structure?
If you used malloc() to create the allocated memory, use free() in the reverse order to free up the memory.


Calculating letter grade using function in c++?

I am supposed calculate the letter grade using fuction in c++ and I just need some help with writing the actual function. so far, I got this





#include %26lt;iostream.h%26gt;





char getLetterGrade (int gradeIn) {


// replace this comment with your code for this function


} // letterGrade





// insert your code for the getNumericGrade function here








int main() {


int grade;


char letterGrade;





do {


grade = getNumericGrade();


if (grade != -1) {


letterGrade = getLetterGrade(grade);


cout %26lt;%26lt; "The student's letter grade is: " %26lt;%26lt; letterGrade %26lt;%26lt; endl;


}


} while (grade != -1);





cout %26lt;%26lt; "Good-bye" %26lt;%26lt; endl;


return 0;


} // main





can anyone give me any pointers of how to write this function?





Thank you

Calculating letter grade using function in c++?
I hope this isn't your homework, otherwise this is cheating.





Create IF, ELSE IF conditional statements in your function that retun the letter grade





example:


if gradeIn %26gt;= 90 %26amp;%26amp; gradeIn %26lt;=100


return 'A'


else if gradeIn %26gt;= 80 %26amp;%26amp; gradeIn %26lt;90


return 'B'


...


...


else


return 'F'





hope that helps

survey monkey

Calculating letter grade using function in c++?

I am supposed calculate the letter grade using fuction in c++ and I just need some help with writing the actual function. so far, I got this





#include %26lt;iostream.h%26gt;





char getLetterGrade (int gradeIn) {


// replace this comment with your code for this function


} // letterGrade





// insert your code for the getNumericGrade function here








int main() {


int grade;


char letterGrade;





do {


grade = getNumericGrade();


if (grade != -1) {


letterGrade = getLetterGrade(grade);


cout %26lt;%26lt; "The student's letter grade is: " %26lt;%26lt; letterGrade %26lt;%26lt; endl;


}


} while (grade != -1);





cout %26lt;%26lt; "Good-bye" %26lt;%26lt; endl;


return 0;


} // main





can anyone give me any pointers of how to write this function?





Thank you

Calculating letter grade using function in c++?
if grade%26gt;0 and grade%26lt;60 return f





if grade%26gt;59 and grade%26lt;70 return d





etc.


How do I copy an Audio C.D. into MP3 format?

I am trying to upload some original music onto my web-site but they are saying (support providers)that I need to copy the C.D. into MP3 format. I have been trying to figure out how to do this and I'm getting really frustrated. Can anyone give me some pointers?

How do I copy an Audio C.D. into MP3 format?
You can use Windows media player to do it, but i recommend using db Poweramp (http://www.dbpoweramp.com).





This allows you to rip CDs in mp3 or wave formats. Mp3 is a lossy format, and the loss in quality of the ripped files depends on the bit rate you select to rip the audio at. 128k is the minimum rate i would use for decent quality - as you increase the bit rate you also increase the file size as well as the quality.
Reply:Go to http://www.download.com/ and search for windows media player 10, download it and then go to TOOLS and Options or properties then to rip tab then put instead of windows media format mp3, then put your cd and rip it in the folder you choose.
Reply:Pretty simple. Windows Media PLayer and iTunes both allow you to rip to MP3. Make sure that your setting/options are set accordingly because WMP defaults to WMA and iTunes to MP4.
Reply:try any rip to mp3 software. there are lots of them on the net.
Reply:You can use Windows Media player, Real player, or another media player to rip the CD. make sure you set the option to convert to mp3 (128kbps since you're uploading the music), and to make a note of the folder that the songs are ripped to.
Reply:hey put in ur audio cd


open windows media player


either there will be an option below the top bar "Rip"


or u can go in it thru tool--%26gt;option--%26gt;Rip


rip ur audio cd into ur hard disk


u will get the required thing
Reply:You can do this by using one software called CDEX. U can download this software for free and after installing this there will be easy way in this software by, just put the cd in the CD Drive and just click the button CD to MP3 button. It will automatically convet the cd tracks to MP3 format
Reply:You can convert a audio cd into a MP3 using Windows Media Player. It's really easy.
Reply:you have to download a program that converts files to mp3 format and can brun them that way as well. I suggest trying http://www.download.com/3120-20_4-0.html...


Help with array in c++?

Hey im doing this program and i really need some help.





The program is to store alphabet as characters in an array


it must also:


Print the alphabet


Print the first 6 characters


the last ten characters


and the tenth character





Here is what i done so far








#include%26lt;iostream.h%26gt;





int main()


{





char alpha[27]={'a','b','c','d','e',


'f','g','h','i','j','k','l','m',


'n','o','p','q','r','s','t','u','v',


'w','x','y','z','\0'};





cout %26lt;%26lt; "The alaphabet is\n"%26lt;%26lt; alpha %26lt;%26lt;endl;








return 0;


}





The code above only prints the alphabet i think i should use something call pointers or summin to output the other characters but i don't know how

Help with array in c++?
You've done a good job so far, now it's just a matter of calling the right characters to print.





You will want to do a print statement something along these lines:





Print the first 6 characters:


int k;


for (k =0; k %26lt; 6; k++)


{


cout %26lt;%26lt; "The first 6 characters are\n"%26lt;%26lt; alpha[k]%26lt;%26lt;endl;


}








Print the last 10 characters:


int j;


for (k=27; k%26gt;=18; k --)


{


cout %26lt;%26lt; "The last 10 characters are\n" %26lt;%26lt; alpha [k]%26lt;%26lt;endl;


}





Print the 10th character:


cout %26lt;%26lt; "The 10th character is: " %26lt;%26lt; alpha[9]%26lt;%26lt;endl;








You might need to change the syntax up a little bit but this should give you general information and help about how to set up these simple print statements.





I hope this helps


Best Wishes
Reply:You need to loop through every value in the array.





cout %26lt;%26lt; "The alphabet is\n";





for(int i= 0; i %26lt; 26; i++)


{


cout %26lt;%26lt; alpha[i] %26lt;%26lt; endl;


}
Reply:You don't need pointers for this particular exercise.


//first 6


for(int i=0;i%26lt;6;i++)


cout %26lt;%26lt; "Letter " %26lt;%26lt; (i+1) %26lt;%26lt; " is " %26lt;%26lt; alpha[i] %26lt;%26lt; endl;


//last 10


for(int i=15;i%26lt;26;i++)


cout %26lt;%26lt; "Letter " %26lt;%26lt; (i+1) %26lt;%26lt; " is " %26lt;%26lt; alpha[i] %26lt;%26lt; endl;


//10th


cout %26lt;%26lt; "The 10th Letter is " %26lt;%26lt; alpha[9] %26lt;%26lt; endl;
Reply:why dont you use for loop?


If you wanna print t, u,w,x,y,z then a for loop that counts 6 elements from the index of element you want to print, and then just print inside the for loop.


something like this:


for(counter = 22;counter%26lt;28;counter++)


{


cout%26lt;%26lt;alpha[counter] + "\n";


}


this prints from the index 22 to 28 in different lines. and you know how to change it so it prints in oneline.


hope it helped and good luck


Create dynamic array in C++ class?

I am reading a output file with approximately 50 int variables in it. The numbers are stored usingmy current declaration:





in List.h


int data[MAX_LENGTH];





in List.cpp


data[index]=item





I want to be able to dynamically create the array data (using new int[] and pointers, to satisfy an assignment), but still be able to use it as if it were statically created. I would also like to know how I can make the length of data be the length of the input file plus one. In other words, how can I make the array grow/shrink to match the size of it's information? Be nice, I'm only in my 2nd year of C++

Create dynamic array in C++ class?
Let's get the harsh part out of the way first: what you are doing is C, not C++.





The C++ implementation would be to use std::vector%26lt;%26gt;. That class will do what you are asking: it can be treated like a static array (it does offer range checking though!!) but can be resized and is allocated on the heap so size of your data does not matter.


Basic usage is like this:


#include %26lt;vector%26gt;


std::vector%26lt;int%26gt; myVector;


myVector.push_back(1); // let's put in some data..


myVector.push_back(5);


myVector.push_back(10);


cout %26lt;%26lt; myVector[0]; // let's access the contents


cout %26lt;%26lt; myVector[1]; // let's access the contents


cout %26lt;%26lt; myVector[2]; // let's access the contents





Look at the reserve and resize methods of vector to see how you can dynamically change the size of this structure.





If you really have to use new[] then you can simply create it like this:


int* data= NULL;


data= new int[someSize];


//add and retrieve the data


data[0]= 5;


cout%26lt;%26lt; data[0];


// and then get rid of it later with


delete[] data; data=NULL;





You can't really do dynamic resizing of a new'ed array. Instead you would have to create another array of a different size (smaller or larger) and slowly copy everything over from the previous array. Internally this is what std::vector does for you- which is why using reserve() is a good idea to reduce the number of copies.


Hope that helps.





ETA:


You can not call new[] as part of the declaration in your header file, it has to be in your source file:


mylist.h:


char* someList;


mylist.cpp:


someList= new int[500];
Reply:int main (void) {





float d, s1, s2;





int *my_array;





my_array = new int[50]; //or maybe 'new int[MAX_LENGTH]





my_array[33] = 304;





printf("33rd position contains %d",my_array[33]);





return 0;


}

online survey

How can I loose the belly from haveing a C-sections?

I had a c-section with my baby and it has been so hard to loose it! Any pointers on what to do!!!!

How can I loose the belly from haveing a C-sections?
Go for hoodia gordonii, its south afrian diet plant pill for loose weight from face, belly, thights, hips, and its also reduces appetite and decrease weight and also burn calories, fats. i saw the drama and advertise of hoodia on BBCand CNN. http://www.gordoniihoodia.net/hoodia-die...


and yes even you can lose weight by hoodia, am too much sure bcoz ma mom is one of them who loose almot 80 pounds in 3 months, i know that a big time duration but finally she loose fats from belly, thights, hips http://herbalzilla.com/?getlook and also her extra fats and calories has beeeen burn that makes her more sexy figured, she was using Hoodia Gordonii for 3 months http://h-oodia.com/?getlook


Help writing a C program dealing with rectangles?

Hello,


I need help writing a C program that takes the width of a rectangular yard and the length and width of a rectangular house situated in the yard. I don't want the answer because every programmer has a different way of writing code. I just needs some tips or pointers. Thank you in advance for your input.


-AB

Help writing a C program dealing with rectangles?
See Help for Rectangle() via Windows or _rectangle() for DOS window. Latter will also need _setvideomode() and maybe _setcolor() - see also _moveto() and _lineto()


In need of C++ programming help please!!?

I have been taking a programming course for a few weeks now and need a little help with an assignment. My assignment is to write a program that displays a menu with the the option to find the largest # with a known quantity of numbers; find the smallest # with an unknown quantity of numbers or quit.





Here is what I have so far, but my book has gotten me so confused. I need some pointers as to what I am missing or what is wrong and needs fixed. Any help would be greatly appreciated.


Serious answers only please.





#include %26lt;iostream%26gt;


using namespace std;


const int SENTINEL = -99; //to end option 'B'


int number; //variable to store numbers


int counter;


char limit; //variable to store amount of numbers to input in 'A'





int main()


{


char sel;


number = 0;


int count = 0;





cout %26lt;%26lt; "A) Find the largest # in a list." %26lt;%26lt; endl;


cout %26lt;%26lt; "B) Find the smallest # in a list." %26lt;%26lt; endl;


cout %26lt;%26lt; "C) Quit." %26lt;%26lt; endl;


cout %26lt;%26lt; "What do you want to do?" %26lt;%26lt; endl;


cin %26gt;%26gt; sel;


switch (sel)

In need of C++ programming help please!!?
You would be better off going to www.homework.com or to www.studybuddy.com There is a lot of help there.
Reply:You're overwriting the previously entered number every time you cin a number from the list.





You need to set up an array, say


int list[100];





Then use an integer variable to count your position in the array


int i;


cout %26lt;%26lt; "Enter the numbers for the list: "


while(i=0;i %26lt; listsize;i++)


cin %26gt;%26gt; list[i];





The better way to do this is to use a linked list since there is then no upper bound on the size of the list of numbers, but that is probably a bit too high level for an early programming class. I'd stick with the array solution.
Reply:well, first, your program will only run through 1 selection then end. you need to make a loop with your selections in it. something like:


do


{


//your selections


//your code


}


while (sel != 'c' || sel != 'C');





next, in your "case 'A'" you never initialize counter or increment it. did you mean to use count instead?





in your "case 'B'" you never increment count, and all it does is read in numbers. I assume you just didnt finish it yet because your still trying to get case a to work first.





thats for starters just off the top of my head
Reply:#include %26lt;iostream%26gt;


#include %26lt;cstdlib%26gt;


using namespace std;


int main(){


int i,min_val,max_val;


int list[10];


for(i=0;i%26lt;10;i++) list[i]=rand();


min_val=list[0];


for(i=1;i%26lt;10;i++)


if(min_val%26gt;list[i]) min_val=list[i]


cout%26lt;%26lt;"minimun value: "%26lt;%26lt;min_val%26lt;%26lt;"\n";


max_val=list[0];


for(i=1;i%26lt;10;i++)


if(max_val%26lt;lsit[i])


max_val=list[i];


cout%26lt;%26lt;maximum value: "%26lt;%26lt;max_val%26lt;%26lt;"\n";


return 0;


}


Computer Science C++ HELP!!!?

Does anyone know a really good website to learn about Computer Science C++? The book i have explains it in way too many details. I need something simple and understandable. I want to know about Pointers, Enums, Classes and Data Abstraction.

Computer Science C++ HELP!!!?
The C++ Language Tutorial! See the link below
Reply:Learn C++ in 21 Days!





http://newdata.box.sk/bx/c/
Reply:Go to www.programmersheaven.com Also check out your local community college for classes or join an online computer club or a local one.
Reply:Also check out http://www.cprogramming.com/tutorial.htm... for tutorials. Avoid the learn C++ in 21 days link posted above. The C++ tutorials there are outdated, and haven't been updated.

salary survey

The best way to learn c++?

Ive tried several times to teach myself c++ and I start out strong but get frustrated when dealing with more complex topics especially pointers, working with data, classes, and other stuff. I feel like I need someone who knows what theyre doing to talk to when I get frustrated. plus I'd like someone to give me tasks that Im capable of coding. I don't know any programmers so this is frustrating. i really feel i need to talk to someone rather than post on a message board, is there anything out there that i could use?? aside from college.

The best way to learn c++?
Best way is to have an older brother who has learned.





Second best way is take a class.





Third best way is use a book.





Fourth best way are online tutorials.





Fifth best way is just fool around and figure it out (good luck)





The WORST way is go asking on Yahoo answers for help.
Reply:Why do you say "aside from college?" You don't have to go to four years of college to learn C++. I learned it by taking a single class at a local community college.





In my opinion that's way better than taking some seminar, or trying to learn it from a "Teach yourself C++" book.





Community college courses are typically very cheap and offer night courses so that you can go when you already have a job.
Reply:You might be too frustrated for my suggestion, but I highly recommend "For Dummies" books on C and C++. They explain it in a non-technical manner but you still get the details you need, and they have lots of examples and exercises.
Reply:I know learning a language can be frustrating, especially when you don't have any challenges. I have been there!


In my opinion, try surfing the web and finding different problems, especially programming problems, and questions, and try to code them in C++. I did that, and it really helped me.


For example, I will try to code a program that creates stacks, in the form of linked lists! Then, I will push, pop, is_emp() etc. This will really keep the ball rolling.


Hope this helps, and Good Luck!


Need help in C programming?

i need a c program that displays all factors of a number including one and itself. I can't use arrays, pointers, and strings. I am also not allowed to use other libraries... only stdio.h. help anyone?

Need help in C programming?
Use the mod operator %.





Remember 0 is equivalent to false, and anything else is equivalent to true in C, so you don't need to waste system time with a comparator like (==).





10 % 2 returns false, and that means it's a factor wile


10 % 3 returns true, and that means it's not a factor





the highest factor for any number is that number divided by 2, and the number itself and 1 will always be a factor.
Reply:Well the best way to do this would be to iterate from 1 through to the square root of the number desired. then divide the number by each one, test if fpart(number/possiblefactor) == 0. If it does equal zero then print the possible factor and the result of the division.





Finally check if the number is a perfect square and print that too if it is.
Reply:what is C programming

survey

Quicksort Algorithm Program in C++ Help?

You should write a program that goes through partitioning and recursive sets and create a program that does a quicksort. Write a recursive function to sort a single-subscripted


integer array. The function should receive as arguments an integer array, starting subscript


and an ending subscript. Function partition should be called by the recursive quickSort


function to perform the partitioning step. You should use the principle of least privilege


and pass-by-reference with pointers for passing arguments to functions.


You should generate 10 numbers randomly to test your program.





Expected Output:





Initial Values:





70 674 335 209 420 548 406 437 990 313





The sorted array values are:


70 209 313 335 406 420 437 548 674 990





This is in my C++ book (C++ How to Program 5th Edition by Dietel). Any idea as to how to do this? I'd really appreciate help. Thanks!

Quicksort Algorithm Program in C++ Help?
Exercise 8.24 pretty much tells you how to do it.
Reply:If you are still stuck, may be you can contact a C++ expert live at website like http://askexpert.info/ .


C++: When do you decide to pass variables by value, reference, or pointers?

Two situations:


1) When we want to modify the actual variable passed as the function parameter


void swap(int %26amp; a, int %26amp; b) ==%26gt; Swaps values of a and b.


2) If we do not want to make copy of the parameter for example


void display (const int%26amp; n) // pass by reference.


Here you do not want to change the variable n , also you do not want to create a local copy (if u pass by value a local copy will be created).

C++: When do you decide to pass variables by value, reference, or pointers?
It is purely based on requirements %26amp; operations
Reply:Pass by value if it's small, for example integers or characters or pointers. Pass by reference if you want to save a memory copy and the value you pass should not be null. Passing by reference is similar to pointers, in that only a pointer sized piece of memory will be transmitted, however it's understood that passing by reference implies the object is not null. Pass by pointer if you want to save on memory copy and the value could be null (in which case null might be a special sentinel value condition).
Reply:it's a tricky question, and you need some experience to decide what to do.





by value: i always pass by value, unless i'm passing an object. if you pass by value, the value is copied; if you're passing an object (i.e. std::string or your own objects) by value, the copying can cost performance, and therefore i want to avoid it.





by pointer: that's what i use if the original value should be modified. You can also use references in that case, but there's one difference: a pointer can be NULL, a reference cannot be NULL. sometimes i use this feature to signal that this variable can be optional (by setting it to 0).





reference: i don't like references, therefore i don't use them a lot. but i do like const references. they are useful, especially if you want to avoid copying objects.
Reply:First you have to choose pass by reference if the


function or method is permitted to (and is capable of) modifying the actual argument. This implies that the argument must be an expression (lvalue) that


can reasonably be modified. Example : swap function.


But if you are using the value of the argument to compute a new value or do something else, it's cleaner to pass by value, except if there is performance issue such as the following.


Here is a recommendation by Meyers (Effective C++) :


prefer pass-by-reference over pass by value, except for built-in types and STL iterator and function object types.


So if your copies are lightweight enough , pass-by-value but if you are passing something large like an struct, choose pass-by-reference or pointer .


choosing between pointers and references is more of a style preference as there is no difference in performance .pointers are more explicit than references, if we do not go with pass-by-value. So they make a cleaner interface.


What should i do next in c++??? + MATLAB software.?

I have taken only one course of c++ at college (engineering). We learned about: scan, print,loops, conditions,functions, macros,recursive functions,switch functions,pointers, 1d %26amp; 2d arrays,structures,a very short lecture about strings . Now , at summer time, i want to learn additional things about c++. Can anybody tell me what to do? please give me the link to it. consider that i am interested in topics involving numbers and calculations and not words and characters.


An additional question: I have found a tutorial of MATLAB linked to wikipedia, but i don't know where to get a free download to a matlab software.

What should i do next in c++??? + MATLAB software.?
Writing games is a very good option you can consider if you think you can do well in math.You can start with Mesa GL which can give you even more depth into C and c++ including callbacks,line drawing algorithms, and you can graduate to splines and other more complex algorithms.Finally you would have done enough to create a game ;)


You can try hacking with the kernel and device drivers on a linux box to get a better understanding of things which make linux click ;).Most of the linux kernel is written in C and C++.


AS for your information Matlab isnt free.You will have to pay a huge sum to get it.
Reply:dfghgetggeg
Reply:so far you've learned the C heritage of C++. The next language features would be classes, object oriented programming (OOP), and then templates. You find a lot of information and tutorials on the web.





my personal opinion, though: learning this doesn't lead to anything, unless you actually USE it. So think of some nice programs and implement them in C++. That way, it's more fun and you learn faster.
Reply:if you are really a programming enthusiast and you are that good, then you can try studying about database applications or try to study directX so you can start to create games with you would be applying math and complex calculations as you go on.

land survey

Learning C++?

I know the basics, cout %26amp; cin, OOP, pointers, functions and a bunch of stuff, I know lots about programming in text based console apps.


I have bought 2 books, the first going over very basic, and the next a bit more advanced.





I want to be able to program with graphics! How do I do that!


Nothing will tell me! I don't wan to buy any more books, I'm pretty much broke, I'm using Dev-C++ as my compiler, as I can't afford a high quality one.


Someone name a website or place that offers free tutorials that teach you programing with graphics. I don't want something that just shows source code, that is dumb, because you don't know what It means, I want something that will show, and describe to me how to do. Thank you

Learning C++?
for games gamedev.net


but to learn graphics go to codeproject.com


u have to use MFC,WTL,ATL or similar library file provided by others to do graphics


the basic graphic can be done using win32
Reply:Asking for too much to be written here.. visit comp.lang.c++ newsgroup from Google groups. Their FAQ and old threads have answers for your questions. That was a short answer wasn't it? ;)





I hope you have already sen things like CUJ(out of publication now), Dr. Dobb's et al.
Reply:search devshed can't remember but think it's devshed.net, but it will have a list of languages on the left to choose from. also, devguru and search yahoo for free online books programming, should help you find a bunch of online texts for development.


C programming help?

Hey guys, just trying to learn c programming here. I'm wondering, how would you be able to write a function that could determine between a capitalized and lowercase letter? I've been hearing something about a malloc or pointers and I'm not too sure if I understand.





Thanks

C programming help?
I'll try to explain pointers first, since they are very important in C programming.





In C, if you have a chunk of text in a variable, what you really have is a memory address that tells your code where in RAM (which I'll refer to as just memory) your text is being stored. This memory address is called a pointer in C.





When dealing with data in memory, everything (and I mean EVERYTHING) in C is handled as a number. So if you have code like this:





char letter = 'A';





what you really have is a 1 byte number with the value of 65. That's right, a capital "a" is actually stored in memory as the number 65, whereas a lowercase "a" is 97. These numbers are referred to as ASCII codes.





Here's an excellent ASCII reference: http://www.asciitable.com/


You'll be most interested in the "Dec" column for each letter for the correct number. "Dec" is short for decimal, which is the base 10 number system on computers (numbers 0 - 9), while "hex" (or "Hx" on that website) is short for hexadecimal, the base 16 number system (numbers 0 - F, see http://en.wikipedia.org/wiki/Hexadecimal...





Anyway, back to your question...





Now, armed with this information, if you look at the ASCII codes for each letter, you'll notice something: all uppercase letters have an ASCII code between 65 and 90, while lowercase letters are between 97 and 122.





The simplest way to test if a letter is uppercase or lowercase is to do something like this:





bool isupper( char letter )


{


if ( letter %26gt;= 65 %26amp;%26amp; letter %26lt;= 90 ) return true;


return false;


}





bool islower( char letter )


{


if ( letter %26gt;= 97 %26amp;%26amp; letter %26lt;= 122 ) return true;


return false;


}





What these two functions do is simply test to see if the letter you send them is within a certain range. If the letter is in that range, then the letter is either uppercase (if you tested with isupper) or lowercase (if you tested with islower).





Here are a few examples:





isupper( 'C' ) // returns true


isupper( 'j' ) // returns false





islower( 'C' ) // returns false


islower( 'j' ) // returns true





isupper( '2' ) // returns false


islower( '?' ) // returns false


isupper( '_' ) // returns false


islower( '@' ) // returns false





Something to note is if you give either function something that isn't a letter, you will always get false back.





Now, going back to pointers...





When you want to work with more than one letter, say the text "I’m a text string", each character (letters, numbers, spaces, punctuation, etc.) is a separate 1 byte number, which means you need 17 bytes of memory to store that text. So, you’ll need more than just a single 1 byte variable. This is where pointers come in.





When you do this:





char *text = "I’m a text string";





you are creating what’s referred to as a string literal in your code (which is a practice known as hard-coding) which is handled as a pointer to a block of memory that stores the text.





There are two ways to interact with this text now. One way is through pointer arithmetic, which is beyond the scope of this answer, and the other way is to treat your pointer as an array. Any pointer can be handled as an array in C, it’s up to you to know when and where this is appropriate. Since we know that the pointer “text” in the above code points to a block of text in memory, we know it’s safe to use it as a character array.





Put simply, if you want to access the first character in your text string, you would use text[0]. The second character is accessed with text[1], the third with text[2], fourth with text[3], and so on.





So in the end, by calling isupper( text[0] ), you will get true back.





I really hope you were able to follow all of that, and that it helps out. If you have any questions regarding my answer, just let me know.
Reply:Actually, you shouldn't need any header files or libraries at all, unless your compiler doesn't support bool natively (though it should). Report It

Reply:http://c2.com/cgi/wiki?CapitalizationRul...


hope that will help ,I dont really know alot about c programming or about programming and design but i have my reasons to be hear.
Reply:Use the isupper() function.





char x = 'a';


bool testing = isupper(x); // false





x = 'A';


testing = isupper(x); // true





Remember to add #include %26lt;cctype%26gt; at the top.


C++ Stack Question?

Hey Guys I am making a C++ Stack program for a school assignment and I have a quick question. I just learned about stacks so bear with me.... how do you print the contents of the stack?? also is it going to print it backwards? If so how would I go about printing it forwards??





I think I have an idea of what I need to do and it would involve nodes and pointers but can you give me some help?





Thanks!

C++ Stack Question?
Stack is known as a Last In, First Out object.


Only the last item pushed onto the stack is accessible.





typedef struct list_node


{


int data;


struct list_node *next;


} *list_node_ptr;





class Stack


{


list_node_ptr head, current;


list_node_ptr MakeNode(int data)


{


return new list_node(data, NULL);


}





public:


Stack() {head = current = NULL;}


void Push(int value)


{


list_node_ptr link = MakeNode(value, NULL);


if (head == NULL)


head = current = link;


else


{


current-%26gt;next = link;


current = link;


}


}





int Pop()


{


if (head == NULL)


{


throw "Stack Empty"; // remove this if not use exceptions


return 0;


}


else


{


int v = Examine();


if (head == current)


{


delete head;


head = current = NULL;


}


else


{


for (list_node_ptr link = head; link-%26gt;next != current; link = link-%26gt;next);


delete current;


current = link;


current-%26gt;next = NULL;


}


return v;


}





int Examine() {return (current ? current-%26gt;data : 0);}


}
Reply:You can print it either forwards or backwards, it's up to you. A stack is usually stored backwards, that is, the most recent data is at the bottom and oldest data is at the top.





When you say you are making a C++ Stack program, does that mean you are implementing your own stack data structure? It's hard to answer your question without knowing exactly what kind of stack you are talking about.


C++ sorce code for user input matrix size & values during runtime and rotate 90 degrees clockwise?

I'm having problems rotating 90 degrees clockwise for a matrix with user inputing size %26amp; values during runtime and rotation is performed in function. How to pass matrix to function %26amp; use pointers for this problem?





Here's the question.





Write %26amp; rtest the function that rotate 90 degrees clockwise a two-dimensional square array of ints. For example, it would transform the array





11 22 33


44 55 66


77 88 99





to





77 44 11


88 55 22


99 66 33





The program should use dynamic memory allocation to allocate memory for the 2D array after getting the size of the square array.





It's hard to rotate when having the user giving array size and rotate based on the size.





Please insert the C++ source code for this question.





All helps are appreciated.TQ very much.

C++ sorce code for user input matrix size %26amp; values during runtime and rotate 90 degrees clockwise?
To use pointer with 2D matrix it is better to use pointer to a pointer. It can be used like usual 2D array.


Code in main should be something like below


//input dimension from user, m by n matrix


int** matrix;


matrix=new int*[m];


for( i=0;i%26lt;m;i++)


matrix[i]=new int[n];


// now input matrix from user in usual way.





now you can use this pointer to pointer as usual 2D array, when calling function just pass pointer to pointer as argument.


I have said you how to raotate 2D array in your previous question. I'm just repeating procedures, not the code.


First transpose the matrix and then reflect it wrt horizontal axis. I think this will work.
Reply:Run it u can get some idea ...





#include%26lt;stdio.h%26gt;


#include%26lt;conio.h%26gt;





#include%26lt;stdlib.h%26gt;





# define ROW 4


# define COL 4





void rotate_90(int**,int,int);


void print_matrix(int* m , int r, int c );











int main()


{


int * matrix ;


matrix= (int*)malloc(COL*ROW*sizeof(int));


int count=0;





for(int i=0;i%26lt;ROW;i++)


for(int j=0;j%26lt;COL;j++)


matrix[i*COL+j]=count++;


printf("till ");





print_matrix(matrix,ROW,COL);


rotate_90(%26amp;matrix,ROW,COL);





printf("\n\n");





print_matrix(matrix,COL,ROW);








return 0;


}








void rotate_90(int** m,int r,int c)


{


int *matrix;


matrix=(int*)malloc(r*c*sizeof(int));


for(int i=0;i%26lt;r;i++)


for(int j=0;j%26lt;c;j++)


matrix[j*c + c-i-1]=(*m)[i*c+j];





free(*m);


*m=matrix;











}





void print_matrix(int* m , int r, int c )


{


int j=0;


for(int i=0;i%26lt;r;i++)


{printf("\n");


for(int j=0;j%26lt;c;j++)


{


printf("%d \t",m[i*c+j]);


}


}


}

survey software

C++ Code to Implement an Abstract Interface ?

In Visual Studio 2005 and using C++, how can I implement the


properties and methods of an abstract interface that I have imported from a type library (.tlb file)? (What functions do I need to call, what pointers do I need to create, etc.) Also, what type of Visual Studio project do I need to create in order to accomplish this?

C++ Code to Implement an Abstract Interface ?
There is no such thing as an Abstract Interface.





Interfaces are not supported with (ISO) C++. You should use an abstract class with only virtual methods.





A .tlb file is (I'm guessing) a Type Library. These are used with COM/ActiveX controls.





Type of Visual Studio project: .... a C++ project I guess





If you are using managed C++, you can just add a reference to the COM object, which should add a RCW you can use (a wrapper around the object referenced). This will do most housekeeping for COM/ActiveX objects for you.
Reply:Here is a resource to do that.


C# Question?

I have been studying c# for a little over than a month, and i have developed an application, at the moment is very intermediate, would someone be kind enough to have a look at the source code and give me some pointers on how i can improve?

C# Question?
sure.. i'll do it..


I learned C++ in 12 hours?

I learned C++ from functions, arrays, writing to files ,data types ,2-D arrays, the math, rand() , variables, input/output consoles, ALL of the loops, pointers and a bit on classes public/private








I also learned Pascal this weeked in a couple of hours ...














A lot of people laughed at me when I told them I learned C++ in 3 days (4 hours /day) ...nothing advanced ...but I could write an original program and use all of those things above with no problems and I never forgot how to do it ...I still remember.








So why do people laugh when I tell them?

I learned C++ in 12 hours?
Anyone can learn the basics of a programming language in a couple of days. If you have already programmed in another language, you can pick up another very very quickly. Just because you have basics down in 12 hours does not make you some sort of genius.





Do you know good programming practices? Do you write maintainable code? Do you know what encapsulation is? Do you know what polymorphism is? Do you understand inheritance? Do you know anything about synchronization and multi-threaded programming? Do you know how to use sockets?





Don't worry, you haven't conquered the language yet.
Reply:Because of it's complexity.


I took it for a complete semester, and we covered that material, and I may have learned it, but I did not master the entire language itself. You must be a genius. (not being rude, but you must be to have gotten a grip on all you say in 4 days.)





peace,





mavin
Reply:I guess you can LEARN C++ in a few days, but it takes a lot of practice and time to really excel at it. Maybe you are just a fast learner. I learned the entire Adobe Suite in just a few days (with prior Photoshop knowledge). Consider peoples' laughing as a complement. You are so good, they cannot even believe it!
Reply:Apparently, the question is, "So why do people laugh when I tell them?" Is it that they are laughing or just disbelieve the claim?





I do think it is possible for people who have backgrounds in similar or related technologies to learn programming languages rather quickly.





For example, if you are an EE who might have a background in using lower level languages for programming PALs or perhaps you are an assembly language programmer, it might be fairly quick for one to grasp concepts of a language after learning the syntax.





I think that even BASIC programmers, specifically those who learned different dialects or even programmed in Visual Basic over time may have the acumen required to quickly pick up a new language.





However, there is one thing to note: learning the syntax of the language is the easiest part, learning how to use it basically is the next step (which apparently you have done); using it proficiently does take time, as it seems that all languages allow for people to use them just as incorrectly as they do correctly and efficiently.





A benefit of you having learned the syntax of two other languages, is that you can probably, with some practice, be able to translate between one language to another. This is a very good skill to have, especially when you find a problem solved in one language that can be introduced into a system that uses another.





Congratulations on your newly learned languages, I hope you use them well!
Reply:well.... do you want a cookie or something?


maybe they don't care. who are telling also. maybe they are egg heads and learned it in 15 minutes.
Reply:because they are jealous
Reply:I don't think you can say that's "learning" C++. I mean, you could write a basic program... But could you make a program that looks like World of Warcraft, or Photoshop, or anything that complicated? There's much more to learn!


I learned C++ in 12 hours?

I learned C++ from functions, arrays, writing to files ,data types ,2-D arrays, the math, rand() , variables, input/output consoles, ALL of the loops, pointers and a bit on classes public/private








I also learned Pascal this weeked in a couple of hours ...














A lot of people laughed at me when I told them I learned C++ in 3 days (4 hours /day) ...nothing advanced ...but I could write an original program and use all of those things above with no problems and I never forgot how to do it ...I still remember.








So why do people laugh when I tell them?

I learned C++ in 12 hours?
Thats nothing hefty, people who do not get the proper teaching styles learn slower. 3 days learning basic C++ isn't much and pascal is a joke.
Reply:because they can't comprehend it even being possible to learn that quickly.. i know the feeling

survey research

R/C Helicoter?

I just ordered an Eflight Blade cp R/C Helicopter and am fairly new to the R/C Flying things world. I was doing some research on the model I got and found some nice looking upgrades for it. The one that caught my eye is a kit that replaces the plastic parts with cnc alluminum. One part in particular is that it converts the heli from dual engine to belt drive system with pitch control for the tail rotor. Is his system much better than the dual set up and is it worth the extra effort for an electric micro-heli? And what pointers can you give me for learning to fly it? Thanks all!

R/C Helicoter?
it is i nice little Helli but get use to it first before you start spending money on hop ups this site is only Helli's and it is for everyone from beginners to the pros


fly safe


Dan


http://www.runryder.com/
Reply:Go to www.rcuniverse.com for a specialized forum on everything RC. Enjoy your heli


C programming: Returning multiple arguments from a function.?

In C, how do you return multiple arguments from a function? I'm pretty sure it needs pointers... But I have no clue how!





Please go easy on the jargon, I'm just learning!

C programming: Returning multiple arguments from a function.?
Yeah you got it right. You have to use the pointers for that purpose.


If you have to return the values that are of the same data type (eg. int) then you can use array to return multiple values.


But if you need to return values of different data types, then you have to use the pointers (in C).


for example: this function will put values in a, b and c and return them all.


void ReturnVals(int %26amp;a, int %26amp;b, int %26amp;c)


{


a=2;


b=3;


c=4;


}





call this function from somewhere else using the code like:





int val1,val2,val3;


ReturnVals(val1, val2, val3);


printf("%d, %d, %d",val1,val2,val3);





Then you'll get the output as 2,3,4


As you've seen we've succeeded in getting multiple return values from the function ReturnVals.
Reply:You can't return more than one argument from a function call. However, there are ways around this. The easiest way is to create a structure and then pass the address of the structure as one of the arguments to the function call. The function can then assign values to the various members of the structure and they will still be intact when the function exits. I hope this isn't too heavy on jargon. Here's an example: (but please forgive any syntax errors - it's been years since I did C programming...)





main()


{


struct


{


int a;


char b ;


} myStruct ;





DoFunc (%26amp;myStruct) ;


printf ("a=%n, b=%c\n", myStruct.a, myStruct.b) ;


}





void DoFunc (myStruct *TheStruct)


{


TheStruct.a = 2;


TheStruct.b = 'q' ;


}





A should be equal to 2 and b should be equal to q.
Reply:when defining the function, put multiple arguments in the brackets.





main(a, b, c)





instead of





main(void)





Hang on, that might be arguments supplied _TO_ the function, err, sorry, I'm learning too.





Good luck.
Reply:The only way to return multiple arguments is to return a struct. It is not obligatory to use pointers. You have to define a struct with all the information you need to return


typedef struct sth { int a;


int b;


char c;}sth;





sth func(int aa,int bb,char cc)


{ sth my_sth;





my_sth.a=aa;


my_sth.b=bb;


my_sth.c=cc;





return my_sth;


}





main()


{ sth sth_ret;


int a1=1,b1=2;


char c1='a';





sth_ret=func(a1,b1,c1);





printf("%d %d %c\n",sth_ret.a,sth_ret.b,sth_ret.c);


}
Reply:Here's the "complete" way to do it.





#include%26lt;iostream%26gt;





using std::cin;


using std::cout;


using std::endl;








void Return2variables(int %26amp;variable1, int %26amp;variable2);





int main()


{


int variable1;


int variable2;





cout %26lt;%26lt; "Enter a variable: ";


cin %26gt;%26gt; variable1;





cout %26lt;%26lt; "Enter another variable: ";


cin %26gt;%26gt; variable2;





Return2variables(variable1, variable2);





cout %26lt;%26lt; endl %26lt;%26lt; endl;


cout %26lt;%26lt; "You have exited the function and now you're in main function" %26lt;%26lt; endl;


cout %26lt;%26lt; "Here are the variables after they got converted: ";


cout %26lt;%26lt; variable1 %26lt;%26lt; "," %26lt;%26lt; variable2 %26lt;%26lt; endl;





system("PAUSE");


return 0;


}





void Return2variables(int %26amp;variable1, int %26amp;variable2)


{


cout %26lt;%26lt; "You're in the function" %26lt;%26lt; endl;


cout %26lt;%26lt; "These are the variables before they get converted: ";


cout %26lt;%26lt; variable1 %26lt;%26lt; "," %26lt;%26lt; variable2 %26lt;%26lt; "," %26lt;%26lt; endl;





variable1 = 17;


variable2 = 18;





}
Reply:I don't really use C, but you could probably do this by returning an array or some type of object.
Reply:All the answerers here are terrible. Some of you give misguided answers. The code many of you write is flawed. If you don't know C, don't write a wrong answer. Please stop. It's one thing to be a poor programmer yourself, don't make others bad.





http://c-faq.com/misc/multretval.html





A structure is probably easiest. If you're using pointers, have pointers passed in through the function arguments, and then modify the values pointed to by the pointers.





Be careful of returning pointers. If you declare a variable on the stack, pointers to it won't be valid after the function returns. So if you're returning pointers, make sure they point to memory on the heap.


C++ Programming Help. Need a Program?

My problem to solve is:





The C++ standard template library contains a %26lt;string%26gt; class that can be used to handle strings. String functions that exist in the C library %26lt;string.h%26gt; are replaced by member functions of the %26lt;string%26gt; class. This project requires your own implementation of a simplified string class, called mystring. The class should contain all the basic string handling functions, as well as overloaded operators for some manipulations. All member functions should use basic operations. Make use of pointers where possible. Do not use functions from %26lt;string.h%26gt;.





A driver program must also be included to test all the functions. It should display a menu and complete instructions to the user.





Anyone whose willing to do this program just type the answer for the problem and post it. I will be proud that you made this programme for me. Pls Help. I need within 2 days

C++ Programming Help. Need a Program?
And I will be proud that you gave your paycheck to me.
Reply:You can find someone to help you from http://k.aplis.net/


C++ Programming.?

The C++ standard template library contains a %26lt;string%26gt; class that can be used to handle strings. String functions that exist in the C library %26lt;string.h%26gt; are replaced by member functions of the %26lt;string%26gt; class. This project requires your own implementation of a simplified string class, called mystring. The class should contain all the basic string handling functions, as well as overloaded operators for some manipulations. All member functions should use basic operations. Make use of pointers where possible. Do not use functions from %26lt;string.h%26gt;.





A driver program must also be included to test all the functions. It should display a menu and complete instructions to the user.





Anyone whose willing to do this program just type the answer for the problem and post it. I will be proud that you made this programme for me. Pls Help. I need within 1 day

C++ Programming.?
I've got one right here but I cant post it, I sorry kid, my conscience wont let me do you homework for you for free as you so elegantly explain it.





You even explain how your too lazy to search for it yoursef, I know there are like a billion string classes out there.





Give us what you've come up with any we'll help you if not good luck!
Reply:Wow. How do you expect to pass your class if you don't do this yourself? Or if you can't even use google to look for the answer yourself?
Reply:good luck with the AP CS class in High School.





That was one of the easiest things to learn.

survey for money

Please give a few C/C++ questions on the topics............?

I need a few questions for writing programs in c/c++ on the following topics (its a college assignment !!!! )


structures, linked lists, class, arrays, strings, functions, pointers, file input/output. The questions should not be from any book preferable (or if it is, then please specify the name of the book). Thanks.

Please give a few C/C++ questions on the topics............?
1. Perform recursive binary search and Linear search. Hence find the time required to search an element.





2. Sort a given set of elements using the Heapsort method.





3. a)Sort a given set of elements using Merge Sort Method.


b)Check whether a given graph is connected or not using DFS method.





4. Sort a given set of elements using selection sort and hence find the time required to sort elements.





5. a) Obtain the Topological ordering of vertices in a given digraph.


b)Soft a given set of elements using Insertion sort method.





6. Implement 0/1 Knapsack problem using dynamic programming.





7. From a given vertex in a weighted connected graph, find shortest paths to other vertices using Dijkstra’s algorithm.





8. Sort a given set of elements using Quick sort method.





9. Find minimum Cost spanning Tree of a given undirected graph using Kruskal’s algorithm.





10. a)Print all the nodes reachable from a given starting node in a digraph using Breadth First Search method.


b)Implement all pair shortest paths problem using Floyd’s algorithm.





11. Find a subset of a given set S = {s1, s2,….,sn} of n positive integers whose sum is equal to a given positive integer d. For example, if S = {1,2,5,6,8} and d=9 there are two solutions {1,2,6} and {1,8}. A suitable message is to be displayed if the given problem instance doesn’t have a solution.





12. a) Implement Horspool algorithm for string matching.


b) Find the Binomial Co-efficient using Dynamic Programming.





13. Find minimum Cost spanning Tree of a given undirected graph using Prims algorithm.





14. a)Print all the nodes reachable from a given starting node in a given digraph using Depth First Search method.


b) Compute the transitive closure of a given directed graph using Warshall’s algorithm. Implement N Queen’s problem using Back Tracking.





write a c++ program to create a class called STRING and implement the following operations. Display the results after every operation by overloading the operator %26lt;%26lt;.


a. string s1=”aaa”.


b. String s2=”dddddd”.


c. String s3=s1+s2 (use copy constructor).





.Check whether a given graph is connected or disconnected using Depth First Search Method





write a c++ program to create a class called matrix using a two dimensional array of integers. Implement the following operations by overloading the operator == which checks the compatibility of two matices to be added and subtracted. Perform the addition and subtraction by overloading the operators + and - respectively. Display the results by overloading the operator %26lt;%26lt;


if(m1==m2)


{


m3=m1+m2;


m4=m1-m2;


}


else


display error








Write a C++ program to create a class called bin tree with member functions to perform inorder ,postorder,preorder traversals.Create a binary tree object to demonstrate traversals.





these are lab programs for 3rd sem engg
Reply:http://yepoocha.blogspot.com


might help Report It

Reply:how to program a perfect diamond using c++


the output is like this








enter a character:___A____(enter a character to use ex. A)


enter size :____5___(enter the how many characters in the center or its size)








______A


_____AAA


____AAAAA


_____AAA


______A





( "_" the underscore there is a space)
Reply:May be you can contact a C++ expert at websites like http://askexpert.info/
Reply:C++++++++++++++++++++++++++


+++++++++++++++++++++++++++


+++++++++++++++++++++++++++


Making a GUI in C++?

I'm a beginner in C++ and I am currently taking a intro class for my computer engineering degree. We just got into pointers and classes so I guess that's still the intro stage. My question is for you advanced programmers out is what is there to learn after you master the basics like after classes, arrays, pointers ect? What are more topics to learn? I want to learn how to make a windows GUI like where you click "ok" "exit" ect. like a visual basic sort of program using C++. How would you learn that? Is there any good online resource or book I can buy? This is still far off from my skills but it never hurts to look ahead.

Making a GUI in C++?
You should definitely learn the Windows API before you start making GUIs with .NET or a GUI builder. If you go right in and do them like in VB, you won't learn that much (and if you have the curiosity to look ahead, I'll assume you probably want to really learn what you're doing).





It's very hard, and it takes a lot of code to even bring up a window. You have to learn a little about how windows works under the hood.





With that said, when you get a solid grasp of C++, read this tutorial. http://www.winprog.org/tutorial/start.ht... This tutorial is for the C language, not C++, but everything is pretty much the same, and when you get to the level where you can understand what's going on, that aspect shouldn't be a problem.





Good luck!
Reply:Learn Win32 API - it gives you full power to create anything you want in Windows. It is a bit complicated though. Gonna take you ~60-70 lines of code just to display "Hello World" but it is worth it. The one and only book you need is "Programming Windows 5th edition" by Charles Petzold.





Your other option is to learn C# and use .NET to create GUI's. Oh, and one more thing, stay away from MFC (Microsoft Foundation Classes)!


Write a function in C to split a list into two sub-list using pointers?

There's not enough information, what type of list, I don't think you mean an Enumerated List, and into what type of split, are you talking about linked lists, or something like indexing using trees to navigate or manage keys?

Write a function in C to split a list into two sub-list using pointers?
data structure, you are reading, good,
Reply:For i=0 to 10


who_cares=me


Next


C-programming l as a beginner i need help here. this is the question:?

Write a C program tha t p rint s the character s in a s t ring in rever se order.


char s[10] = "abcdefg";


char* cptr;


i can do without the pointers. which is simple but i need someone to use pointers!!!

C-programming l as a beginner i need help here. this is the question:?
try this:


#include "stdio.h"


#include "stdlib.h"


int main(){


printf("type a string:\n");


char* s = malloc(1);


int c = 0;


*s = getchar();


while(s[c] != '\n'){


c++;


s = realloc(s,c + 1);


s[c] = getchar();


}/*this gives a string, terminated by a newline*/


while(c != -1){


putchar(s[c]);


c--;


}


free(s);


}


but srsly, don't expect me or my fellow professionals to help you all the time!
Reply:Do you understand what the pointer is? My guess is that you are a little confused about that.





You probably have already learned that C does not have a variable to type string. One way to build a string is to use an array. In C, an array is a group of memory addresses that are next to each other (what is important is that the addresses are next to each other). Now, you don't know which memory addresses in your computer store this array. If you knew, you could go to the end of the array and print the value in the address. You would repeat this for the previous address, and so on until you got to the first address.





Like I said, YOU don't know where the array is stored, but your computer does. Use a pointer to look at (point to) the first element of the array. By incrementing the pointer, you look at the next memory address. So if you can find the end of the string (\0), you can decrement the pointer to look at the previous memory address.





Hope this makes sens.
Reply:Keep asking people to do your homework for you and you'll always fail in programming :P
Reply:Have you tried _anything_ yet?





int i = strlen(s);


char *cptr = %26amp;s[i - 1];





printf ("fwd: %s\n", s);


printf ("rev: ");


while(cptr %26gt;= s) {


printf("%c", *cptr--);


}


printf("\n");

survey questions

C++ help! Can anyone tell me the books that are sequential in learning C++ from basic to most advanced.?

I want to learn a programming language, so I thought to go for C++.


As a CS major, I took introductory programming class where I learned making classes, and the concept of pointers.


But still, would like to start right from base to reach the very roof. What are books that you C++ developers or learners would recommend me. I understand that it may take 3, 4 to 5 books.


Thank you

C++ help! Can anyone tell me the books that are sequential in learning C++ from basic to most advanced.?
Beginner's C++ Books:


http://accu.org/index.php/book_reviews?u...


Advanced C++ Books:


http://accu.org/index.php/book_reviews?u...





Start with C++ Primer by Lippman or Accelerated C++ by Koenig. They will get you the fundamentals of C++ from which you can polish your knowledge.





Once you've gone through those books, you'll want to get books like Modern C++ Design, Exceptional C++, Exceptional C++ Style, and Efficient C++. There's a few other books you may consider keeping like "The C++ Standard Library". If you're serious about C++, you'll definitely want a copy of "The C++ Programming Language", get the Special Edition. It's by Stroustrup, *the* authority on C++.
Reply:the book is called "C++: An Introduction to Computing". Not for sure but I believe the author is Larry Nyhoff
Reply:This is so hard


go to amazon.com





i took the class and didnt learn anything i ended up getting C grade
Reply:I don't know of any books, but I do know of a great website: Planet Source Code. http://www.pscode.com - has everything from simple subs and functions to complete applications - all in source code form (you have to have the IDE on your system in order to run them)
Reply:First you should start with "Teach Yourself C++" by Robert Lafore. This is an excellent book which gives you top to bottom description for each feature of C++ language in easy language and with easiest and practical examples. Once you will complete this book you will be confident to do programming in C++.





Then you should start learning "The Complete Reference: C++" By Herbert Schildt. This is an advance book which describes all the feature in much depth.





I think "Teach Yourself C++" by Robert Lafore is enough to make you confident about C++ programming. You should use "The Complete Reference: C++" in future use while advance programming in C++.





Happy learning...
Reply:all the e-books of C and C++ and source examples in a CD.


you may write me for it.
Reply:C++ Primer by Lippman


Factoring with C programming?

I am trying to write a C programming code to factor between 1-100. Can anyone give some hints/pointers to solve this?

Factoring with C programming?
Check out this small Javascript I made that does what you want.





http://answers.yahoo.com/question/index;...





I wouldn't use that script for large numbers because it is horribly inefficient, but for small numbers it works well enough. All you would need to do is convert it to C.
Reply:Can u please clarify the question with inputs and outputs. Are you trying to find out the factors of a given number? e.g .if input is 65 output is 5,13.
Reply:Are you sure that description is correct? You can't factor a prime by definition.
Reply:Factoring as in factorising a number?


To check if A is divisible by B, try it! If the result is an integer, then you have found a factor!!! If no factors are found, the result is prime. You only ever need check for prime factors, and only ever for factors less than or equal to the square root of the number you are checking. Refer back to your school maths textbooks for more info.





Rawlyn.





In response to your additional remarks: A prime number by it's own definition has only two factors - itself and one. Therefore factorising primes is a trivial matter, not something you need to write a program to do. Try reading my post again, all the information you need is right there.


Learning troubles about C++?

I am newbie in C++ programming.





I am learnging programming in C++. I have read through some websites and books. I thought out the following questions. Please help!





I want to use MS visual C++ to program.


1/ What is the difference between .c and .cpp?


2/ Does the c codes got from the internet work properly in MSVC++?


3/ I saw two different types of pointers: ^ or *. What are the differences?

Learning troubles about C++?
1). .c is the extension for C source code files while .cpp is the extension for C++ source code files. The main difference between C and C++ is that C isn't object oriented while C++ is.


2). Not all of them work on Microsoft Visual C++. If you installed the latest 2005 or 2003 edition, the syntax for it is a bit different (because it only compiles on .NET platform).


3). There are two types of pointers in C++:


- the reference operator (%26amp;)


- the dereference operator (*)


The address that locates a variable within memory is a reference to that variable. For example:


int* x;


int y=10;


x=%26amp;y; // x will pointer the memory location where y is located.


Using a pointer you can directly access the value stored in the variable which it points to. To do this, you simply have to precede the pointer's identifier with an asterisk (*), which acts as dereference operator and that can be literally translated to "value pointed by".


int *p1,*p2;


*p1=10; //value pointed by p1 is 10


*p2=*p1; //p2 and p2 point the same value


p2=p1; //the pointers are being copied





Hope it helps.. If you have any questions please e-mail me
Reply:1) .c is for C language, .cpp is for C++ language, it's just a file extension, there's nothing preventing you from putting C++ compatible code in a .c file and compiling it using a C++ compiler.





2) Usually, code from the internet might need to be modified slightly to work correctly. Sometimes function names change, or OS version changes will cause code to need to be modified to work.





3) * is the standard C / C++ pointer operator. In .net, you can do managed C++ which uses the ^ pointer operator. By default in languages like C# and VB.net, all class instances are actually pointers using the managed pointer operator (^). In traditional C++, you will never use the managed pointer operator because it is .net and Microsoft specific.
Reply:1


.c for c files


.cpp for c++ files


2


you must not find anything wrong, it will work properly


3


i think both are the same
Reply:I think there is a code in c for dos that don't run in MSVC++





For me it's very hard to code on MSVC++ because if you forgot one code it will display many error which sometimes confused you.


Why do i need to derefence pointers when passing them to a function in the C languge?

Because a pointer is also a value that is perfectly legitimate to send into a function. Because you might be trying to actually send the pointer instead of the value that the pointer points to.





That would be called "pass by reference".


Example:





void PassByReferenceFunction( int * referenceToInt )


{


printf("I got %d!\n",*referenceToInt);


}





void main()


{


int value=10;


int * referenceToValue = %26amp;value;


PassByReferenceFunction( referenceToValue );


}





As you can see, we can pass the pointer into the function, and we can get the value by using the * operator before the pointer. This is very useful if we want the function to change the value of multiple parameters and have them stay changed when you return.





I imagine what you are doing is "pass by value".





Example:


void PassByValueFunction( int value )


{


printf("I got %d!\n", value);


}





void main()


{


int value=10;


int * referenceToValue = %26amp;value;





PassByValueFunction( *referenceToValue );


}





In this case, we are dereferencing the pointer outside of the function (in the function call) when we send "*referenceToValue" as the parameter to PassByValueFunction.





C (as opposed to C++) by default gives you a lot of leeway to mix and match types for your own purposes. It's very low level... it assumes you know what you are doing. Maybe you WANT the value of the pointer instead of what it points to. This is very powerful, especially when you are accessing hardware directly. Pointers are the most basic and powerful concept in C coding.

surveys

C++! Can anyone tell me the books that are sequential in learning C++ from basic to most advanced?

I want to learn a programming language, so I thought to go for C++.


As a CS major, I took introductory programming class where I learned making classes, and the concept of pointers.


But still, I would like to start from base and reach to the very roof of C++.


What are books that you C++ developers or learners would recommend me for this SEQUENTIAL ASCENT . I understand that it may take 3, 4 to 5 books.


Please provide me a good sequential list.


Thank you

C++! Can anyone tell me the books that are sequential in learning C++ from basic to most advanced?
First you should start with "Teach Yourself C++" by Robert Lafore. This is an excellent book which gives you top to bottom description for each feature of C++ language in easy language and with easiest and practical examples. Once you will complete this book you will be confident to do programming in C++.





Then you should start learning "The Complete Reference: C++" By Herbert Schildt. This is an advance book which describes all the feature in much depth.





I think "Teach Yourself C++" by Robert Lafore is enough to make you confident about C++ programming. You should use "The Complete Reference: C++" in future use while advance programming in C++.





Happy learning...
Reply:Prime C++ should be one of the must-read c++ books
Reply:I learned from "Starting out with C++" by Tony Gaddis, and I like the way he goes step to step, that 's why to learn Visual Basic I opt to by book written by him again. And this book is for starter .


Hope this help.


Want a website where i can get very good tutorials on C++?

don't understand classes and objects and pointers


want aslso a site where i can get excellent C++ source codes

Want a website where i can get very good tutorials on C++?
for understanding c++ from the basics try this site





www.geocities.com/sstutor





trust me its the best c++ tutorial site on the net





for source codes check out these links..





http://www.planet-source-code.com/vb/def...


http://www.vyomworld.com/source/Language...





happy learning
Reply:Have u tried going to CNET.com or download.com or even better searched on YouTube.com! u know u can easily find videos in these places





Cheers!
Reply:try http://www.cs.wustl.edu/~schmidt/C++/


or http://www.sourcecodesworld.com/source/L...
Reply:http://www.cplusplus.com
Reply:I would look at codeguru.com


C programming... Please help....Thanks?

Develop a C-code that calculates the following summation:





sum =0.5f0 + 0.5fN + Sigma(summation) from n=1 to N-1 of fi





Note : 0, N and i are subscripts.





where fi = f(xi) is a function. Choose ONE of the following functions:





f(x) = xe^x and epsilon ranges from 0 to 10.





and carry out the above summation using N = 21 and N = 41, to. Print out all and the results of summation using the above formula.





Your C-code must contain the following features: (1) use of arrays, (2) use of pointers, (3) use of structure, (4) use of union, (5) use of functions and function calls, (6) formatted output on screen and (7) saving of the same output on a file.

C programming... Please help....Thanks?
You just need to use a for loop, not that difficult.


I am asking for a good and very advance C programming reference?

i need a refrence (book or e-book) include not only pointers, classes and ......


but also system calls, threads, hardware instruction, C over UNIX and ......

I am asking for a good and very advance C programming reference?
You can check free ebooks websites like http://myitcareer.org/

survey monkey

Need help in c programming (not C# or C++)?

i need to write a function reverse_string, whose prototype is


void reverse_string( char * string). i need to use pointers rather than arrays and subscripts, and do not use the C library functions. this function should take the following as input and prints it reversed to stdout

Need help in c programming (not C# or C++)?
void reverse_string(char* string)


{


char* ptr = string;


char c = *ptr;


if(c != '\0')


{


reverse_string(++ptr);


printf("%c",c); // if %c is format symbol for type char...


}


}





this should work I think...it's a recursive thing...
Reply:off handed solution..





try something like


for(i=0,j=strlen(string);i%26lt;=j;++i,++j)


{


swap string[i] and string[j]


}





homework question eh? If I didn't suspect so, I'd have written out a working code ;)
Reply:Probably not an elegant solution, but you could do the following:





1. Using a While loop, locate the '/0' indicating the end of the string. You can count the number of characters, starting with 0 (stored in int x for this example).





2. Make a new "char * newString"





3. Run through a For loop "for(int i = 0; i %26lt; x; i++)





4. Build the newString setting the i-th character equal to string's (x-i)-th character. Sorry, it's late and I don't recall pointer math right now, so I can't write down the proper syntax for this


C++ beginners question??

Im a beginner to the new C++ code language and i was wondering what are classes and pointers and functions and what do they do. Pls give examples.


ALso what is the Win32 API and how do i use it or create it whatever.


PLS note: I am a beginner NO TEASING.

C++ beginners question??
fristly Classes :


you can create your own classes, the purpose in designing classes is, if you want to work as software designer, once you create a class any other user can use its properties easily we as designer just make things easy.





the class contains its own variables, functions, and constructor.





Secondly Pointers:


the array is a pointer, but created through c++ developers, in the array list if you have 10 cells you cant delete or remove the 7th cell but in pointer you can, and connect the 6th cell with 8th cell, and also pointers save memory.





Thirdly Functions:


rather than writing a large code in "void main" you can easily divid your code into pieces that what function does.





if you want any thing Specifically contact me.





and good luck.
Reply:check out www.functionX.com


it has great tutorials
Reply:The items you asked about are fundamental. To keep it simple I am going to avoid code and just explain the concepts. If you understand this learning how to code will be easier. Pointers are what make C++ and C such poweful languages. A pointer is just it is a place set aside in memory that points to another place in memory. What are pointers good for it may help to consider a classic example. You have a paper with the address to a house it is not the house but it points to the location. If you want something in that house the address would very usefull. In C++ and C strings are null terminated arrays. All elements in an array are place next to each other. So a pointer to a variable of type char would be the beginning of your string. To understand what else you can do with pointers it would help to understand the other two language elements you talked about. Lets start with functions. A function is a small program within a program. Functions are sets of statements organized to perform some task in a program. You can also pass information for the function to act on. This information passed to the function is called parameters. Here is how you might use it. Lets pretend you are writing a program that is going to be the next great thing in rocket science. This means you are doing alot of math with exponents. So you may want to have some part of the program there to do this. You would pass the number and the power you wanted to raise it to. You program would then multiply that number the number of time you sepcified in the power parameter and return the number back to the program. In many programming languages functions are required to return a value. In the languages that force you to return a value they provide a mechnisim to group statements that just perform some desirable task these they call subroutines. C++ makes no such distinction subroutines and functions are one and the same. The catch is that when you declare a function you must declare the type of value that the function returns. C++ provides a special type for a function that is a subroutine and returns no values the type is void. Objects are not that hard once you look around you . You see a monitor that you are looking at this content on a light on your desk perhaps a phone. That all objects are they are just a way of describing things. Objects have chacteristics like color, brandname maybe some others. Charchterisits in object lingo are properties Objects may have other objects as part of them for instance a lamp object has a switch object. Objects also can be acted upon you could for instance push the switch. These actions are called events. The event may cause somethings to happen like the bulb emit light the function that the event calls to illuminate is a method. Occasionally there are goups of objects that share charcteristics like a car and a boat they both speed up and slow down. They both turn left a turn right. Although these are the same action a car is not a boat. But wouldn't it be nice if you could describe what both things have in common in a class and have both use them. The answer is inheritance a car is not a boat but both a car and a boat are vehicles. In the vehicle class I could describe these actions have the car and boat inherit that and then go on and just describe car what is unique to car and in boat what is unique to boat. car.pressBrake Boat.dropAnchor. Often times people will have groups of classes and functions they use over and over again in different programs so they will group them together in one file they then will compile this file so that they are already machine code. These files are the infamous dll's. The Win32 API is a collection of these dll's to expose various windows services. There are some for file management some for network management, some that control hardware. You declare which dll you are going to use then call the functions that you want to use as if you wrote it in you own program. Win32 API stands for Windows 32 bit Application Interface. I know this is pretty simplified without code but if you know what it is, then understanding the code that you are reading about is easier. I hope this helps