Friday, July 31, 2009

Given real numbers a,b,c,d, let, f : R(squared) go to R(squared) be defined by f(x, y) = (ax+by, cx+dy)?

How to prove that f is injective if and only if (iff) f is surjective.

Given real numbers a,b,c,d, let, f : R(squared) go to R(squared) be defined by f(x, y) = (ax+by, cx+dy)?
suppose that f is injective,


to prove: f is surjective





if f is injective then


f(1,0) = (a,c)


and


f(0,1) = ( b,d) are linearly independent vectors.


but since the dimension of R^2 is 2, then these vectors are a basis, and so


any vector (z,w) can be written as a linear combination of (a,c) and (b,d)


(z,w) = A(a,c) + B(b,d)


=( Aa + Bb, Ac+Bd)


take (x,y) = (A,B)


then f(x,y) = ( Aa + Bb, Ac+Bd) = (z,w)


thefore f is surjective.





If f is surjective, then any vector (z,w) = f(x,y) for some (x,y).


Hey guys n gals need someone good in c to take on this one will send u my feedback after ur result thanks?

How can one Implement a function in C that takes an array of integers,%26amp; and reverses the order of items in the


The function you implement must have the following form:


void reverse_order(int array[], int n)


{


/* your code goes here: re-order the n items in the array so that the


first one becomes the last


* * and the last one first.


*/


}


You should then implement a main() function which reads in a set of integers into an array,


reverses the order of the number (using the function you have just defined) and prints them out


again.


For example, when complete and compiled, you should be able to run your program, and enter


the numbers:


2 4 5 11 23 1 4


then program will then print out:


4 1 23 11 5 4 2





make sure your program will allow the user enter the numbers and then gives the output as their reverse

Hey guys n gals need someone good in c to take on this one will send u my feedback after ur result thanks?
do your own homework. this is actually a very easy exercise - a simple loop is all that is needed.

nobile

In C#, how can you access only the selected text in a cell defined by the DataGridTextBoxColumn class?

For example, if a textbox in a DataGrid contains "little" but the user has only selected "li", how can I see programmatically that the user selected "li"?

In C#, how can you access only the selected text in a cell defined by the DataGridTextBoxColumn class?
Unfortunately, .NET doesn't have this as a built-in property or method for the DataGridTextBox control.





If you are working on a Web page, you could access that information client-side via JavaScript's Selected property.


When he became president, Franklin D. Roosevelt a,b,c,or d?

a. was a self amde man businessman who had little sympathy for disadvantaged americans


b. had to convince businessmen that government had a role to play in ending the depression


c. had a progresssives faith in the power of government to solve problems


d. had a clearly defined program that he was convinced would end the depression

When he became president, Franklin D. Roosevelt a,b,c,or d?
B
Reply:B
Reply:D, but he still got frustrated
Reply:b.
Reply:B and D
Reply:d.


How to pass arrays in functions in C++?

I want to pass arrays in the function I write in C++. How to do that? When I pass single variable, its easy. But when arrays are taken as input the size have to be defined in the first place. Please help.

How to pass arrays in functions in C++?
There are a few ways to do this, not one. Let us look at them:





1. The straightforward way: Say you have an int [] array that you want to pass to a function func(). You can define func() like this:





void func( int [] iArrayParam, int iArrayLength )


{...}





Note: The above definition is same as


void func( int * iArrayParam, int iArrayLength )


{...}





Then, from the calling function, you can call func() with the array as the 1st argument, and its length as the 2nd. Like:





...


int iArray[ 5 ] = { 34, 35, 0, 2, 41 };


...


func( iArray, 5 };


....





2. The above method is crude and naive. Some people like to be more sophisticated and instead of passing the length, they populate the array with a delimiter value. Because inside func(), you will probably traverse the array and that is WHY you need to know the length. But you can also traverse an array if you, instead of the length, knew the last value.





This is how it works: Say you need to pass an int array to func(). You need to pass the 5 values 34, 35, 0, 2, 41 in it. So, from the calling function, you crate an array of length 6 (not 5). In the last place, you put a value like -1. Be careful while choosing this value - it must be a value which the other elements CANNOT BE. I mean you can choose -1 ONLY IF implementation logic prevents any other element of the array to be -1. So, your func() looks like this:





void func( int * iArrayParam )


{


...


int iCnt = 0;


while( iArrayParam[ iCnt ] != -1 )


{


//Do something with iArrayParam[ iCnt ]...


//Note that you aren't using array length to traverse.


}


...


}





And you call it like this:


...


int * iArray = new int [6];


iArray[0] = 34;iArray[1] = 35;iArray[2] = 0;


iArray[3] = 2;iArray[4] = 41;


iArray[5] = -1; //This is the delimiter value


func( iArray );


...





3. The above method (#2) is what C++ uses in strings - A C style string always ends in NULL ('\0'). So basically when you pass a string (which is nothing buta char array) to a function, you do not state its length - because there is an unstated understanding between the functions that the array will end in a string null - ASCII zero.





Lastly, it is your imagination. Func() needs some way to know where the passed array ends. You, as developer, can devise more and more clever ways to tell that to func(). You can create a class that encapsulates the array and also holds the array length as a public property. But before you get all excited and start writing such a class, hold on! That has already been done! Why not use STL vector instead of a simple array?





So instead of using int[], all you do is #include %26lt;vector%26gt; and may be write





using namespace std;





on top, and declare and populate:





vector%26lt;int%26gt; vMyIntegerArray;


vMyIntegerArray.push_back( 34 );


vMyIntegerArray.push_back( 35 );


...





Finally, pas it to func, which looks like:





void func( vector%26lt;int%26gt; v )


{


//Use v.length() to access the length of the array, oops, vector


}
Reply:The easiest solution is to pass a pointer to the array, and to specify the size of the array in other variables.





If you want, you can create a structure that holds both the size of the array and the array contents, and pass a pointer to the structure. That's basically how Turbo Pascal handles strings - the first byte of the structure specifies the length of the string, and the rest of the structure holds the string itself.





When you pass variables in C (and consequently in C++), you are copying those variables to the stack. When you have an array, that's not only slow and inefficient, you may also run out of stack.





In C, there is no difference between arrayname[5] and 5[arrayname]. The compiler simply adds together arrayname and 5 together, using pointer arithmetic, and then dereferences the pointer. Multi-dimensional arrays are actually single-dimensional arrays; that's why you have to declare the size of a multi-dimentional array. Without the declaration, there's no way for the compiler to calculate whether arrayname[5][3] is actually arrayname[83] or arrayname [123].





You might want to ignore Mantrid's answer; he doesn't seem to understand that there's a difference between an array and an ASCIIZ string. You have to pass the size when you are passing an array.
Reply:If you're talking about C-style arrays and not STL ones, you can pass a pointer to the first element of the array. example-





void toUpperCase( char* ptr)


{


int i =0;


while (ptr[i] != 0)


{


ptr[i] = toupper(ptr[i]);


++i;


}


}
Reply:Pass pointers, array == pointer in C/C++


Can anyone please help me with this C program??

Write a program to transform its input according to a specified transformation scheme. The transformation scheme will consist of two strings: a string of characters and then a string of replacement characters. The idea is that your program replaces every instance of the ith character in the initial string with the (i+3) character (of English alphabets) in the replacement string. When no substitution is defined for a character, the program just passes it through to the output unchanged. The program should inform the user of any errors in the transformation scheme. Your program should display the phrase before and after the substitutions have been made.


Example:


Original String: This is a C program.


String after the transformation: Wklv lv d F Surjudp.

Can anyone please help me with this C program??
The function is as under:





void transform(char str[100])


{


int i;


for(i=0;i%26lt;strlen(str);i++)


{


if((str[i]%26gt;=65 %26amp;%26amp; str[i]%26lt;=87)||


(str[i]%26gt;=97)%26amp;%26amp;(str[i]%26lt;=119))


{


str[i]+=3;


}


}


}





NOTE : ASCII code for A is 65 and W is 87, a is 97 and w is 119.





The main function :


void main()


{


char c[100];


printf("Enter a string:");


scanf("%s",c);


printf("Original string:%s",c);


transform(c);


printf("String after the transformation is:%s",c);


}
Reply:I don't normally program in C but I will give you the general idea in Java:


first create an array with the 26 alphabet characters.


so to find the letter we can call the array[n]


where n is the number associated with the letter starting with 0, because arrays always start with index 0.


We need to change the original string so that we can read it.


To do so we need to take each letter and find the length of the whole string.





function String replace(String originalS)


{


int stringLength = originalS.length(); //length of the string


char array1[] = new array[26]; //create the array class with 26


array1[] = {'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'};


//lets make the original String into a char array


char array2[] = originalS.toCharArray();


//now we have filled the array class with the characters


String finalS = new String("");


//we initialize a final string here for later


//now we can do a bunch of for loops to each string character


//this loop will traverse through the original string


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


{


//this loop will traverse through array1 and check it


for(int j = 0; j %26lt; array1[].length; j++)


{


if(array2[j] == ' ')


{


finalS += " "; //we add a space if the original had a space


break; //we break the inserted for loop


}


else if(array2[j].toLowerCase() == array1[j])


{


if(array2[j].isUpperCase())


{


try


{


finalS += array1[j+3].toString().toUpperCase();


}


catch(Exception e)


{


//now we know that the letter is either x, y, or z


finalS += array1[j+3-26].toString().toUpperCase();


}


}


else


{


try


{


finalS += array1[j+3].toString().toLowerCase();


}


catch(Exception e)


{


//now we know that the letter is either x, y, or z


finalS += array1[j+3-26].toString().toLowerCase();


}


}


break; //breaks the inserted for loop


}


else


{


finalS += array2[j].toString();


//if the character is not a letter just keep it the same and add it to finalS


}


}


}


return finalS; //returns the output string


}
Reply:I hope this is the program. If you have problem compiling call me at m_gopi_m@yahoo.co.in





/*


Please create a new folder and place this program in it. It creates


Two text documents(first.txt and second.txt).





first.txt is a copy of the input stream.


second.txt is a copy of encryption.


repalaces ith term by i+3 terms.





Please do not use any special keys like delete,backspace etc...





If you want to change the encryption number. Change 'num' variable(int)


present at 23:14.


*/








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


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





void main()


{


FILE *fp1,*fp2;


char a,b;


int num=3,i;





clrscr();


printf("\n\nEnter your message:\n%26lt;When you do so press enter%26gt;");


printf("\n%26lt;Please avoid special characters%26gt;\n\n\t");





fp1=fopen("first.txt","wt+");


while(a!=13)


{


a=getche();


if(a==0)


{


getch();


printf("\b\a");


}


else if(a==8)


{


printf("%c\a",b);


}


else


{


fputc(a,fp1);


b=a;


}


}


rewind(fp1);





fp2=fopen("second.txt","wt+");


while(a!=EOF)


{


a=fgetc(fp1);





if(a!=EOF %26amp;%26amp; a!='\0')


{


if(a!=' ')


a+=num;


fputc(a,fp2);


}


}


fclose(fp1);





rewind(fp2);


clrscr();


printf("\nThe resultant text is\n\n\t");





a=' ';


while(a!=EOF)


{


a=fgetc(fp2);


printf("%c",a);


}





gotoxy(1,22);





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


printf("%c%c%c%c%c%c",205,205,205,20...


printf("\nFor convenience the input data is saved in first.txt");


printf("\nThe encrypted data is saved in second.txt");


printf("\nPlease take a view at it.");





getch();


fclose(fp2);


}

flower girl dresses

In c++ what is basically the difference between derived data type and user defined data type ?

Derived data types defined by the system include pointer, array and reference. User defined derived datatypes are built on existing types. These include class, struct, union and enumerations.

In c++ what is basically the difference between derived data type and user defined data type ?
If I remember correctly, and I could be wrong, a derived data type is something that your program comes up with, like if you were making it do a calculation and then the answer would be the derived data type.


The user defined would be what the user enters when prompted.


Let R be an equivalence relation defined on a set A containing the elements a, b, c, and d.?

Prove that if aRb, cRd, and aRd, then bRc.

Let R be an equivalence relation defined on a set A containing the elements a, b, c, and d.?
aRb --%26gt; bRa (symmetric)





bRa and aRd --%26gt; bRd (transitive)





cRd --%26gt; dRc (symmetric)





Thus





bRd and dRc --%26gt; bRc. (transitive)





Hope this helps.


What is the best source to find a WinCE devel w C/C++, NDIS drivers, wireless network exp immed in Sil Valley?

A well defined project working with very capable people. Moonlighting is O.K. Development of a handheld device in the Silicon Valley CA area. We will go with any reasonably qualified contractor. The handheld is Windows CE development C/C++, NDIS drivers, wireless networking.

What is the best source to find a WinCE devel w C/C++, NDIS drivers, wireless network exp immed in Sil Valley?
Hi contact me if you are still looking for that developer. My e-mail is hhpcsolutions@yahoo.ca. Regards.





Pishoy
Reply:Try Monster.com


I need help with my c++ program?

This HW is regarding strings. The sample output looks like this





Enter your lines:


Write a C program that will process a series of "words"


entered by the user. A word (for the purpose of this


assignment) is defined as a sequence of non-white-space


characters (anything other than a space, a tab, or a


newline). The following activities should be performed


in the program, and on the data entered by the user.


Does all of this sound right? You betcha!





There were 66 words found.


The longest word was 'non-white-space'.


The longest length was 15 characters.


The shortest word was 'a'.


The shortest length was 1 characters.


There were 6 capitalized words.


There were 5 sentences.


The longest sentence had 26 words in it.


The shortest sentence had 2 words in it.


The average word length was 4 characters.





I just need help finding number of words in the longest and shortest sentence. And the average word length of all the sentences.


I just need h

I need help with my c++ program?
// I have made a few changes to your program. Here is what


// I have:








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





int main()


{


string word, largest, smallest;


int numWords = 0;


int capital = 0;


int sentences = 0;


int currentSentenceWords = 0;


int smallestSentence = 0;


int largestSentence = 0;


char lastchr;





// To the following while-loop condition you need to add


// something that would make the loop termintate such as:


// while (cin %26gt;%26gt; word %26amp;%26amp; word != "-1")


// so if the user enters -1 then there are no more words or


// sentences to be entered and so your program can display


// the results and terminate. It's up to you what the termintating


// condition should be.





while (cin %26gt;%26gt; word)


{


//cout %26lt;%26lt; words %26lt;%26lt; endl;


numWords++;


currentSentenceWords++;





if (word[0] %26gt;= 'A' %26amp;%26amp; word[0] %26lt;= 'Z')


capital++;





lastchr = word[word.length() - 1];


if(lastchr == '.' || lastchr == '?' || lastchr == '!')


{


sentences++;


if(sentences == 1)


smallestSentence = largestSentence = currentSentenceWords;


else if(currentSentenceWords %26lt; smallestSentence)


smallestSentence = currentSentenceWords ;


else if(currentSentenceWords %26gt; largestSentence)


largestSentence = currentSentenceWords;


currentSentenceWords = 0;


}





// NOTE THAT I HAVE CHANGED THE FOLLOWING IF


// STATEMENT FROM if(numWords == 0) TO


// if(numWords == 1)





if(numWords == 1)


largest = smallest = word;


else if(word.length() %26gt; largest.length())


largest = word;


else if(word.length() %26lt; smallest.length())


smallest = word;


}





return 0;


}








// To calculate the average just divide the number of words by


// the number of sentences (numWords / sentences)





// If you need more help please let me know.

flower garden

Can anyone hep me with this c programming question?

Write a program that implements a stack with at most 30 integer elements with operations push and pop as defined


below:


A. Declare an integer array with a size of 30 elements.


B. Write a function called push that will insert an integer into the array.


C. Write a function called pop that removes the top-most element in the array.


D. Write a main function that takes input from the user based on integers: 1 - PUSH; 2 - POP; 3 - EXIT. Whenever


the user enters 1 (for PUSH), the integer that follows it is the element to be pushed.


E. The program prints as output the elements of the stack at the end of input and prints the maximum size to


which the stack grew during the operation.

Can anyone hep me with this c programming question?
That is going to be quite difficult. If you are still stuck with your project assignment may be you can contact a C expert live at website like http://askexpert.info/ .


Using Linked Lists and STL in C++ to write a code , Who can Help ?

I want to write the following code in C++ , who can help me or give me some example or pre-written code about this topic ???





you will implement a class template called polynomial using linked lists and instantiate it by int. Each node in the linked list represents a term (such as -7x5) in the polynomial and contains at least the following member variables: the degree(the degree of the term) and coeff (the nonzero coefficient of the term). Note that you should only store nonzero coefficients. This means that if a coefficient goes to zero as a result of any operation, you must make sure that you delete that node.





In addition, you must make sure that the terms in the linked list are arranged in increasing order of their degree. Thus, the linked list corresponding to polynomial q(x) defined above must have nodes in the following order: node 1 representing term -5, node 2 representing the term 6x3, and node 3 representing the term -7x5.

Using Linked Lists and STL in C++ to write a code , Who can Help ?
I won't write the whole thing for you, but here is reasonable starting methodology for this type of problem :





// Begin Code





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








// Polynomial term definition ... you can use a class or typedef it


// instead if you'd prefer.





struct Polynomial_Term


{


int coefficient;


int exponent;


};





// Polynomial type definition using the list template of the STL.





typedef list%26lt;struct Polynomial_Term%26gt; Polynomial;





// End Code








So you'll declare a local variable of type Polynomial ... loop through adding your nodes using the list template methods (possibly tossing 0 coefficient terms at this stage before adding them to the Polynomial) ... then sort the Polynomial using the list template method and a sorting routine supplied by you (compare the exponents of both terms).





You can see the list template's header file in your compiler's includes ... but the STL headers are a bit messy and cumbersome. If you need resources to help you understand what methods are available and how to properly use them, do a Google search for "C++ STL list template".


Cited for 22350 V.C. in CA (Basic Speed Law) -- was clocked with LIDAR at 60 mph in a 40 mph zone on Feb. 3rd?

I was recently pulled over and cited with a 22350 V.C.('unsafe speed' is what the office wrote). This Violation Code is in reference to the 'Basic Speed Law' in California. The weather was partially sunny (no rain, no fog, no haze, no wind), the street is not defined as a 'local road', there were no cars within 200yds of my vehicle, the roadway is six lanes (3 lanes going North, and 3 going South, separated by a raised center divider). Can I beat this citation? Do I have enough proof that my speed was safe?





One note, when the officer was fishing for my incrimination, I did say, "I was driving way too fast" without saying exactly how fast I thought I was traveling. However, I said this in reference to the posted speed limit, and not the Basic Speed Law (as I had no idea it existed until later that evening).





Did I incriminate myself in this case by saying, "I was driving way too fast", even though that is in reference to the posted speed limit? Can I still beat this citation?

Cited for 22350 V.C. in CA (Basic Speed Law) -- was clocked with LIDAR at 60 mph in a 40 mph zone on Feb. 3rd?
I found myself in a similar situation no too long ago. I started looking into how to go about defusing the issue. I found this forum which upon first reading seemed to be quite promising. The link is as follows:





http://forums.nasioc.com/forums/showthre...





I believe this is a rather good method to use regardless of your situation. Good Luck. -Carb30


C++ help.......Back again...this time, i am kinda stuck on user defined functions. i almsot have it working...

#include%26lt;iostream%26gt;


#include%26lt;string%26gt;


#include%26lt;cctype%26gt;


using namespace std;


//getValue


int getValue(int value);


int value=0;


//getLetter


char getLetter(char letter);


char letter='y';


int main()


{


int thisYear=0;


int thisMonth=0;


int year=0;


int month=0;


int ageYear=0;


int ageMonth=0;


char again='y';


cout%26lt;%26lt;"This program asks you to enter today's year in 4 digits,\n";


cout%26lt;%26lt;"and today's month number in 2 digits.\n\n";


cout%26lt;%26lt;"Then it asks you to enter your birth year in 4 digits,\n";


cout%26lt;%26lt;"and your birth month number in 2 digits.\n\n";


cout%26lt;%26lt;"The program will calculate and display your age in years and months.\n";


cout%26lt;%26lt;getValue(thisYear);


cout%26lt;%26lt;getValue(thisMonth);


while (again=='y')


{


//assign to year value returned from getValue.


cout%26lt;%26lt;getValue(year);


//assign to month value returned from getValue.


cout%26lt;%26lt;getValue(month);


ageYear=thisYear-year;


ageMonth=thisMonth-month;


if(thisMonth%26lt;month)


{


ageYear=ageYear--;


ageMonth=ageMonth+12;


}

C++ help.......Back again...this time, i am kinda stuck on user defined functions. i almsot have it working...
where you are calling the gatValue ( year) and the other call you are passing an int down to the fuction. BUT the only getValue you have supplied takes a string as the param.





I think you want


int getValue () {


int i;


cin %26gt;%26gt; i // allow input


return(i); // and give to to the caller


}





then in your main you want


year = getValue( ) ;


cout %26lt;%26lt; year;





Good luck
Reply:Yep yep, you defined int getValue(string) and you are calling int getValue(int), so the linker is looking in all the files it is building for that function, is not finding it, and is coughing. The reason your code compiles is because you *declared* int getValue(int), but you *defined* int getValue(string).





The compiler does not actually match your function calls to the physical code, it just makes sure everything is syntactically and semantically correct. The linker does the heavy lifting of matching function calls with jumps to the right memory addresses.
Reply:int getValue(int) and ur defining method with following method name getValue(string); thats why it is giving err;

edible flowers

How much will a C+ in calculus affect my college chances?

I have a C+ in AP calculus AB for the semester (...hopefully) and it's the lowest grade I have ever received. That, and the B I received in Pre-calculus honors last year. I am not interested in math or anything, my recs are good, my extra-curriculars are pretty solid and I think my essays were good... also, my GPA as of last year is 3.98 (and I'm in a school system where an A is defined as 94-100..meaning it could be higher...) and my SAT score is pretty good. I'm not hoping for any Ivy leagues, but I am trying for UVa. and W%26amp;M... thoughts?


My grades in all my other classes, including APs, are either A's or B+'s...

How much will a C+ in calculus affect my college chances?
You have a really good chance of getting into a good college and depending on what year in high school you are you have some time to bring your GPA back if it drops just because of 1 C.
Reply:The danger is not the C, but the fact that you took AP calculus in high school. This is perhaps the most dangerous course for anyone to take if you're planning to take mathematics in college, because it makes you think you know more than you do. High-school calculus courses are, in general, rotten: they treat their students like trained monkeys, teaching them to do a couple of nifty-looking tricks without the poor kids understanding what they're actually doing. It entertains the parents and the teacher, but it makes life very tough for any math teacher they get in the future.


"if" statements in Visual C++ (Microsoft VC++ 2008)?

I'm trying to self-teach (myself) visual C++, and i'm starting with a simple calculator. i'm trying to ask the user to input how to calculate an answer, but i'm having trouble with the if statements. heres my source code for that part:





cout %26lt;%26lt; "Ok,\n Would you like to Add, Subtract, Multiply or Divide?\n\n";


int type = 0;


int add = ;


int subtract = ;


cin %26gt;%26gt; type;


if ( type == add ) {


cout %26lt;%26lt; TotalPlus;


}


elseif ( type == subtract ) {


cout %26lt;%26lt; TotalMinus


}





I have no idea what to put in the int add and int subtract. any help? I have defined all the intigers and totals exc. above, i didnt include that code for the sake of character space on the question's body paragraph.

"if" statements in Visual C++ (Microsoft VC++ 2008)?
What does the user enter to say they want to add? You didn't tell them what to enter. As a result, there's no way to say what the value of "add" or "subtract" should be.





If you prompt with "Enter 1 to add or 2 to subtract" then you could say add = 1 and subtract = 2.





Otherwise I don't know what to tell you.
Reply:What you want to do is use integers to get a function. You would half to use a enum. Dont do that.





#include %26lt;string%26gt;





void main(){


string function;





cout %26lt;%26lt; "What function?";


cin %26gt;%26gt; function;


if (function == "add")


...


elseif


...


}





YOU CAN ALSO DO THIS


cout %26lt;%26lt; "1 - add, 2 - subtract";


int func = 0;


if (func == 1)


...


elseif (func == 2)





http://iamtruancy.co.nr/





Navigate to C++


This is my site, ask if you have any problems
Reply:dude, i noticed an "elseif" statement in your code. That is not valid, you must be a vb programmer lolz... here's the syntax of an if statement:





if (expression)


{


//do this


}


else if (expression)


{


//do that..


}


else


{


// fallback codes..


}





You can also use the so called ternary operator when your condition is limited to two options, example:





(expression)?(do this if true):(or this if false);





Hope this one helps.


Need help with implementing C that takes an array of integers,& and reverses the order of items in the array?

Implement a function in C that takes an array of integers,%26amp; and reverses the order of items in the array?


The function you implement must have the following form:


void reverse_order(int array[], int n)


{


/* your code goes here: re-order the n items in the array so that the


first one becomes the last


* * and the last one first.


*/


}


You should then implement a main() function which reads in a set of integers into an array,


reverses the order of the number (using the function you have just defined) and prints them out


again.


For example, when complete and compiled, you should be able to run your program, and enter


the numbers:


2 4 5 11 23 1 4


then program will then print out:


4 1 23 11 5 4 2


__,_._,___

Need help with implementing C that takes an array of integers,%26amp; and reverses the order of items in the array?
Well now you have the reverseArray function. Does it all work now????


;-)
Reply:simple in the reverse function just make another array that will copy the orignal array backwards


j=0;


for(int i=sizeof(array)-1;i%26gt;=0;i--){


modarray[j] = origarray[i];


j++;


}
Reply:Use a for loop


swap a[i] with a[n-i-1]





a[0] a[5-0-1]


RightTriangle function for C++?

The book I am consulting is Gary Bronson, C++ for Engineers and Scientists, Second Edition, Course Technology, 2006, ISBN 0-534-99380-X





I’m using Microsoft Visual Studios 2005 .


So here is what I’m attempting to do:


1. Write a function rightTriangle that accepts two double arguments (the two sides of a right triangle a, and b) and returns one double value (the length of the hypotenuse). The function prototype should be defined in file student.h and the function itself should be written in file student.cpp.


2. Write a program in Main.cpp that reads the two sides from a file, uses the function rightTriangle to calculate the hypotenuse length, and writes all three values to an output file.


3. Execute the program using the following triangle side input.


First Side (a) Second Side (b)


3 4


5 12


12 16


2.8 4.5








The problem is that I cannot get the function to strip values from my inFile. It says that inFile is an undeclared indentifier in my function

RightTriangle function for C++?
are you declaring that you are using a file? usually you have to use the file package


#include %26lt;fstream%26gt; in the beginning. then you need to declare your files...





ifstream inputfile.open("input.txt");


ofstream outputfile. open("output.txt");





that should fix your input problem

covent garden

How do i write a self defining data structure for a linked linear list data structure in C language?

I also want to use the self defining structure to create a linked list to perform the following functions on the list:


i. Insert data items into the list. Input should be terminated by a zero ii. Delete a specified item from the list iii.Modify a specified item in the list iv. Print the list.

How do i write a self defining data structure for a linked linear list data structure in C language?
I'm not sure what you mean by "self defining data structure"


unless you're pointing out that the "node" of a linked list


contains pointers to it's own type. If it's more than that, then


maybe my answer won't be sufficient; however, I think


what you're asking for is a data structure like:





struct node {


void* data;


struct node* next;


};





If you visit the following web page, you'll find an explanation


of this (and other variations), including source code for


insertion, deletion, search, etc.





http://stsdas.stsci.edu/bps/linked_list....
Reply:Sounds to me like you want to do a template class, so that you can define which data type to store in your linked list "on the fly". Here's a tutorial about templates:





http://www.devarticles.com/c/a/Cplusplus...





Oh, it is in C++. But I thought maybe that's what you meant, because I wouldn't know what "self-defining data structure" is otherwise.
Reply:Seems like you are making a database software. Like a library or dictionary program. Most likely you will need iostream.h and stdio.h as header then use multidimensional arrays to store the result. as for printing use printf or if you save the data on a file


fprintf.


But if I tell you more you will have to pay/employ me :).


An advice: Think on the data structures before you create the program.


If the letter A is defined to be equal to 36 (=6·6), B=37, C=38, and so on, then:?

The sum of the letters in the word SUPERSTITIOUS = ???





Find The Answer...u can say it related to music...

If the letter A is defined to be equal to 36 (=6·6), B=37, C=38, and so on, then:?
666? Creepy!!
Reply:"The Number of the Beast" by Iron Maiden





I left alone my mind was blank


I needed time to get the memories from my mind





What did I see can I believe that what I saw


that night was real and not just fantasy





Just what I saw in my old dreams were they


reflections of my warped mind staring back at me





Cos in my dreams it's always there the evil face that twists my mind


and brings me to despair





The night was black was no use holding back


Cos I just had to see was someone watching me


In the mist dark figures move and twist


was all this for real or some kind of hell


666 the Number of the Beast


Hell and fire was spawned to be released





Torches blazed and sacred chants were praised


as they start to cry hands held to the sky


In the night the fires burning bright


the ritual has begun Satan's work is done


666 the Number of the Beast


Sacrifice is going on tonight





This can't go on I must inform the law


Can this still be real or some crazy dream


but I feel drawn towards the evil chanting hordes


they seem to mesmerize me...can't avoid their eyes


666 the Number of the Beast


666 the one for you and me





I'm coming back I will return


And I'll possess your body and I'll make you burn


I have the fire I have the force


I have the power to make my evil take its course

email cards

If the letter A is defined to be equal to 36 (=6·6), B=37, C=38, and so on, then:?

The sum of the letters in the word SUPERSTITIOUS = ???





FIND THE ANSWER...

If the letter A is defined to be equal to 36 (=6·6), B=37, C=38, and so on, then:?
got it - 656.


I hope I haven't made any mistakes in my calculations.


A VERY original question, I must say. But I love it. I could marry maths.


What is Turbo C program for this problems?

1.) a program that would generate each of the following series


of numbers on the screen


this must be the output





a 1 4 9 16 25 36 49 64 81 100


b 1 2 4 7 11 16 22 29 37 46


c 1 2 4 8 16 32 64 128 256 512





2.)The Series Numbers:


1, 1, 2, 3, 5, 8, 13, 21, ...


is known as fibonacci series. each number is the sum of the two preceding numbers. write a program that reads in an arbitary number between 1 and 30 then display the fibonacci series of the number.





3.)the factorial of a non-negative integer n is written as n! (pronounced as "n factorial") and is defined as follows:


n!=n*(n-1)*(n-2)*...*(for values of n greater than or equal to 1) and n!=1 (for n=0)





write a program that reads a non-negative integer and computes and prints the factorial.





4.) write a program that estimates the value of the mathematical constant e by using the formula:





e=1 +1/1 + 1/2! + 1/3! + ..... 1/n!

What is Turbo C program for this problems?
1a. is square of natural numbers


1.b. is given by formula


a=1,b=1


print a


a=a+b


b++


repeat from second line


1.c. is given by formula


a=1;


print a


a=a*2


repeat


2. fibonocci


in this a=1,b=1 is set


now print a


set a=b


b=a+b


repeat from second line


3 and 4 u have formula now implement them
Reply:Homework? work out yourself. I hope you are not lazy since you took the pains to type out such a long question, spend some more time to type out the programs that do this work.
Reply:Answer 1(a)





int x;


int y;


y = 0;





for (x=0; y=100)


{


if (x%2==0)


{


y=y+x;





}


x++;


}


printf ("%d"; y);


Question on C functions programming language?

( you can see my previous question or read it here again)


I have declared various functions outside the main() function. all the functions can be called from main(), but some of the functions are better called from the other functions defined outside main(), otherwise I have to allocate another memory. Someone suggested I creat a lib file of the functions that I need to acess...how can I creat a lib file. Sorry if i sound stupid, but I have never created a lib file myself. I am using visual C++, but will be using CodeComposer, soon. But I have to simulate everything on pc, any help....?

Question on C functions programming language?
Do you have access to the command line? I am not a visual C++ guy, I do all my stuff via Makefiles on UNIX systems. Can you access the "ar" command in your compiler/linker?





If so, here is a simple command to build a static library out of several compiled ".o" (object) files.





ar rsuv %26lt;library name%26gt;.a %26lt;1st file%26gt;.o %26lt;2nd file%26gt;.o





Where:


---------


"ar" is the command


"rsuv" are command line switches that you can learn about by looking at your "man pages" for the "ar" command


"library name" is the name of the library file you are creating, and will have a ".a" suffix to denote that it is a static library


"yourfile" 1 and 2 are the object files that were created during your compilation step.





Voila - once you have this library, it can be linked in using the "ld" command with other libraries to create your executable program.





Sorry if this is useless to you since you might only be familiar with graphical programming. Perhaps it might be useful to others if not for you.





Good luck!
Reply:Your question isn't very clear. You're saying you need to call a function from a function...that doesn't have anything to do with lib files. All you need to do is make sure that the function you're calling is declared previously (i.e. before the function you're currently in). The only way a lib file comes in is if you need to keep the functions completely seperated from your main cpp/h file. In that case you would just create a seperate cpp/h file and compile it, but don't link it. Then you would declare those functions as "extern" in your main cpp/h file and make sure to inclue your lib file in the link parameters of your main program (of course you would have to compile the functions cpp/h first to get the lib file). Just be ready for a lot of confusion dealing with extern though, because it's not easy the first time you're doing it.


What happens if someone deletes the /etc/inittab file in solaris m/c?

Hi I am a newbie to unix, was wondering what would happen if someone deletes the inittab file in the solaris m/c... would that crash the OS as such, since thats the file which defines the startup scripts to be run for any level...and since the default login level is also specified in the /etc/inittab, if the inittab file is deleted then, would that mean no body could login in to the system???

What happens if someone deletes the /etc/inittab file in solaris m/c?
Actually, not much of anything would happen until you tried to *change* from one init level to another. So if the system was already booted up and running multiuser, it would be fine - until you tried to shutdown, reboot, or go to single-user mode, ad which point you'd discover you were stuck in multiuser.





Incidentally, starting in Solaris 10, a lot of the functionality of /etc/inittab and the /etc/rc.d directories has been migrated into the Service Management Facility (SMF).

cheap flowers

If know C language then solve it.....?

write a program to transform its input according to a specified transformation scheme. the transformation scheme will consist of two strings: a string of character and then a string of replacement characters. the idea is that your program replaces every instance of the ith character in the initial string with the (i+3) character (of english alphabets) in the replacement string. when no substitution is defined for a character , the program just passes it through to the output unchanged. The program should inform the user of any errors in the transformation scheme. Your program should display the phrase before and after the substitutions have been made.





example : This is a C program.


string after the transformation : Wklv lv d f Surjudb.

If know C language then solve it.....?
Here is a source code i have enclosed below.Copy and paste it in a new text file and compile it.





If it is not upto your needs dont worry . Contact me at m_gopi_m@yahoo.co.in. I really like to program like this.





But time doesn't support me and i was not able to understand the question clearly. So if you want contact me and i can design new program.





Here the source begins.......





/*


Please create a new folder and place this program in it. It creates


Two text documents(first.txt and second.txt).





first.txt is a copy of the input stream.


second.txt is a copy of encryption.


repalaces ith term by i+3 terms.





Please do not use any special keys like delete,backspace etc...





If you want to change the encryption number. Change 'num' variable(int)


present at 23:14.


*/








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


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





void main()


{


FILE *fp1,*fp2;


char a,b;


int num=3,i;





clrscr();


printf("\n\nEnter your message:\n%26lt;When you do so press enter%26gt;");


printf("\n%26lt;Please avoid special characters%26gt;\n\n\t");





fp1=fopen("first.txt","wt+");


while(a!=13)


{


a=getche();


if(a==0)


{


getch();


printf("\b\a");


}


else if(a==8)


{


printf("%c\a",b);


}


else


{


fputc(a,fp1);


b=a;


}


}


rewind(fp1);





fp2=fopen("second.txt","wt+");


while(a!=EOF)


{


a=fgetc(fp1);





if(a!=EOF %26amp;%26amp; a!='\0')


{


if(a!=' ')


a+=num;


fputc(a,fp2);


}


}


fclose(fp1);





rewind(fp2);


clrscr();


printf("\nThe resultant text is\n\n\t");





a=' ';


while(a!=EOF)


{


a=fgetc(fp2);


printf("%c",a);


}





gotoxy(1,22);





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


printf("%c",205);


printf("\nFor convenience the input data is saved in first.txt");


printf("\nThe encrypted data is saved in second.txt");


printf("\nPlease take a view at it.");





getch();


fclose(fp2);


}
Reply:That's not a hard task.


All we need is an array, or you can called: matrix.


In ANSCI behind every character there is a number.


For example: A-97,B-98(just assume, i dont have a manual now on hand), then you should design a number array, such as : {1,2,5,6}, then you could process the string with such method: the first charac. add the array[1], then the second add the array[2], and make a simple recycle, to let the string to add the members of array in a round turn.


Relly simple, right?
Reply:i will not write program for u.





But make an array of 26 characters.





take every character from given string and get the position no.


then add two and get the string





Do it untill all the characters completed.


And yes dont forget to skip to 1 if count increase to 26.





simple.


Programming with c?

Vectors


Vectors are very important in mathematical computing and in computer graphics .Vector graphics is economical in its use of memory, as an entire line segment is specified simply by the coordinates of its endpoints. A vector can be represented by an arrow whose length represents the magnitude and the direction represents the vector direction.








The above vector a can be represented as





a = [a1, a2]





The arithmetic operations can be performed in the following way:





o Addition





If a and b are two vectors





a = [a1, a2]





b = [b1, b2]





then the sum of a and b is





a + b = [a1+b1 , a2+b2]





o Subtraction





If a and b are two vectors





a = [a1, a2]





b = [b1, b2]





then the difference of a and b is





a - b = [a1-b1 , a2-b2]





o Multiplication





If a and b are two vectors





a = [a1, a2]





b = [b1, b2]





then dot product of a and b is





a . b = (a1 * b1 ) + ( a2 * b2)





o Length of vector





If a is a vector





a = [a1, a2]





then the length of vector a is





length =





Assignment





Write a C++ program that performs the above mentioned operations on vectors with the help of above mentioned formulae. The program should have four user defined functions for the above operations.





1) Addition


2) Subtraction


3) Multiplication


4) Length





The following menu of commands should be displayed at the start of program execution.





Press 'a' to add two vectors





Press 's' to subtract two vectors





Press 'm' to multiply two vectors





Press 'l to calculate the length of vector





Press 'q' to quit





Please enter your choice: a





After the user selects a choice, prompt the user to enter the vector components on which the selected mathematical operation is to be performed, and then display the result. For example,





if the user enters ‘a’ then your output should be:





Enter first component of vector : 2


Enter second component of vector : 7





The vector is : [ 2 , 7 ]





Enter first component of vector : 6


Enter second component of vector : 3





The vector is : [ 6 , 3 ]





The sum is [ 8 , 10 ]





if the user enters ‘s’ then your output should be :





Enter first component of vector : 2


Enter second component of vector : 7





The vector is : [ 2 , 7 ]





Enter first component of vector : 6


Enter second component of vector : 3





The vector is : [ 6 , 3 ]





The difference is [ -4 , 4]





if the user enters ‘m’ then your output should be :





Enter first component of vector : 2


Enter second component of vector : 7





The vector is : [ 2 , 7 ]





Enter first component of vector : 6


Enter second component of vector : 3





The vector is : [ 6 , 3 ]





The multiplication is 33





After the menu if the user selects ‘l’ then your output should be





Enter first component of vector : 1


Enter second component of vector : 2





The vector is : [ 1 , 2 ]





The length is 2.23607





After the menu if the user selects ‘q’ then your output should be





Press any key to continue …..





Conditions that must be checked and fulfilled:





1) If a user enters choice other then choices given in menu, then a message should be displayed “You have entered wrong choice:” and main menu should be displayed again.


2) If a used enters a ,s or m then you have to take components of two vectors then do calculation on them


3) If a user enters l then you have to take components of one vector only then do calculation on it.

Programming with c?
Do not you think that is lot of homework ?
Reply:This questions seems professional, i would recommenced, if you cannot do it yourself, you can take professional help and ofcourse this never comes free, i know professional who do this type of homework, try contact ankurjain@excitonpublications.com they have nominal charges around $50 per answer.





try this, hope they will help





regards
Reply:Do your homework yourself. Who do you think has that much time to read through your zillion words long questions and then give you a ready made answer. %26gt;.%26lt; Have some decency!





Write down your code, and then if you are stuck somewhere, ask us and we'll help you.
Reply:Seriously do your own homework. Im tired of "questions" like these. Are we allowed to report them? Btw, if you can't handle an assignment like this without asking someone else to do it for you, drop the class. THIS IS SIMPLE! A few cin's, a few cout's, can count the number of variables required with my fingers and a couple if's or switch statements. Read the material your instructor provided you with and then come back with specific questions. Those we will answer.
Reply:hey lareb, i hope that i can make the program for you, it is simple, all you have to do is email me at my id, so that i get your email, and i will reply / post the answer in the cpp format for you,





i am not like others i just want to help you,


try me and see if i am helpful, ok


contact me at :





qazeeassad@gmail.com


qazeeassad@yahoo.com





both are ok but first try gmail,


i will be waiting for your email ok


as there is only 1 day left in your assignment


see you


If v is an eigenvector of A and c(x) is the characteristic polynomial, then c(A)v = 0?

For any polynomial p(x) = a0+a1x+...+ak x^k and any square matrix A, the matrix p(A) is defined as p(A) = a0 I +a1A+...+ak A^k. Show that if v is any eigenvector of A and c(x) is the characteristic polynomial of A, then c(A)v = 0. Deduce that if A is diagonalisable then c(A) is the zero matrix.

If v is an eigenvector of A and c(x) is the characteristic polynomial, then c(A)v = 0?
We can start with two lemmas:





Lemma 1: If v is an eigenvector of A with eigenvalue b, then A^n v = b^n v for all n %26gt; 0





This is trivially true for n = 0 since A^0 = I and Iv = v = b^0 v





It's also true for n = 1 by the definition of eigenvector, A^1 v = Av = bv = b^1 v





And if you assume it's true for n, then it's true for n = 1 since:





A^(n + 1)v


= AA^n v


= Ab^n v (by assumption)


= b^n Av


= b^n bv


= b^(n+1) v





So by induction, the lemma holds.





Lemma 2: For any polynomial p, and A, b, and v as above, p(A)v = p(b)v





Suppose that p(x) = c0 + c1 x + c2 x^2 + c3 x^3 ...





Then p(A) = c0 + c1 A + c2 A^2 + c3 A^3 ...





And p(A) v = (c0 + c1 A + c2 A^2 + c3 A^3 ...) v


= c0v + c1 Av + c2 A^2v + c3 A^3v ...


= c0v + c1 b v + c2 b^2 v + c3 b^3 v ... (by lemma 1)


= (c0 + c1 b + c2 b^2 + c3 b^3 ...) v


= p(b) v





Which is the required result.





From lemma 2, it follows immediately that if we substitute the characteristic polynomial c for p, then:





c(A)v = c(b)v = 0





Since the eigenvalues are zeros of the characteristic polynomial.





And if A is diagonalizable, that means that there is a set of eigenvectors for it {v0, v1, v2, v3, ...} which form a basis for the space. By the above, c(A) is going to be zero for all of these vectors, and since any other vector in the space can be represented as a linear combination of {v0, v1, v2, v3, ...}, and c(A) is linear, this means c(A) x = 0 for all vectors x in the space. This means c(A) is identically zero.
Reply:If v is an eigenvector and Av = av (where a is a constant, possibly complex), then A^2v = AAv = Aav = aAv = a^2v, and so on. That is, A^n v = a^n v. Hence for any polynomial P,


P(A)v = P(a)v. Note that c(a)=0, since a is an eigenvalue of A.


Thus c(A)v = c(a)v = 0.





If A is diagonable, then C^n (n dimensional complex space) has a basis of eigenvectors of A. So for any z in C^n, we can write


z = sum_k z_k v_k, where the z_k are complex constants and the v_k are the eigenvectors of A. Say Av_k = a_k v_k.





Thus c(A)z = c(A) sum z_k v_k = sum z_k c(A) v_k


= sum z_k . 0 = 0, since each v_k is an eigenvector and we're applying the result we just proved.





We say that A satisfies its characteristic equation, and we've just proved it in the diagonable case. You'll soon learn that it holds for any matrix.


Statistics Please check (a) (c) (d) to see if they are correct.?

What is the age distribution of promotion-sensitive shoppers? A supermarket super shopper is defined as a shopper for whom at least 70% of the items purchased were on sale or purchased with a coupon. The following table is based on information taken from Trends in the United States (Food Marketing Institute, Washington, D.C.).





Age range, years 18-28 29-39 40-50 51-61 62+


Midpoint x 23 34 45 56 67


% of shoppers 7% 44% 24% 14% 11%





(a) Using the age midpoints x and the percentages of super shoppers, do we have a valid probability distribution? Explain.


Yes, events are distinct and probabilities total to 1.





(c) Compute the expected age µ of a super shopper.


Age P(x) x(P)x


23 0.07 1.61


34 0.44 14.96


45 0.24 10.8


56 0.14 7.84


67 0.11 7.37


µ = ∑xP(x) = 42.58





(d) Compute the standard deviation õ for ages of super shoppers.


√∑(x-µ)²P(x) = √151.442 = 12.31

Statistics Please check (a) (c) (d) to see if they are correct.?
You are correct.





I have verified the calculations





d%26lt;-c(1.61,14.96,10.8,7.84,7.37)





m%26lt;-sum(d)





s%26lt;-c((23-m)^2 * 0.07,(34-m)^2 * 0.44,(45-m)^2 * 0.24,(56-m)^2 * 0.14,(67-m)^2 * 0.11)





sqrt(sum(s))








output:





mean = 151.4436


std dev = 12.30624
Reply:oh my...i dont think anyone is gonna help you with this one....looks like way too much work...10 points isnt worth it

baseball cards

I want to convert a c program into a .dll file?

I want to convert a c program into a .dll file..... i am using visual studio c++ for tht using MFC applcation wizard i am trying to convert..... but its not working.. in the c program i am having my own header files... the error i am getting is cannot include the header file. the header file are user defined files.. pls help.its an important issue.

I want to convert a c program into a .dll file?
Without more information I'm not entirely sure why you're getting the error you're getting, but in MS VC++ 6.0 you create a DLL by selecting:





File %26gt; New





Then, select the Projects tab, and select Win32 Dynamic-Link Library.





Give the project a name and location and click OK. You can then add your C and header files and it should build the DLL just fine.


Regular expressions with C++?

If you have a string of text and you wanted to use a regular expression to identify any words in that string of text, what is the c++ code that would do it? What #include statements would I need?





Note: A word is defined as any sequence of letters that is not interrupted by a space.





Complete code would be helpful, but any help is appreciated.

Regular expressions with C++?
I believe from this description, what you are trying to do is identify whether a given word is contained within a character string - in other words, you are looking for a substring.





If so, the function you are looking for is the famous "stir-stir", or





char * strstr ( const char * string1, const char * string2 );





The function is in the string.h library, which you need to include:


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





The function returns a null pointer if the substring (string2) is not located in string1. Otherwise it returns a pointer to string2.





This link has an example of use:


http://www.cplusplus.com/ref/cstring/str...





====


Addendum:


I see that I misunderstood your question, but I will let my answer stand for now. If I get the chance I will come back later and show you some code to parse a string for words as you describe.





====


Addendum #2


I completely missed on your question. Sometimes that happens, even with the best of intentions.





C++ does not come "out of the box", any box version, with regular expressions. You have to add an external library, and there are a few out there:


like this:


http://www.onlamp.com/pub/a/onlamp/2006/...


or this:


http://ourworld.compuserve.com/homepages...
Reply:OK answering this one is a bit tough as I worked with regex long time ago. But a simple search in Google will bring you some good results. Here is one place I found very help full just from a quick glance. http://www.tropicsoft.com/Components/Reg...


C Programming Help? Word Count/Character Count Problem?

I need to write a program to perform word count/character count. I'm really stuck. Can anyone please help me out? Thanks





In this problem you are asked to analyze a string of characters and report the words contained within. The characters will be entered from the command line, and you may assume that no more than 512 characters will be entered. Your goal is to report the individual 'words' contained in the series of characters (a word is defined as any number of characters separated by spaces). You should also report the number of characters in each word, and the total number of words found. For this program you should not use %s to read the input. Instead you should use %c to read each character individually.





Sample Run:


Please enter some characters:


my name is


Word : Length


my : 2


name : 4


is : 2





Found 3 words

C Programming Help? Word Count/Character Count Problem?
This should work. You should familiarize yourself with the strtok function in C.





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


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





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


int i = 0;


char *strPtr = NULL;


char str[512];





printf( "Please enter some characters:\n" );


do {


scanf( "%c", %26amp;str[i] );


i++;


} while( str[i - 1] != '\n' );





str[i - 1] = '\0';





i = 0;


printf( "Word:Length\n" );


strPtr = strtok( str, " " );


while( strPtr != NULL ) {


printf( "%s:%d\n", strPtr, strlen( strPtr ) );


i++;





strPtr = strtok( NULL, " " );


}





printf( "Found %d words.\n", i );





return( 0 );


}


C++ error messages. Help....?

I used these two lines in my code:





initgraph(%26amp;g,%26amp;h,"c:\tc\bgi");


setbkcolor(BLUE);





The error meassges are :





Call to undefined function 'initgraph' in function fool()


Call to undefined function 'setbkcolor' in function fool()


How can I defined them? please help..

C++ error messages. Help....?
Did you add an include statement for these functions?





ex: #include %26lt;graphics.h%26gt;





void initgraph(int *graphdriver, int *graphmode, char *pathtodriver);
Reply:Usually this means you forgot to "include" the approprate header files that contain the defintions of "initgraph" and "setbkcolor".

artificial flowers

How to write C code to convert currency?

Having the following prototype:


float ForeignToDollars (float units, float conv);


how do i write C code that converts currency from pounds, kronors (to US dollars) etc?





the following info is #defined:


* 1.96109 dollars per British pound


* 0.15794 dollars per Swedish kronor


* 1.46785 dollars per Euro


* 0.04067 dollars per Russian Ruble

How to write C code to convert currency?
This is more of a math problem than programming. Let's consider today's rate: 1 British Pound = 1.9881 USD





The best way to think of conversion, is cancellation of currency units, as one might do in physics.





For example:


1.9881 USD per British Pound implies


1.9881 USD/British Pound





To convert from USD to British pounds, divide 1 USD by 1.9881 USD per British Pound:


1 USD / 1.9881 USD/British Pound


Gives us: 0.5030 British Pound (since the USD units cancel)





If you try this in a converter like: http://finance.yahoo.com/currency/conver... the math works out.





So for your case, the pseudocode could be:


float DollarsToForeign(float units, float conv){


return units * ((float)1 / conv));


}





Hope that helps


Need help with programming a C++ program to find circumference with a given radius.?

This is what I have:


#include %26lt;iostream%26gt;


#include %26lt;fstream%26gt;


#include %26lt;iomanip%26gt;


using namespace std;


double pi=3.14159;





int main ()


{


cout %26lt;%26lt;"Michael ..MJNL6P2.cpp Lab#6 C++ Tutorial \n" %26lt;%26lt; endl;








double radius;





ofstream outfile;


outfile.open("circle.out");





cout %26lt;%26lt;"ENTER LENGTH FOR RADIUS: " ;





cin %26gt;%26gt; radius;


double CIRCUMFERENCE = 2 * pi * radius;





cout %26lt;%26lt; "Circumference is " %26lt;%26lt; CIRCUMFERENCE %26lt;%26lt; " \n\n\n";


outfile %26lt;%26lt; "Circumference is " %26lt;%26lt; CIRCUMFERENCE %26lt;%26lt; ".\n";








return 0;


}





I get the errors:


PYRMJN-1.obj : error LNK2005: _main already defined in MJNL6P2.obj


Debug/MJNL6P2.exe : fatal error LNK1169: one or more multiply defined symbols found


Error executing link.exe.

Need help with programming a C++ program to find circumference with a given radius.?
hmmm....thats a weird error message. Cant say Ive seen it before. It shouldnt be anything to do with your actual code, looks good to me.





Im guessing it has something to do with how you are compiling it. What are you using?





If you are using g++ you can do it all in one line.


g++ thisFile.cpp -o pgm.exe


C++ Counting Problem?

I'm attempting to count how many correct, second-try corrects, and incorrects [Incorrect after second try is wrong].





Here's my code so far:


[I have the subroutines defined before this and everything, so, that's definately not the problem. I'm just going to put down my subroutine I'm using at the moment.


Addition()


{





randomize();


int A, B, C, D, setnum, correct2, incorrect, insane;


int number, correct, count2;


textcolor(RED+BLUE);


clrscr();


gotoxy(15, 12);


int i;


cout%26lt;%26lt;"Why, hello there! How many questions do you want to solve?\n\n";


cin%26gt;%26gt;setnum;


clrscr();


gotoxy(15,12);


cout%26lt;%26lt;"Okay, then! You have "%26lt;%26lt;setnum%26lt;%26lt;" to answer! :]";


getch();


textcolor(RED+BLUE);


clrscr();


gotoxy(15, 12);

C++ Counting Problem?
You aren't initializing your correct, correct2, and incorrect counters. Set them to zero before you use them





Also, in C++ you don't need to use printf( ).


C++ Help- Input and Output txt document?

Please can someone help me with my c++ program. I need to read a file, display it on the screen, and then write the data to an output file called output.txt. Each functionality should be defined in a class, leaving the main function clean. This is what i have so far.





#include%26lt;iostream%26gt;


#include%26lt;fstream%26gt;


#include %26lt;string%26gt;


using namespace std;





void gettext();


void output();





int main(){


void gettext(string i);


void output();


return 0;


}





void gettext(string i){





string line;


ifstream myfile("input.txt");


if(myfile.is_open()){


while(!myfile.eof()){


getline(myfile, line);


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


}


}


else{


cout%26lt;%26lt;"Problem opening file"%26lt;%26lt; endl;


}


}


void output(){


string line;





ofstream my2file;


my2file.open ("output.txt");


my2file%26lt;%26lt; line;


my2file.close();


}

C++ Help- Input and Output txt document?
It seems like you overlooked the part of the problem statement that requires you to create a class. You need something like this:





class FileHandler {


public:


FileHandler() : { } // Default constructor


FileHandler(const string%26amp;) ; // Constructor (in file only)


FileHandler(const string%26amp;, const string%26amp;); // Full constructor (in and out filenames)


FileHandler(const FileHandler%26amp;); // Copy constructor


~FileHandler() { } // Destructor


void setInFileName(const string%26amp;);


void readInFile();


void setOutFileName(const string%26amp;);


void writeOutFile(const string%26amp;);


private:


string inFileName;


string outFileName;


vector%26lt;string%26gt; inFileText;


};





In main(), then you could:





// get input and output file names; maybe they're in argv[1]


// and argv[2], or maybe you prompt for them; store the names


// in string inFileName and string outFileName





FileHandler myFileHandler = new FileHandler(inFileName);


myFileHandler-%26gt;readInFile();


myFileHandler-%26gt;writeOutFile(outFileNam...


...


// when you're done :


delete myFileHandler;





You have some problems with the code you've written. In main, you declare gettext and output, after you declared them prior to main. Also, the gettext declaration in main is not the same as the previous one, and you are not calling any functions. You don't want these anyway, the read and write operations need to be in the class.





Your input() function is just displaying the input file, not saving the contents. If it saves the file contents, you'll be able to create the output file later.





Your output() function is writing the contents of a default-constructed string, your 'line' variable', to output.txt. Certainly not what you want.





Obviously I'm leaving a lot of the details for you to fill in. I hope the class definition will get you started on solving the problem as stated.
Reply:You've got to put in classes then. If you're have an input function in your first class... it will need to accept your ifstream object. Same for your output function. Then, when calling your function pass in your input and output files respectively.
Reply:This program takes the name of a file from the keyboard (without error-checking) opens it, gets the file length, and copies that many characters both to the screen and to the file Output.txt.





#include %26lt;iostream%26gt;


#include %26lt;fstream%26gt;





using namespace std;





int main()





{





char Name[30], c, length;


ifstream Myfile;


ofstream Outputfile;


cout %26lt;%26lt; "Enter the name of the file to open:";


cin %26gt;%26gt; Name;


Myfile.open(Name);


Outputfile.open("Output.txt");


Myfile.seekg(0,ios::end);


length=Myfile.tellg();


Myfile.seekg(0,ios::beg);


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


{Myfile %26gt;%26gt; c;


cout %26lt;%26lt; c;


Outputfile %26lt;%26lt; c;


}


Myfile.close();


Outputfile.close();


return 0;


}











Output is:


jplatt@darkstar:~/Apr06$ ./filefun


Enter the name of the file to open:myfile.txt


IhateC++\!!!!jplatt@darkstar:~/Apr06$ cat Output.txt


IhateC++\!!!!jplatt@darkstar:~/Apr06$ cat myfile.txt


I hate C++\!





Have fun rewriting it to your purposes -- oh, and in case you haven't figured it out yet, it's compiled with GCC for Linux. Your OS and compiler may handle it slightly differently.

800flowers.com

Using C++: Is there a way to make this program a user defined number of names to be entered and sorted???

//Sort an array of 3 names


#include %26lt;iostream%26gt;


#include%26lt;string%26gt;


using namespace std;


void swap(string %26amp;n1, string %26amp;n2)


//receive strings n1 and n2, exchange


{ string temp;


temp=n1;


n1=n2;


n2=temp;


} //swap





void main() //input 3 names, sort, print


{ string names[3]; //3 names: [0],[1],[2]


int index;


for(index=0; index%26lt;3; index++)


{ cout%26lt;%26lt;"enter a name: ";


getline(cin,names[index]);


} //for loop


if (names[0]%26gt;names[1])


swap(names[0],names[1]);


if (names[1]%26gt;names[2])


swap(names[1],names[2]);


if (names[0]%26gt;names[1])


swap(names[0],names[1]);


for(index=0; index%26lt;3; index++)


cout%26lt;%26lt;names[index]%26lt;%26lt;"\n";


} //main

Using C++: Is there a way to make this program a user defined number of names to be entered and sorted???
//do this:


int nint;


cin%26gt;%26gt;nint;


string names[nint];


// and this


for(index =0;index%26lt;nint;index++)


{


//etc.
Reply:Uhm, are you asking is there a way to create a user defined data type? I don't think there is a such thing as a "user defined number" or what you said... Unless you are asking if there is a way to call that whole segment of code using a function with in a class? Or perhaps by using a structure.... I am not really to sure on what you are asking. Please try and be more clear so people can help you :)


C++ mutual-inclusion (mutual dependcies)?

Hi all. I am having an issue using Borland C++ Builder where I have 2 classes:


TTarget


TTgtMgr





Both classes include references to the other in the defintions (header) and the implementation (cpp)





I tried using forward declarations. This allows me to make vars


TTarget *tgt


TTgtMgr *mgr





in each others classes, however the problem is, in the implementation, I try to access the methods of the other class and I recieve the following compiler error:





Cannot access methods of %26lt;class%26gt; because %26lt;class%26gt; is not yet defined.





So for example in TTarget.cpp I do:


*TTgtMgr *mgr


mgr-%26gt;someMgrFunc();





And the error occurs.





I feel like some form of late binding might help but I really dont understand it well enough to implement such a fix.





Any thoughts on how I can remedy this problem?





Thanks!

C++ mutual-inclusion (mutual dependcies)?
In the .h files of the above two classes use forward declaration, no "*" required.





In TTarget.h before actual class definitions starts








/////////// TTarget.h file





class TTgtMgr; //forward declaration





class TTarget{





}








/////////// TTgtMgr.h file





class TTarget; //forward declaration





class TTgtMgr{





}





fill in the rest of the implementations


C++ program?

We want to develop a C++ program that calculates the distance between two cities. We will use the longitude and latitude to determine the location of each city. This is not as straightforward as you might imagine because the distance is not in a straight line. Instead, one would travel along a great circle defined by the curve of the Earth’s surface and passing through the two locations. Therefore, the actual distance to travel is the distance along the segment of such a great circle.





If the coordinates for location 1 are (θ1, φ1) and the coordinates for location 2 are (θ2, φ2), then the distance from location 1 to location 2 is:





r × arccos( sin(θ1)sin(θ2) + cos(θ 1)cos(θ2)cos(φ2−φ1))





where:





r is the radius of the earth, in the units for which you wish to calculate the distance. Measured in kilometers, r = 6378.7


θ is the latitude measured in radians


φ is the longitude measured in radians








Your program must allow the user to calculate as many distances as he/she wishes. In other words at the end of your program you need to prompt the user if he/she wants to continue or not. If the user says "yes" (or 1) then the the user is prompted to enter other locations, if the user enters "no" (or 2) then the program terminates.

C++ program?
It's been years since I learned C++, but don't you have the formula already? All you gotta do is just declare the variables and do 3 of those cin things for the radius, latitude and longitude, and then just do cout%26lt;%26lt;(that equation) and then you're done.





For the continue or termination thing, you just have to do declare a string sAnswer for "yes" and "no"


Run the previous whole calculation in a loop, if sAnswer = "yes" then boolean is true and you repeat the loop, if its "no" then just terminate the program.
Reply:USE FORTRAN AND LEARN PROGRAMMING.


Using regular expressions with C++?

If you have a string of text:





string SampleText = "12345 quick 12345 brown 12345 fox";





and you wanted to use a regular expression to identify the words in the SampleText (a word is defined as a group of letters not separated by a space), what is the c++ code that would do it? What #include statements would I need?





Complete code would be helpful, but any help is appreciated.

Using regular expressions with C++?
If you are using unix:





you can use %26lt;regex.h%26gt;


Posix function are: regcomp, ergexec, and regerror.





you can type 'man regcomp' to get an explanation of how to use the functions.





If you are using Windows, here is some sample code:





// regex_parse.cpp


// compile with: /clr


#using %26lt;system.dll%26gt;





using namespace System;


using namespace System::Text::RegularExpressions;





int main( )


{


int words = 0;


String^ pattern = "[a-zA-Z]*";


Console::WriteLine( "pattern : '{0}'", pattern );


Regex^ regex = gcnew Regex( pattern );





String^ line = "one\ttwo three:four,five six seven";


Console::WriteLine( "text : '{0}'", line );


for( Match^ match = regex-%26gt;Match( line );


match-%26gt;Success; match = match-%26gt;NextMatch( ) )


{


if( match-%26gt;Value-%26gt;Length %26gt; 0 )


{


words++;


Console::WriteLine( "{0}", match-%26gt;Value );


}


}


Console::WriteLine( "Number of Words : {0}", words );





return 0;


}





-----------------------


Note, the using namespace statement up top ends in: RegularExpressions;


The ... is a yahoo answers problem.

wildflower