Write a program that reads ten numbers (in an array), and counts the number of elements in the array that are divisible by 3.
What would this look like in C++ code?
#include %26lt;iostream%26gt;
using namespace std;
int main( int, char **)
{
int i, ary[10];
for (i = 0; i %26lt; 10; ++i)
cin %26gt;%26gt; ary[0];
int cnt = 0;
for (i = 0; i %26lt; 10; ++i)
{
if (ary[i] % 3 == 0)
++cnt;
}
cout %26lt;%26lt; cnt %26lt;%26lt; endl;
return 0;
}
Reply:all numbers are divisible by 3. No need to load them into an array.
Reply:It could look very similar to a program written in C to do the samething. Shouldn't you do your own homework? At lease give it a try and ask for help.
Actually - I've seen someone earlier posting a nearly complete program to do the same thing but having problems withit.
chrysanthemum
Monday, May 24, 2010
Explain line by line the following C++ code?
#include %26lt;iostream.h%26gt;
#include %26lt;conio.h%26gt; //for getch()
#include %26lt;ctype.h%26gt; //for isdigit
#include %26lt;stdlib.h%26gt; //for atoi
main()
{
char ch;
char entier[6];
int compteur=0;
cout %26lt;%26lt; "Enter a whole number : ";
cout.flush ();
do
{
ch = getch();
if ( ch=='\b' %26amp;%26amp; compteur%26gt;0)
{
compteur--;
cout %26lt;%26lt;'\b';
cout %26lt;%26lt; ' ';
cout %26lt;%26lt;'\b';
cout.flush ();
}
else
if (compteur%26lt;6 %26amp;%26amp; isdigit(ch))
{
entier[compteur++]=ch;
cout%26lt;%26lt;ch;
cout.flush();
}
}
while(ch!='\r');
entier [compteur]='\0';
int valeur=atoi(entier);
cout %26lt;%26lt; "\nThe whole number is " %26lt;%26lt; valeur %26lt;%26lt; endl;
system("pause");
}
Explain line by line the following C++ code?
Hey that's not a very good question to ask here. We are here to help you, not serve you.
So instead of giving a junk code and ordering others to explain the damn code, point to the specific line and ask to explain that line. Hope you got my point.
Reply:Damn, that code is just hard enough to read that I couldn't be bothered trying to comprehend it. Damn Yahoo! answers for not keeping indentation.
Reply:hey are you reading Programming for Dummies? Because I'm reading it too
#include %26lt;conio.h%26gt; //for getch()
#include %26lt;ctype.h%26gt; //for isdigit
#include %26lt;stdlib.h%26gt; //for atoi
main()
{
char ch;
char entier[6];
int compteur=0;
cout %26lt;%26lt; "Enter a whole number : ";
cout.flush ();
do
{
ch = getch();
if ( ch=='\b' %26amp;%26amp; compteur%26gt;0)
{
compteur--;
cout %26lt;%26lt;'\b';
cout %26lt;%26lt; ' ';
cout %26lt;%26lt;'\b';
cout.flush ();
}
else
if (compteur%26lt;6 %26amp;%26amp; isdigit(ch))
{
entier[compteur++]=ch;
cout%26lt;%26lt;ch;
cout.flush();
}
}
while(ch!='\r');
entier [compteur]='\0';
int valeur=atoi(entier);
cout %26lt;%26lt; "\nThe whole number is " %26lt;%26lt; valeur %26lt;%26lt; endl;
system("pause");
}
Explain line by line the following C++ code?
Hey that's not a very good question to ask here. We are here to help you, not serve you.
So instead of giving a junk code and ordering others to explain the damn code, point to the specific line and ask to explain that line. Hope you got my point.
Reply:Damn, that code is just hard enough to read that I couldn't be bothered trying to comprehend it. Damn Yahoo! answers for not keeping indentation.
Reply:hey are you reading Programming for Dummies? Because I'm reading it too
What owuld this lookd like in C++ code?
A program that reads ten numbers (in an array) and displays them in reverse order in which they are read.
What owuld this lookd like in C++ code?
#include %26lt;iostream%26gt;
using namespace std;
int main( int, char **)
{
int i, ary[10];
for (i = 0; i %26lt; 10; ++i)
cin %26gt;%26gt; ary[i];
for (i = 0; i %26lt; 10; ++i)
cout %26lt;%26lt; ary[ 9 - i ];
cout %26lt;%26lt; endl;
return 0;
}
Reply:It could look very similar to a program written in C to do the samething. Shouldn't you do your own homework? At lease give it a try and ask for help.
What owuld this lookd like in C++ code?
#include %26lt;iostream%26gt;
using namespace std;
int main( int, char **)
{
int i, ary[10];
for (i = 0; i %26lt; 10; ++i)
cin %26gt;%26gt; ary[i];
for (i = 0; i %26lt; 10; ++i)
cout %26lt;%26lt; ary[ 9 - i ];
cout %26lt;%26lt; endl;
return 0;
}
Reply:It could look very similar to a program written in C to do the samething. Shouldn't you do your own homework? At lease give it a try and ask for help.
How can you write and run C code on mac?
You get yourself a compiler that runs on a mac.
I am told you can get this to run on a mac:
http://www.leonardo-vm.org/
Apple itself distributes Xcode:
http://developer.apple.com/tools/downloa...
I checked out this Mac forum:
http://forums.macrumors.com/showthread.p...
Their response in the end is the Gnu GCC compiler which is so familiar to those of us who work on Linux.
http://gcc.gnu.org/
How can you write and run C code on mac?
you cant... its a mac.
Reply:C is portable and will run where it was compiled so long as you are not counting on OS specific API's
You can can GCC for this.
Reply:Find a compiler that works on the mac and get it.
Reply:Just get a compiler.
Reply:Get XCode:
http://developer.apple.com/tools/downloa...
Or just get GCC for Mac.
In order to download XCode, you'll have to create developer's account with Apple, which is free. XCode includes GCC.
I am told you can get this to run on a mac:
http://www.leonardo-vm.org/
Apple itself distributes Xcode:
http://developer.apple.com/tools/downloa...
I checked out this Mac forum:
http://forums.macrumors.com/showthread.p...
Their response in the end is the Gnu GCC compiler which is so familiar to those of us who work on Linux.
http://gcc.gnu.org/
How can you write and run C code on mac?
you cant... its a mac.
Reply:C is portable and will run where it was compiled so long as you are not counting on OS specific API's
You can can GCC for this.
Reply:Find a compiler that works on the mac and get it.
Reply:Just get a compiler.
Reply:Get XCode:
http://developer.apple.com/tools/downloa...
Or just get GCC for Mac.
In order to download XCode, you'll have to create developer's account with Apple, which is free. XCode includes GCC.
Is there software that will write C++ code automatically?
It depends. There are packages out there that will convert UML to C++ code or many other types of code such as Java or SQL that you then run through a compiler or interpreter. Can it do that for a PC application? Probably no. Can it do that for general applications? Probably yes. Is it a good idea? That is a loaded question. It is definitely a programming paradigm shift, modifications and maintenance may be more difficult but on the other hand good requirements analysis and documentation are required since they "are" the code. Google "code generation" or "rose realtime" as a start.
Is there software that will write C++ code automatically?
Depends what you mean. If you mean, you don't have to touch any code, period, the short answer is no.
There are a number of IDEs (integrated development environments) that allow you to visually drag and drop elements into a project, and then specify certain parameters via a form; that minimizes your coding.
Borland's C++ Developer does this:
http://www.borland.com/us/products/cbuil...
So does Microsoft's Visual C++ Express:
http://msdn.microsoft.com/vstudio/expres...
And that tool is free to download / use.
There are also several programs that will convert one programming language to another; for example, a Visual Basic program to C++.
daffodil
Is there software that will write C++ code automatically?
Depends what you mean. If you mean, you don't have to touch any code, period, the short answer is no.
There are a number of IDEs (integrated development environments) that allow you to visually drag and drop elements into a project, and then specify certain parameters via a form; that minimizes your coding.
Borland's C++ Developer does this:
http://www.borland.com/us/products/cbuil...
So does Microsoft's Visual C++ Express:
http://msdn.microsoft.com/vstudio/expres...
And that tool is free to download / use.
There are also several programs that will convert one programming language to another; for example, a Visual Basic program to C++.
daffodil
I need help to write this C++ code urgently. I don't know where to start??
A.) Write a function named powfun () that raises an integer number passed to it to a positive integer power and displays the result. The positive integer should be the second value passed th the function. Declare the variable used to store the result as a long-integer data type to ensure sufficient storage for the result.
B.) Include the function written in (A.) in a working program. Make sure your function is called from main ().
Test the function by passing various data to it.
I need help to write this C++ code urgently. I don't know where to start??
just first try to learn c++ then code otherwise u will start hating it.
Reply:unsigned long powfun(int base, int power)
{
unsigned long res = 1;
for (int i=power; i%26gt;=1; --i)
res = res * base;
return res;
}
Now, do the main() function yourself.
Reply:A) create a function that returns long-integer
make sure the function has 2 parameters one for the base and one for the power.. example call power_func(base, power); once u have the skeleton done, write a loop the decreases Power until it is one, every time it decreases the power it should multiply the base time its self and store that into a temp. variable, then return That temp variable outside ur loop, after it
also u have to account for the 0th power which is always 1, u might want to block ur while with an if statement
Thats a normal way for doing powering , there are way faster algorithms out there for fast powering, like interval halving
Reply:#include %26lt;stdio.h%26gt;
#include %26lt;stdlib.h%26gt;
#include %26lt;math.h%26gt;
int main()
{
int integer,
power,
result;
printf("Please input the integer\n");
scanf("%d",%26amp;integer);
printf("Please input the power\n");
scanf("%d",%26amp;power);
{
result=pow(integer,power);
}
printf("%d raised to the %d power is %d",integer,power,result);
system("PAUSE");
return 0;
}
B.) Include the function written in (A.) in a working program. Make sure your function is called from main ().
Test the function by passing various data to it.
I need help to write this C++ code urgently. I don't know where to start??
just first try to learn c++ then code otherwise u will start hating it.
Reply:unsigned long powfun(int base, int power)
{
unsigned long res = 1;
for (int i=power; i%26gt;=1; --i)
res = res * base;
return res;
}
Now, do the main() function yourself.
Reply:A) create a function that returns long-integer
make sure the function has 2 parameters one for the base and one for the power.. example call power_func(base, power); once u have the skeleton done, write a loop the decreases Power until it is one, every time it decreases the power it should multiply the base time its self and store that into a temp. variable, then return That temp variable outside ur loop, after it
also u have to account for the 0th power which is always 1, u might want to block ur while with an if statement
Thats a normal way for doing powering , there are way faster algorithms out there for fast powering, like interval halving
Reply:#include %26lt;stdio.h%26gt;
#include %26lt;stdlib.h%26gt;
#include %26lt;math.h%26gt;
int main()
{
int integer,
power,
result;
printf("Please input the integer\n");
scanf("%d",%26amp;integer);
printf("Please input the power\n");
scanf("%d",%26amp;power);
{
result=pow(integer,power);
}
printf("%d raised to the %d power is %d",integer,power,result);
system("PAUSE");
return 0;
}
Is it possible to copy your c++ code and put into a word file? If so, how is it done?
C++ or any code prior to compilation or interpretation is a text file fun through a parser, etc. All you need to do is either cut-n-paste, as above, or open the file in Word, or whatever editor.
Is it possible to copy your c++ code and put into a word file? If so, how is it done?
Yea, you copy the code from your compilers editor and then paste it into word or elsewhere.
Is it possible to copy your c++ code and put into a word file? If so, how is it done?
Yea, you copy the code from your compilers editor and then paste it into word or elsewhere.
I need to have the the c++ code for this one..i really need it...help me pls!!!!?
The first output is:
Group Project in
IT221-Data Structures
Submitted by:
Juna Char
Mai Char
submitted to:
Emo
please press enter to continue....
The second output is:
Select the following choices:
1. STACKS
2. QUEUES
3. TREE
4. SORTING
*Under the Stacks you can have 1 sample program
like testing contiguous implementation.
*Under the Queues you can have 1 sample program
like Using queues of strings.
*Under the Tree you can have traversal or binary tree.
*and under the Sorting you can have the 3 simple sorting:
bubble sorting, selection sorting and insertion.
2 days ago - 1 day left to answer
I need to have the the c++ code for this one..i really need it...help me pls!!!!?
Just a thought, but by looking at this problem you are in about a freshman/sophomore college level class, most likely going into Computer Science or Management Information Systems... Since you chose this degree, I suppose you have many more courses to take, such as OS, Architecture, Automata, SE, etc, you might want to learn about basic programming and data structures... Try learning it on your own... It might help for future courses.
Reply:Look, the display is pretty straightforwarward. And it looks like the required actions are display.
My teacher in college told us that C (and C++) is a language that in and of itself doesn't DO much, until you add libraries.
for the display screens on a windows system the libraries you need are iostream and cstdlib which you begin the program by telling the compiler you need thus:
#include %26lt;iostream%26gt;
#include %26lt;cstdlib%26gt;
Because of a change in the language a few years back, the next line is required to keep the syntax from being impossibly convoluted. I won't explain it because it wouldn't help.
using namespace std;
Notice the semicolon at the end. Most but not all of the statements which follow should end with a semicolon. If they don't then the program won't compile.
This next line is the first exception:
void main(){
After this you need to know a few commands/operators:
cout is the standard output. In other words the screen.
%26lt;%26lt; sends something somewhere, usually to cout.
endl. is the end of the line. When you send it to cout it moves to the next line of output.
system() from cstlib is a function which calls another program which is why this can only work with Windows. You;ll be calling a program which doesn't work in Linux or MacOS.
Now for the code:
cout %26lt;%26lt; "Group Project in" %26lt;%26lt; endl;
cout %26lt;%26lt; "IT221-Data Structures" %26lt;%26lt; endl;
cout %26lt;%26lt; endl;
cout %26lt;%26lt; "Submitted by:" %26lt;%26lt; endl;
cout %26lt;%26lt; "Juna Char" %26lt;%26lt; endl;
cout %26lt;%26lt; "Mai Char" %26lt;%26lt; endl;
cout %26lt;%26lt; endl;
cout %26lt;%26lt; "submitted to:" %26lt;%26lt; endl;
cout %26lt;%26lt; "Emo"; %26lt;%26lt; endl;
cout %26lt;%26lt; endl;
cout %26lt;%26lt; endl;
cout %26lt;%26lt; "please ";
system("pause");
That is your first screen and that's all I think you need. Close off the program with a '}' and an enter.
}
Pause stops the program prints out "press any key to continue" and waits for you to press a key before continuing. Therefore all the elements you want are there on the screen.
You probably can do the second screen yourself. If this is for college you should. If you want to know how to implement the menu choices you should tell us how the stacks, queues and trees are implemented. There are two ways of doing each -- with arrays and with pointers -- and we don't have enough information to try any of them.
Group Project in
IT221-Data Structures
Submitted by:
Juna Char
Mai Char
submitted to:
Emo
please press enter to continue....
The second output is:
Select the following choices:
1. STACKS
2. QUEUES
3. TREE
4. SORTING
*Under the Stacks you can have 1 sample program
like testing contiguous implementation.
*Under the Queues you can have 1 sample program
like Using queues of strings.
*Under the Tree you can have traversal or binary tree.
*and under the Sorting you can have the 3 simple sorting:
bubble sorting, selection sorting and insertion.
2 days ago - 1 day left to answer
I need to have the the c++ code for this one..i really need it...help me pls!!!!?
Just a thought, but by looking at this problem you are in about a freshman/sophomore college level class, most likely going into Computer Science or Management Information Systems... Since you chose this degree, I suppose you have many more courses to take, such as OS, Architecture, Automata, SE, etc, you might want to learn about basic programming and data structures... Try learning it on your own... It might help for future courses.
Reply:Look, the display is pretty straightforwarward. And it looks like the required actions are display.
My teacher in college told us that C (and C++) is a language that in and of itself doesn't DO much, until you add libraries.
for the display screens on a windows system the libraries you need are iostream and cstdlib which you begin the program by telling the compiler you need thus:
#include %26lt;iostream%26gt;
#include %26lt;cstdlib%26gt;
Because of a change in the language a few years back, the next line is required to keep the syntax from being impossibly convoluted. I won't explain it because it wouldn't help.
using namespace std;
Notice the semicolon at the end. Most but not all of the statements which follow should end with a semicolon. If they don't then the program won't compile.
This next line is the first exception:
void main(){
After this you need to know a few commands/operators:
cout is the standard output. In other words the screen.
%26lt;%26lt; sends something somewhere, usually to cout.
endl. is the end of the line. When you send it to cout it moves to the next line of output.
system() from cstlib is a function which calls another program which is why this can only work with Windows. You;ll be calling a program which doesn't work in Linux or MacOS.
Now for the code:
cout %26lt;%26lt; "Group Project in" %26lt;%26lt; endl;
cout %26lt;%26lt; "IT221-Data Structures" %26lt;%26lt; endl;
cout %26lt;%26lt; endl;
cout %26lt;%26lt; "Submitted by:" %26lt;%26lt; endl;
cout %26lt;%26lt; "Juna Char" %26lt;%26lt; endl;
cout %26lt;%26lt; "Mai Char" %26lt;%26lt; endl;
cout %26lt;%26lt; endl;
cout %26lt;%26lt; "submitted to:" %26lt;%26lt; endl;
cout %26lt;%26lt; "Emo"; %26lt;%26lt; endl;
cout %26lt;%26lt; endl;
cout %26lt;%26lt; endl;
cout %26lt;%26lt; "please ";
system("pause");
That is your first screen and that's all I think you need. Close off the program with a '}' and an enter.
}
Pause stops the program prints out "press any key to continue" and waits for you to press a key before continuing. Therefore all the elements you want are there on the screen.
You probably can do the second screen yourself. If this is for college you should. If you want to know how to implement the menu choices you should tell us how the stacks, queues and trees are implemented. There are two ways of doing each -- with arrays and with pointers -- and we don't have enough information to try any of them.
Guys.. can u translate it into C++ code?? please....?
Sub SingleSorter( byRef arrArray)
Dim row, j
Dim StartingKeyValue, NewKeyValue, swap_pos
For row = 0 To UBound( arrArray ) - 1
'Take a snapshot of the first element
'in the array because if there is a
'smaller value elsewhere in the array
'we'll need to do a swap.
StartingKeyValue = arrArray ( row )
NewKeyValue = arrArray ( row )
swap_pos = row
For j = row + 1 to UBound( arrArray )
'Start inner loop.
If arrArray ( j ) %26lt; NewKeyValue Then
'This is now the lowest number -
'remember it's position.
swap_pos = j
NewKeyValue = arrArray ( j )
End If
Next
If swap_pos %26lt;%26gt; row Then
'If we get here then we are about to do a swap
'within the array.
arrArray ( swap_pos ) = StartingKeyValue
arrArray ( row ) = NewKeyValue
End If
Next
End Sub
Guys.. can u translate it into C++ code?? please....?
Let me guess, you needed Bubble sort in c++, couldn't figure it out on your own. You googled, but got the code in VB instead. Pathetic.
You would get better help if you wanted to seriously learn the algorithms at hand.
Reply:ya that first guy was right on
this is for asking questions, not getting people just to do work for u
hyacinth
Dim row, j
Dim StartingKeyValue, NewKeyValue, swap_pos
For row = 0 To UBound( arrArray ) - 1
'Take a snapshot of the first element
'in the array because if there is a
'smaller value elsewhere in the array
'we'll need to do a swap.
StartingKeyValue = arrArray ( row )
NewKeyValue = arrArray ( row )
swap_pos = row
For j = row + 1 to UBound( arrArray )
'Start inner loop.
If arrArray ( j ) %26lt; NewKeyValue Then
'This is now the lowest number -
'remember it's position.
swap_pos = j
NewKeyValue = arrArray ( j )
End If
Next
If swap_pos %26lt;%26gt; row Then
'If we get here then we are about to do a swap
'within the array.
arrArray ( swap_pos ) = StartingKeyValue
arrArray ( row ) = NewKeyValue
End If
Next
End Sub
Guys.. can u translate it into C++ code?? please....?
Let me guess, you needed Bubble sort in c++, couldn't figure it out on your own. You googled, but got the code in VB instead. Pathetic.
You would get better help if you wanted to seriously learn the algorithms at hand.
Reply:ya that first guy was right on
this is for asking questions, not getting people just to do work for u
hyacinth
Please people help me with a c code which compresses files by conversion bmp to jpg?or where should i search?
its urgent!
Please people help me with a c code which compresses files by conversion bmp to jpg?or where should i search?
.bmp is a more of a microsoft paint extension, that and most websites will not be able to upload a picture with that extension anyway.
Go with jpg or jpeg, this is a universal format.. any website host can upload them and they are much smaller in size than .bmp's are
Reply:u just need to open ur pic using mspaint(in run command u type mspaint and open ur file) and then save as ur file whatever u extension u want it always be in compressed form ....have a fun!
Reply:http://www.wikipedia.org
Please people help me with a c code which compresses files by conversion bmp to jpg?or where should i search?
.bmp is a more of a microsoft paint extension, that and most websites will not be able to upload a picture with that extension anyway.
Go with jpg or jpeg, this is a universal format.. any website host can upload them and they are much smaller in size than .bmp's are
Reply:u just need to open ur pic using mspaint(in run command u type mspaint and open ur file) and then save as ur file whatever u extension u want it always be in compressed form ....have a fun!
Reply:http://www.wikipedia.org
Can u provide me with a c code for logic given below.......?
$GPRMC,040302.663,A,3939.7,N,10506.6,W,0...
$GPRMC,
040302.663, //time (current IST=Time+5.30)
A, //Validate (OK)
3939.7675,N, //Latitude ddmm.mmmm
10506.64565,W, //Longitude dddmm.mmmm
0.27,
358.86,
200804, //Date
,*1A
/**********Latitude Calculation**************/
ddmm.mmmm = 3939.7675
dd=39
mm.mmmm= 39.7675
minutes= mm.mmmm/60 =0.66279
decimal format = dd + minutes
= 39.66279
/************longitude calculation***********/
dddmm.mmmm= 10506.6456
ddd= 105
mm.mmmm= 06.64565
minutes= mm.mmmm/60 = 0.11076
decimal format = dd + minutes
= 105.11076
/*******Coordiantes to enter in Google Earth************/
Latitude, longitude
39.66279,105.11076
39.66279N,105.11076E
+39.66279,+105.11076
Can u provide me with a c code for logic given below.......?
try c compiler ,or just printf them all
Reply:I can surely but not getting what have you writte mail me regarding this if you want the source code and your question.
$GPRMC,
040302.663, //time (current IST=Time+5.30)
A, //Validate (OK)
3939.7675,N, //Latitude ddmm.mmmm
10506.64565,W, //Longitude dddmm.mmmm
0.27,
358.86,
200804, //Date
,*1A
/**********Latitude Calculation**************/
ddmm.mmmm = 3939.7675
dd=39
mm.mmmm= 39.7675
minutes= mm.mmmm/60 =0.66279
decimal format = dd + minutes
= 39.66279
/************longitude calculation***********/
dddmm.mmmm= 10506.6456
ddd= 105
mm.mmmm= 06.64565
minutes= mm.mmmm/60 = 0.11076
decimal format = dd + minutes
= 105.11076
/*******Coordiantes to enter in Google Earth************/
Latitude, longitude
39.66279,105.11076
39.66279N,105.11076E
+39.66279,+105.11076
Can u provide me with a c code for logic given below.......?
try c compiler ,or just printf them all
Reply:I can surely but not getting what have you writte mail me regarding this if you want the source code and your question.
What would this look like in C++ code?
A program that finds the smallest element in the array of integers.
What would this look like in C++ code?
Amanda's answer is good, but it may be slow when your array is very large. Since most data sets are usually larger than N%26gt;=20 the algorithm I am giving is going to be more useful when dealing with an unsorted array. It may seem long but it is a very powerful algorithm. I apologize for the lack of formatting because it won't accept my spaces.
int quicksort(vector %26amp; A, int left, int right)
{
if(left + 10 %26lt;= right){
int pivot = median(A, left, right);
int i = left, j = right-1;
for( , , ){
while(A[++i] %26lt; pivot) {}
while(pivot %26lt; A[--j]) {}
if(i %26lt; j)
swap(A[i], A[j]);
else
break;
}
swap(A[i], A[right - 1]);
quicksort(A, left, i -1); // sort small elements
quicksort(A, i+1, right); // sort large elements
}
else
insertionSort(A, left, right);
/* array is now sorted so you can select any element you want be it the smallest or the largest because the array is sorted */
return A[0];
}
const int median(vector %26amp; A, int left, int right)
{
int center = (left+right)/2;
if(A[center] %26lt; A[left])
swap(A[left], A[center]);
if(A[right] %26lt; A[left])
swap(A[left], A[right]);
if(A[right] %26lt; A[center])
swap(A[center], A[right]);
swap(A[center], A[right-1]);
return A[right-1];
}
void insertionSort(vector %26amp; A)
{
int j;
for(int p=1; p%26lt;A.size(); p++){
int tmp = A[p];
for(j = p; j %26gt; 0 %26amp;%26amp; tmp %26lt; A[j-1]; j--)
A[j] = A[j-1];
A[j] = tmp;
}
}
Now you can easily find minimum numbers in very large arrays with no problem.
I forgot to mention you need to include %26lt;algorithm%26gt; to use the swap function.
PS - All the other solutions posted so far are really stupid because finding the minimum in say 100 million integers is going to take forever. Also one of them is incorrect.
Reply:#include %26lt;algorithm%26gt;
return *std::min_element(array, array + size);
The std library has many useful routines for doing things like searching, sorting and whatnot.
The previous posters gave good information if you need to write it yourself.
Reply:the easiest way is a for loop:
int smallest=array[0];
for(int i=0; i%26lt;array.length; i++){
__if(array[i]%26lt;smallest)
_____smallest=array[i];
}
that will compare every element in the array.
the underscores are cause its easier to read w/ formatting, but yahoo isn't letting me do that right now. :)
Reply:#include %26lt;iostream%26gt;
using namespace std;
int main(){
//This is an int because I like to return 0.
int alphabet[]={12, 2, 7, 6,39}; //hey, I wanted an array.
int SizeOf=5; //It's always better to assign size of array to a variable
// or macro
int Least; // to hold the smallest number.
Least=alphabet[0];
//No braces because I'm only repeating one
//test/action.
for (int i=1;i%26lt;=SizeOf;i++) if (alphabet[i]%26lt;Least) Least=alphabet[i];
// print out the smallest value.
cout %26lt;%26lt; Least %26lt;%26lt; endl;
// tell the OS all is well and bail.
return 0;
}
Reply:int findSmallest(int *arr, int max) {
int smallest = arr[0];
for (int i=1; i%26lt;max; i++)
if (arr[i] %26lt; smallest)
smallest = arr[i];
return smallest;
}
Reply:const int ARRAY_SIZE = 35;
int array[ARRAY_SIZE] = {4,6,2,9,7,0,1,5,7,4,3,7,9,0,1,3,45,6,7,...
int SmallestElementIndex = 0;
int SmallestElement = array[SmallestElementIndex];
for (int i = 0; i %26lt; ARRAY_SIZE; i++)
{
if(array[i] %26lt; SmallestElement)
{
SmallestElement = array[i];
SmallestElementIndex = i;
}
}
This code finds the smallest integer in the array, and also stores the index of that item. If there are multiple elements that have the same value as the smallest integer then the index will be the lowest index (first occurring smallest integer).
What would this look like in C++ code?
Amanda's answer is good, but it may be slow when your array is very large. Since most data sets are usually larger than N%26gt;=20 the algorithm I am giving is going to be more useful when dealing with an unsorted array. It may seem long but it is a very powerful algorithm. I apologize for the lack of formatting because it won't accept my spaces.
int quicksort(vector %26amp; A, int left, int right)
{
if(left + 10 %26lt;= right){
int pivot = median(A, left, right);
int i = left, j = right-1;
for( , , ){
while(A[++i] %26lt; pivot) {}
while(pivot %26lt; A[--j]) {}
if(i %26lt; j)
swap(A[i], A[j]);
else
break;
}
swap(A[i], A[right - 1]);
quicksort(A, left, i -1); // sort small elements
quicksort(A, i+1, right); // sort large elements
}
else
insertionSort(A, left, right);
/* array is now sorted so you can select any element you want be it the smallest or the largest because the array is sorted */
return A[0];
}
const int median(vector %26amp; A, int left, int right)
{
int center = (left+right)/2;
if(A[center] %26lt; A[left])
swap(A[left], A[center]);
if(A[right] %26lt; A[left])
swap(A[left], A[right]);
if(A[right] %26lt; A[center])
swap(A[center], A[right]);
swap(A[center], A[right-1]);
return A[right-1];
}
void insertionSort(vector %26amp; A)
{
int j;
for(int p=1; p%26lt;A.size(); p++){
int tmp = A[p];
for(j = p; j %26gt; 0 %26amp;%26amp; tmp %26lt; A[j-1]; j--)
A[j] = A[j-1];
A[j] = tmp;
}
}
Now you can easily find minimum numbers in very large arrays with no problem.
I forgot to mention you need to include %26lt;algorithm%26gt; to use the swap function.
PS - All the other solutions posted so far are really stupid because finding the minimum in say 100 million integers is going to take forever. Also one of them is incorrect.
Reply:#include %26lt;algorithm%26gt;
return *std::min_element(array, array + size);
The std library has many useful routines for doing things like searching, sorting and whatnot.
The previous posters gave good information if you need to write it yourself.
Reply:the easiest way is a for loop:
int smallest=array[0];
for(int i=0; i%26lt;array.length; i++){
__if(array[i]%26lt;smallest)
_____smallest=array[i];
}
that will compare every element in the array.
the underscores are cause its easier to read w/ formatting, but yahoo isn't letting me do that right now. :)
Reply:#include %26lt;iostream%26gt;
using namespace std;
int main(){
//This is an int because I like to return 0.
int alphabet[]={12, 2, 7, 6,39}; //hey, I wanted an array.
int SizeOf=5; //It's always better to assign size of array to a variable
// or macro
int Least; // to hold the smallest number.
Least=alphabet[0];
//No braces because I'm only repeating one
//test/action.
for (int i=1;i%26lt;=SizeOf;i++) if (alphabet[i]%26lt;Least) Least=alphabet[i];
// print out the smallest value.
cout %26lt;%26lt; Least %26lt;%26lt; endl;
// tell the OS all is well and bail.
return 0;
}
Reply:int findSmallest(int *arr, int max) {
int smallest = arr[0];
for (int i=1; i%26lt;max; i++)
if (arr[i] %26lt; smallest)
smallest = arr[i];
return smallest;
}
Reply:const int ARRAY_SIZE = 35;
int array[ARRAY_SIZE] = {4,6,2,9,7,0,1,5,7,4,3,7,9,0,1,3,45,6,7,...
int SmallestElementIndex = 0;
int SmallestElement = array[SmallestElementIndex];
for (int i = 0; i %26lt; ARRAY_SIZE; i++)
{
if(array[i] %26lt; SmallestElement)
{
SmallestElement = array[i];
SmallestElementIndex = i;
}
}
This code finds the smallest integer in the array, and also stores the index of that item. If there are multiple elements that have the same value as the smallest integer then the index will be the lowest index (first occurring smallest integer).
I have to input integer for c++ code how can i check whether the user input integer or a string character?
then if he input a charecter how to promt him to enter integer again
I have to input integer for c++ code how can i check whether the user input integer or a string character?
there are functions available in ctype.h header
isalph()
isalnum()
isdigit()
use them
Reply:all input is char values, they must be converted to int values, I believe 0 the character 0 is equal to 32, but you can say
if(x%26gt;='0' || x%26lt;'9') then
{
cout%26lt;%26lt;"This character is a number"
}
if you then wanted to convert it to a real number just subtract the character 0 from it IE '9' - '0' = 9
I have to input integer for c++ code how can i check whether the user input integer or a string character?
there are functions available in ctype.h header
isalph()
isalnum()
isdigit()
use them
Reply:all input is char values, they must be converted to int values, I believe 0 the character 0 is equal to 32, but you can say
if(x%26gt;='0' || x%26lt;'9') then
{
cout%26lt;%26lt;"This character is a number"
}
if you then wanted to convert it to a real number just subtract the character 0 from it IE '9' - '0' = 9
How to unlock SAMSONITE luggage b/c code is lost? Is it possible?
See websites below. Hope you can do it ok.
How to unlock SAMSONITE luggage b/c code is lost? Is it possible?
The plastic method works like a charm. thanks!! Report It
Reply:I had to bust mine open with a screwdriver
Reply:metacafe.com has a video on one way to do it.
There is another way. You can use a small piece of plastic like they use on bread wrappers. Cut a "V" shaped point into it. Slip the pointed in adjacent to the wheels. Turn the wheels until you feel the plastic fall into the notch.
Then go to the next wheel and do the same. Then to the last one.
If you get in touch with samsonite they will send you the instructions and a piece of plastic to do it with.
You might find instructions on their web site. Good luck.
How to unlock SAMSONITE luggage b/c code is lost? Is it possible?
The plastic method works like a charm. thanks!! Report It
Reply:I had to bust mine open with a screwdriver
Reply:metacafe.com has a video on one way to do it.
There is another way. You can use a small piece of plastic like they use on bread wrappers. Cut a "V" shaped point into it. Slip the pointed in adjacent to the wheels. Turn the wheels until you feel the plastic fall into the notch.
Then go to the next wheel and do the same. Then to the last one.
If you get in touch with samsonite they will send you the instructions and a piece of plastic to do it with.
You might find instructions on their web site. Good luck.
What would this look like in C++ code?
a program that reads ten numbers (in an array), and counts the number of elements in the array that are divisible by 3.
What would this look like in C++ code?
#include%26lt;iostream.h%26gt;
#include%26lt;conio.h%26gt;
void main()
{
clrscr();
int arr[10];int ctr=0;
cout%26lt;%26lt;"Enter 10 numbers";
for(int i=0,i%26lt;10,i++)
{
cin%26gt;%26gt;arr[i];
if((arr[i]%3)==0)
ctr++;
}
cout%26lt;%26lt;"The no of elements divisible by 3 are"%26lt;%26lt;ctr;
}
Reply:Assuming you already have the numbers in an array called "numbers":
int count = 0;
for(int i = 0 ; i%26lt;10 ; i++){
if(numbers[i] % 3 ==0){
count++;
}
}
The variable "count" will have what you need. Just stick that into a function.
What would this look like in C++ code?
#include%26lt;iostream.h%26gt;
#include%26lt;conio.h%26gt;
void main()
{
clrscr();
int arr[10];int ctr=0;
cout%26lt;%26lt;"Enter 10 numbers";
for(int i=0,i%26lt;10,i++)
{
cin%26gt;%26gt;arr[i];
if((arr[i]%3)==0)
ctr++;
}
cout%26lt;%26lt;"The no of elements divisible by 3 are"%26lt;%26lt;ctr;
}
Reply:Assuming you already have the numbers in an array called "numbers":
int count = 0;
for(int i = 0 ; i%26lt;10 ; i++){
if(numbers[i] % 3 ==0){
count++;
}
}
The variable "count" will have what you need. Just stick that into a function.
Can I use winvi to save C code and open it using a Unix shell already running on a windows os ?
I'm familiar with Windows and UNIX, but have no experience with Winvi. I'm taking a wild shot and saying that it will either be compatible in a UNIX shell, or not. If it does the wierd line marker syndrome, then you can rectify that with a free utility available from the URL below, called ToFroDOS. This should make life bearable with little bells or whistles.
cosmos
cosmos
I am searching for Java or C code that does Euclidean alignment of two 3D point sets. Anyone know of any?
The algorithm needs to handle 2 point sets that do not necessarily have the same cardinality. If you know of a MATLAB toolkit or library that does that, that'd work as well. Thanks a lot to anyone who responds.
I am searching for Java or C code that does Euclidean alignment of two 3D point sets. Anyone know of any?
I'm not familiar with any code, or those mathematical concepts for that matter, but you could try entering different things into Google Code Search:
google [DOT] com [SLASH] codesearch
(Yahoo kept giving me errors trying to submit with the actual URL...)
You can include in your search:
lang:c
or:
lang:java
to specify you only want results in one particular programing language.
I am searching for Java or C code that does Euclidean alignment of two 3D point sets. Anyone know of any?
I'm not familiar with any code, or those mathematical concepts for that matter, but you could try entering different things into Google Code Search:
google [DOT] com [SLASH] codesearch
(Yahoo kept giving me errors trying to submit with the actual URL...)
You can include in your search:
lang:c
or:
lang:java
to specify you only want results in one particular programing language.
How to do the Histogram equalization + C code using opencv in linux?
My task is to write a program to perform histogram
equalisation on a image.
My program should take 6 parameters as follows:
equalise input.bmp output.bmp 100 200 300 400
This should load the input.bmp image and produce the output.bmp file.
The equalisation should be based on a histogram from the rectangular area in the image defined by the points (x,y) and (x',y').
any help welcom
cheers
How to do the Histogram equalization + C code using opencv in linux?
Browse some of these links for ideas, algorithm descriptions, etc., in the comments.
http://www.google.com/search?q=%22histog...
equalisation on a image.
My program should take 6 parameters as follows:
equalise input.bmp output.bmp 100 200 300 400
This should load the input.bmp image and produce the output.bmp file.
The equalisation should be based on a histogram from the rectangular area in the image defined by the points (x,y) and (x',y').
any help welcom
cheers
How to do the Histogram equalization + C code using opencv in linux?
Browse some of these links for ideas, algorithm descriptions, etc., in the comments.
http://www.google.com/search?q=%22histog...
How to identify the cis-elements in genomic DNA? also how to script a simple code in C/perl to do the same.?
to identify, one should look for physical or chemical traits of cis-elements in genomic DNA.
please do mention how the cis-elements can be identified in a strand of genomic DNA.
the code should take in a sample DNA strand as the input and identify and give the cis-element in that as the output. the code can be in either C or perl or any programing language.
How to identify the cis-elements in genomic DNA? also how to script a simple code in C/perl to do the same.?
Your description of the methodology sounds correct, but I do not have any code that would search for only cis-elements.
please do mention how the cis-elements can be identified in a strand of genomic DNA.
the code should take in a sample DNA strand as the input and identify and give the cis-element in that as the output. the code can be in either C or perl or any programing language.
How to identify the cis-elements in genomic DNA? also how to script a simple code in C/perl to do the same.?
Your description of the methodology sounds correct, but I do not have any code that would search for only cis-elements.
How do i condience this c++ code to make it less crowded?
for ( int year = 2007; year %26lt;= 2037; year++ )
{
amount = amount * rate + principal;
principal = principal + 200;
principal = principal + 200;
principal = principal + 200;
principal = principal + 200;
principal = principal + 200;
principal = principal + 200;
principal = principal + 200;
principal = principal + 200;
principal = principal + 200;
principal = principal + 200;
principal = principal + 200;
principal = principal + 200;
out %26lt;%26lt; setw ( 4 ) %26lt;%26lt; year %26lt;%26lt; setw ( 34 ) %26lt;%26lt; amount %26lt;%26lt; endl;
}
out.close();
return 0;
}
How do i condience this c++ code to make it less crowded?
It seems like perhaps something is missing here anyway. You calculate "amount" once and then don't do anything with it until you print it out in the end. Is amount supposed to be somewhere in that equation? I get the impression you are trying to do compound interest. Anyway, if that is the case, I would recommend a for loop:
for(int i = 1; i%26lt;=12; i++)
{
// Do your equation
}
Reply:Would you mind telling me what you're trying to achieve there. Because if its SI/CI you're trying to do there, I just cant figure it out
Reply:for ( int year = 2007; year %26lt;= 2037; year++ )
{
amount = amount * rate + principal;
principal+=200*12;
out%26lt;%26lt;setw(4)%26lt;%26lt;year%26lt;%26lt;setw(34)%26lt;%26lt;amount%26lt;,...
}
out.close();
return 0;
}
online florists
{
amount = amount * rate + principal;
principal = principal + 200;
principal = principal + 200;
principal = principal + 200;
principal = principal + 200;
principal = principal + 200;
principal = principal + 200;
principal = principal + 200;
principal = principal + 200;
principal = principal + 200;
principal = principal + 200;
principal = principal + 200;
principal = principal + 200;
out %26lt;%26lt; setw ( 4 ) %26lt;%26lt; year %26lt;%26lt; setw ( 34 ) %26lt;%26lt; amount %26lt;%26lt; endl;
}
out.close();
return 0;
}
How do i condience this c++ code to make it less crowded?
It seems like perhaps something is missing here anyway. You calculate "amount" once and then don't do anything with it until you print it out in the end. Is amount supposed to be somewhere in that equation? I get the impression you are trying to do compound interest. Anyway, if that is the case, I would recommend a for loop:
for(int i = 1; i%26lt;=12; i++)
{
// Do your equation
}
Reply:Would you mind telling me what you're trying to achieve there. Because if its SI/CI you're trying to do there, I just cant figure it out
Reply:for ( int year = 2007; year %26lt;= 2037; year++ )
{
amount = amount * rate + principal;
principal+=200*12;
out%26lt;%26lt;setw(4)%26lt;%26lt;year%26lt;%26lt;setw(34)%26lt;%26lt;amount%26lt;,...
}
out.close();
return 0;
}
online florists
I need help converting this c++ code into .asm?
sort (int *list,int len){
for(i=len;i%26gt;1;i--)
for(j=0;j%26lt;i-1;j++)
if(list[j]%26gt;list[j+1]){
tmp=list[j];
list[j]=list[j+1];
list[j+1]=tmp;
}
}
I need help converting this c++ code into .asm?
Dude. You need to get a good book on assembly code and start loading values into registers and branching. You can find tons of code examples online via Google and might be able to find some assembly code to do a basic sort such as the one you coded. I wrote a merge sort program in x86 assembly a while ago so I know it is possible! :) Cheers!
Reply:make it an exe.
Then assemler program to see assemler codes
for(i=len;i%26gt;1;i--)
for(j=0;j%26lt;i-1;j++)
if(list[j]%26gt;list[j+1]){
tmp=list[j];
list[j]=list[j+1];
list[j+1]=tmp;
}
}
I need help converting this c++ code into .asm?
Dude. You need to get a good book on assembly code and start loading values into registers and branching. You can find tons of code examples online via Google and might be able to find some assembly code to do a basic sort such as the one you coded. I wrote a merge sort program in x86 assembly a while ago so I know it is possible! :) Cheers!
Reply:make it an exe.
Then assemler program to see assemler codes
Im trying to write some C++ code that starts at 2 and counts up by 2 to 100. Can anyone help?(Exam in details)
int main()
{
counter=2;
do {
cout %26lt;%26lt; counter;counter%26gt;=2%26lt;%26lt; endl;
} while (counter %26lt;100);
Im trying to write some C++ code that starts at 2 and counts up by 2 to 100. Can anyone help?(Exam in details)
int main()
{
int counter=2;
do
{
cout %26lt;%26lt; counter%26lt;%26lt;endl; //print out the current value of counter
counter+=2; //increase counter by 1 each time
}
while (counter %26lt;=100); // You want it to get 100 so u need the equal
OR THIS ONE
int main()
{
for(int counter=2;counter%26lt;=100;counter+=2)
{
//print out the current value of counter
cout %26lt;%26lt; counter%26lt;%26lt;endl;
}
}
OR THIS ONE
int main()
{
int counter =2;
while(counter%26lt;=100)
{
cout%26lt;%26lt;counter%26lt;%26lt;endl;
counter =counter+2;
}
}
Im a Programmer from Microsoft
Reply:I've forgotten how to code in C but you are not adding to your counter
It sounds like your a beginner in C you should really get a reference book.
Reply:int main()
{
int counter=2;
do{
cout%26lt;%26lt; counter %26lt;%26lt; endl;
counter+=2;
}
while (counter%26lt;100);
}
Another one...
int main()
{
for (int index=0;index%26lt;100;index+=2)
{
cout%26lt;%26lt;index%26lt;%26lt;endl;
}
}
Reply:you can use eifther for loop or while loop.
example
int i=2;
for(;i%26lt;102;i+=2)
{
... your code
}
or
int i=2;
do
{
...your code
i +=2;
}while(i%26lt;102);
Reply:well, try this inside do {} instead of what you have
cout %26lt;%26lt; counter %26lt;%26lt;endl;
counter+=2;
and Im not sure if you missed this or not, there should a closing bracket to close the opened bracket after int main ()
This } should go after while statement.
{
counter=2;
do {
cout %26lt;%26lt; counter;counter%26gt;=2%26lt;%26lt; endl;
} while (counter %26lt;100);
Im trying to write some C++ code that starts at 2 and counts up by 2 to 100. Can anyone help?(Exam in details)
int main()
{
int counter=2;
do
{
cout %26lt;%26lt; counter%26lt;%26lt;endl; //print out the current value of counter
counter+=2; //increase counter by 1 each time
}
while (counter %26lt;=100); // You want it to get 100 so u need the equal
OR THIS ONE
int main()
{
for(int counter=2;counter%26lt;=100;counter+=2)
{
//print out the current value of counter
cout %26lt;%26lt; counter%26lt;%26lt;endl;
}
}
OR THIS ONE
int main()
{
int counter =2;
while(counter%26lt;=100)
{
cout%26lt;%26lt;counter%26lt;%26lt;endl;
counter =counter+2;
}
}
Im a Programmer from Microsoft
Reply:I've forgotten how to code in C but you are not adding to your counter
It sounds like your a beginner in C you should really get a reference book.
Reply:int main()
{
int counter=2;
do{
cout%26lt;%26lt; counter %26lt;%26lt; endl;
counter+=2;
}
while (counter%26lt;100);
}
Another one...
int main()
{
for (int index=0;index%26lt;100;index+=2)
{
cout%26lt;%26lt;index%26lt;%26lt;endl;
}
}
Reply:you can use eifther for loop or while loop.
example
int i=2;
for(;i%26lt;102;i+=2)
{
... your code
}
or
int i=2;
do
{
...your code
i +=2;
}while(i%26lt;102);
Reply:well, try this inside do {} instead of what you have
cout %26lt;%26lt; counter %26lt;%26lt;endl;
counter+=2;
and Im not sure if you missed this or not, there should a closing bracket to close the opened bracket after int main ()
This } should go after while statement.
How can i create a c++ code?
1. example of conversion number to word ?
2. example of fibonacci
3. example of sum of powers
4. example of reverse
How can i create a c++ code?
What??
Reply:were we asleep during the lectures.....
as m sure you are well aware yto create the code all you need is an editor, and if you want to make sure its valid a compiler
Reply:Yeah all you need is an editor.... try dreamweaver!
Reply:Here is some code sequences that may help you for the Fibonacci. Please note that you need to be careful how many iterations that you run because it can take a large ammount of time to make the calculations.
#include %26lt;iostream%26gt;
using namespace std;
long fib_num ( long );
int main()
{
long num = 0;
long sequence = 0;
cout %26lt;%26lt; " Enter a positive number and I will compute the Fibonacci sequence for that number: ";
cin %26gt;%26gt; num;
if ( num %26lt; 0)
{ cout %26lt;%26lt; " Number must be greater than zero " %26lt;%26lt; endl;
return 1;
}
cout %26lt;%26lt; endl %26lt;%26lt; endl;
sequence = fib_num(num);
cout %26lt;%26lt; " The " %26lt;%26lt; num %26lt;%26lt; "th number of the Fibonacci sequence is " %26lt;%26lt; sequence %26lt;%26lt; endl;
return 0;
}
long fib_num ( long n)
{
if ( n == 0)
{
return 0;
}
else if ( n == 1 )
{
return 1;
}
else
return fib_num( n -1) + fib_num(n-2);
}
Reply:So, let me guess you are looking for answers on a homework assignment that is due in the near future. Do like every one else and do the research on these topics. This is not the best forum to explain these complicated problems.
Reply:If you're referring to 'a c++ code', you've got a bit more to learn before you start trying to actually program I think.
2. example of fibonacci
3. example of sum of powers
4. example of reverse
How can i create a c++ code?
What??
Reply:were we asleep during the lectures.....
as m sure you are well aware yto create the code all you need is an editor, and if you want to make sure its valid a compiler
Reply:Yeah all you need is an editor.... try dreamweaver!
Reply:Here is some code sequences that may help you for the Fibonacci. Please note that you need to be careful how many iterations that you run because it can take a large ammount of time to make the calculations.
#include %26lt;iostream%26gt;
using namespace std;
long fib_num ( long );
int main()
{
long num = 0;
long sequence = 0;
cout %26lt;%26lt; " Enter a positive number and I will compute the Fibonacci sequence for that number: ";
cin %26gt;%26gt; num;
if ( num %26lt; 0)
{ cout %26lt;%26lt; " Number must be greater than zero " %26lt;%26lt; endl;
return 1;
}
cout %26lt;%26lt; endl %26lt;%26lt; endl;
sequence = fib_num(num);
cout %26lt;%26lt; " The " %26lt;%26lt; num %26lt;%26lt; "th number of the Fibonacci sequence is " %26lt;%26lt; sequence %26lt;%26lt; endl;
return 0;
}
long fib_num ( long n)
{
if ( n == 0)
{
return 0;
}
else if ( n == 1 )
{
return 1;
}
else
return fib_num( n -1) + fib_num(n-2);
}
Reply:So, let me guess you are looking for answers on a homework assignment that is due in the near future. Do like every one else and do the research on these topics. This is not the best forum to explain these complicated problems.
Reply:If you're referring to 'a c++ code', you've got a bit more to learn before you start trying to actually program I think.
Can anyone give me the c code for implementation of two queues using a stack and vice versa.?
please try to illustrate with an example .
Can anyone give me the c code for implementation of two queues using a stack and vice versa.?
Im nt getting wht u exactly want to say.What do u mean by two queues?Explain me ur Q,i vl definately solve it.My mail-ID is:
ruhija_29@yahoo.co.in
Reply:www.freewebs.com/dirtyhands
Reply:1234567890....
Reply:www.freewebs.com/dirtyhands
flowers uk
Can anyone give me the c code for implementation of two queues using a stack and vice versa.?
Im nt getting wht u exactly want to say.What do u mean by two queues?Explain me ur Q,i vl definately solve it.My mail-ID is:
ruhija_29@yahoo.co.in
Reply:www.freewebs.com/dirtyhands
Reply:1234567890....
Reply:www.freewebs.com/dirtyhands
flowers uk
How to port a unix c++ code from a 32-bit machine to a 64-bit machine?
Do we have to take special care of floating types?
How to port a unix c++ code from a 32-bit machine to a 64-bit machine?
Nope, just recompile!
How to port a unix c++ code from a 32-bit machine to a 64-bit machine?
Nope, just recompile!
HELP! I have got a C++ code and when I compile I get theses errors?
Line 111 - Unit key.cpp - VK_OEM_4` undeclared (first use this function)
Please tell me what to do??
HELP! I have got a C++ code and when I compile I get theses errors?
You are missing some required header file that you need to #include. Alternatively, you could add the following #defines yourself to your own code so that iut does not need to depend on any other file to get what it means:
===============================
#ifndef VK_OEM_1
#define VK_OEM_1 0xBA
#endif
#ifndef VK_OEM_2
#define VK_OEM_2 0xBF
#endif
#ifndef VK_OEM_3
#define VK_OEM_3 0xC0
#endif
#ifndef VK_OEM_4
#define VK_OEM_4 0xDB
#endif
#ifndef VK_OEM_5
#define VK_OEM_5 0xDC
#endif
#ifndef VK_OEM_6
#define VK_OEM_6 0xDD
#endif
#ifndef VK_OEM_7
#define VK_OEM_7 0xDE
#endif
#ifndef VK_OEM_8
#define VK_OEM_8 0xDF
#endif
===============================
However, this does not guarantee that once this error is gone, you won't get other errors. This solution is for this particluar error, and does not guarantee error-free compilation, if you know what I mean. I mean that if this solves your error, give me 10 points even if you get other errors :-)
UPDATE: Another webpage seems to have an answer as to which exact file you need to #include: looks like adding
#pragma comment(lib, "user32.lib")
or
#include %26lt;Winuser.h%26gt;
might solve your problem. Look here:
http://www.gamerzplanet.net/forums/warcr...
Reply:It means you tried to use a variable you didn't declare yet. Either you forgot to include a header file that declares it (like an external library, for example), or you misspelled the variable's name.
Reply:If that is a copy and past of the error, did you accidentally add a "`" to the end of the variable name. I don't believe that is a normal part of the error.
Reply:#define VK_OEM_4 VK_OEM + 4
... it's a custom variable, or pre-processor macro .. without code or details isn't possible to answer to your question!
Reply:IT looks like there should be a declared value in VK_OEM_4 but there isn't, step threw the code and see it there is a value being place into it.
Reply:Like the others have said the compiler is complaining that VK_OEM_4 is undeclared. VK_OEM_4 does not seem like the name of a variable that you would normally just declare/use yourself, so I did a search and it looks like it is a Windows GUI value. I have not done much with windows programming, but it appears to be a key code value. You can probably find more about it at MSDN.
Please tell me what to do??
HELP! I have got a C++ code and when I compile I get theses errors?
You are missing some required header file that you need to #include. Alternatively, you could add the following #defines yourself to your own code so that iut does not need to depend on any other file to get what it means:
===============================
#ifndef VK_OEM_1
#define VK_OEM_1 0xBA
#endif
#ifndef VK_OEM_2
#define VK_OEM_2 0xBF
#endif
#ifndef VK_OEM_3
#define VK_OEM_3 0xC0
#endif
#ifndef VK_OEM_4
#define VK_OEM_4 0xDB
#endif
#ifndef VK_OEM_5
#define VK_OEM_5 0xDC
#endif
#ifndef VK_OEM_6
#define VK_OEM_6 0xDD
#endif
#ifndef VK_OEM_7
#define VK_OEM_7 0xDE
#endif
#ifndef VK_OEM_8
#define VK_OEM_8 0xDF
#endif
===============================
However, this does not guarantee that once this error is gone, you won't get other errors. This solution is for this particluar error, and does not guarantee error-free compilation, if you know what I mean. I mean that if this solves your error, give me 10 points even if you get other errors :-)
UPDATE: Another webpage seems to have an answer as to which exact file you need to #include: looks like adding
#pragma comment(lib, "user32.lib")
or
#include %26lt;Winuser.h%26gt;
might solve your problem. Look here:
http://www.gamerzplanet.net/forums/warcr...
Reply:It means you tried to use a variable you didn't declare yet. Either you forgot to include a header file that declares it (like an external library, for example), or you misspelled the variable's name.
Reply:If that is a copy and past of the error, did you accidentally add a "`" to the end of the variable name. I don't believe that is a normal part of the error.
Reply:#define VK_OEM_4 VK_OEM + 4
... it's a custom variable, or pre-processor macro .. without code or details isn't possible to answer to your question!
Reply:IT looks like there should be a declared value in VK_OEM_4 but there isn't, step threw the code and see it there is a value being place into it.
Reply:Like the others have said the compiler is complaining that VK_OEM_4 is undeclared. VK_OEM_4 does not seem like the name of a variable that you would normally just declare/use yourself, so I did a search and it looks like it is a Windows GUI value. I have not done much with windows programming, but it appears to be a key code value. You can probably find more about it at MSDN.
Why does this line of C++ code not work?
label1 -%26gt;Text = vScrollBar1-%26gt;Value;
The control names are correct what else can it be ???????
Why does this line of C++ code not work?
vScrollBar1-%26gt;Value provides an integer, while the label1 -%26gt;Text requires a string. Cast vScrollBar1-%26gt;Value to a string and hopefully that should work.
Reply:The first answer looks right to a point.
If you try to do this:
label1 -%26gt;Text = (char)vScrollBar1-%26gt;Value;
you will probably not get what you expect. For example, if vScrollBar1-%26gt;Value=65, then label1 -%26gt;Text will be the ASCII character with value 65, which is 'A'.
You can do the following:
char buffer[10];
sprintf(buffer, "%d", vScrollBar1-%26gt;Value);
label1 -%26gt;Text = buffer;
provided you have the appropriate member to set Text from char[].
cast the integer to char to
You can't cast a integer into text. You can do the following
The control names are correct what else can it be ???????
Why does this line of C++ code not work?
vScrollBar1-%26gt;Value provides an integer, while the label1 -%26gt;Text requires a string. Cast vScrollBar1-%26gt;Value to a string and hopefully that should work.
Reply:The first answer looks right to a point.
If you try to do this:
label1 -%26gt;Text = (char)vScrollBar1-%26gt;Value;
you will probably not get what you expect. For example, if vScrollBar1-%26gt;Value=65, then label1 -%26gt;Text will be the ASCII character with value 65, which is 'A'.
You can do the following:
char buffer[10];
sprintf(buffer, "%d", vScrollBar1-%26gt;Value);
label1 -%26gt;Text = buffer;
provided you have the appropriate member to set Text from char[].
cast the integer to char to
You can't cast a integer into text. You can do the following
What is wrong with this C# code?
I need to get the input of this textbox (which is supposed to be minutes) multiply it by 60, and then output it to textbox2. I get this error though:
Error 1 Cannot implicitly convert type 'int' to 'string'
private void Start2_Click(object sender, EventArgs e)
{
int timer1 = 0;
if (textBox1.Text != "")
timer1 = Convert.ToInt32(textBox1.Text) * 60;
Convert.ToString(timer1);
text2.Text = timer1;
}
What is wrong with this C# code?
It's because when you executed line "Convert.ToString(timer1)", you did not assign it to any string variable. Do this instead:
string text2Display = Convert.ToString(timer1);
text2.Text = text2Display;
Reply:that should be text2.Text = Convert.ToString(timer1)
You cannot change the actual type of timer1 at runtime but you can create a string which contains the textual representation of timer1. Convert.ToString returns a string which is the textual representation of the integer in timer1. And besides, the compiler has no idea what Convert.ToString actuall does( it just knows that its a function that takes in an int and returns a string), so it would have no way of knowing that timer1 should be turned into a string.
hamper
Error 1 Cannot implicitly convert type 'int' to 'string'
private void Start2_Click(object sender, EventArgs e)
{
int timer1 = 0;
if (textBox1.Text != "")
timer1 = Convert.ToInt32(textBox1.Text) * 60;
Convert.ToString(timer1);
text2.Text = timer1;
}
What is wrong with this C# code?
It's because when you executed line "Convert.ToString(timer1)", you did not assign it to any string variable. Do this instead:
string text2Display = Convert.ToString(timer1);
text2.Text = text2Display;
Reply:that should be text2.Text = Convert.ToString(timer1)
You cannot change the actual type of timer1 at runtime but you can create a string which contains the textual representation of timer1. Convert.ToString returns a string which is the textual representation of the integer in timer1. And besides, the compiler has no idea what Convert.ToString actuall does( it just knows that its a function that takes in an int and returns a string), so it would have no way of knowing that timer1 should be turned into a string.
hamper
I need help with this c++ code, when you find the treasure, it is suppose to turn red but it doesn't?
/* Treasure Hunt program */
#include %26lt;lvp\gui_top.h%26gt;
#include %26lt;lvp\matrix.h%26gt;
#include %26lt;lvp\string.h%26gt;
#include %26lt;lvp\bool.h%26gt;
#include %26lt;lvp\random.h%26gt;
//------------------------------------...
class ButtonClass{
public:
ButtonClass(String Text, int X1, int Y1, int X2, int Y2);
/*Post: A button created with upper-left corner at X1,Y1 and
lower-right corner at X2,Y2 with Text centeredin box */
void Paint();
bool IsHit(int x, int y);
/*Post: true returned if and only if (x,y) is on the button*/
private:
int MyX1,MyY1,MyX2,MyY2;
String MyText;
};
//------------------------------------...
ButtonClass::ButtonClass(String Text, int X1, int Y1, int X2, int Y2)
:MyText(Text),MyX1(X1),MyY1(Y1),MyX2(...
/*Post: Button created with upper-left corner at X1, Y1 and
lower right corner at X2,Y2 with Text centered in box */
{
}
//------------------------------------...
void ButtonClass::Paint()
{
SetColor(BLACK);
Rectangle(MyX1,MyY1,MyX2,MyY2);
gotoxy((MyX1+MyX2)/2, 5+(MyY1+MyY2)/2);
DrawCenteredText(MyText);
}
//------------------------------------...
bool ButtonClass::IsHit(int x, int y)
/*Post: true returned if and only if point (x,y) is on the button */
{
return (x%26gt;=MyX1 %26amp;%26amp; x%26lt;=MyX2 %26amp;%26amp; y%26gt;=MyY1 %26amp;%26amp; y%26lt;=MyY2);
}
//------------------------------------...
//------------------------------------...
class GridClass {
public:
GridClass();
void Paint();
void MouseClick(int x, int y);
void InitGrid();
private:
const int GridDimension; // # of rows and columns in grid
// Constants for board; must all differ
const int Empty, EmptyPicked, Treasure, TreasurePicked;
matrix%26lt;int%26gt; Board; // Uses above constants
int TreasureRow, TreasureCol;
bool GameOver;
int NumClicks;
int BoxSize; // Pixels per box
int LeftMargin; // Pixels from left
int TopMargin; // Pixels from top
void XYToRowCol(int x, int y, int %26amp;Row, int %26amp;Col);
void MarkBox(int Row, int Col, int BoxContents);
ButtonClass QuitButton;
};
//------------------------------------...
GridClass::GridClass()
: GridDimension(5),
Empty(0), EmptyPicked(-1), Treasure(1), TreasurePicked(2),
Board(GridDimension, GridDimension,0),
NumClicks(0), GameOver(false),
BoxSize(GetMaxY()/2/GridDimension), // Fill half of y
LeftMargin((GetMaxX()-BoxSize*GridDim...
TopMargin(GetMaxY()/4),
QuitButton("I give up!",10,10,100,40)
{
randomize();
TreasureRow = random(GridDimension);
TreasureCol= random(GridDimension);
Board[TreasureRow][TreasureCol] = Treasure;
}
//------------------------------------...
void GridClass::InitGrid()
/*Post: Grid initialized for a new game */
{
NumClicks = 0;
GameOver = false;
for (int Row=0; Row %26lt; GridDimension; Row++)
for (int Col=0; Col %26lt; GridDimension; Col++)
Board[Row][Col] = Empty;
TreasureRow = random(GridDimension);
TreasureCol = random(GridDimension);
Board[TreasureRow][TreasureCol] = Treasure;
}
//------------------------------------...
void GridClass::XYToRowCol(int x, int y, int %26amp;Row, int %26amp;Col)
/* Post: Row and Column corresponding to x, y returned,
or -1 returned if x, y is not on the board */
{
int DistFromLeft = x - LeftMargin;
Col = (DistFromLeft+BoxSize)/BoxSize-1;
int DistFromTop = y - TopMargin;
Row = (DistFromTop+BoxSize)/BoxSize-1;
if (Col %26lt; 0 || Col %26gt;= GridDimension ||
Row %26lt; 0 || Row %26gt;= GridDimension) {
Row = -1;
Col = -1;
}
}
//------------------------------------...
void GridClass::MarkBox(int Row, int Col, int BoxContents)
/* Post: Row, Col box in appropriate color */
{
SetColor(BLACK); // For outline
SetFillColor(WHITE);
if (BoxContents==EmptyPicked)
SetFillColor(GRAY);
else if (BoxContents==TreasurePicked)
SetFillColor(RED);
FilledRectangle(Col*BoxSize+LeftMargi... Row*BoxSize+TopMargin,
(Col+1)*BoxSize+LeftMargin,
(Row+1)*BoxSize+TopMargin);
}
//------------------------------------...
void GridClass::MouseClick(int x, int y)
{
int Row, Col;
if (QuitButton.IsHit(x,y)){
GameOver = true;
Board[TreasureRow][TreasureCol] = TreasurePicked;
Paint(); //To show the treasure square
MessageBox("Come back again!","Quit button clicked");
PostQuitMessage(0);
}
else{
XYToRowCol(x, y, Row, Col);
if (Row != -1 %26amp;%26amp; Col!= -1 %26amp;%26amp; Board[Row][Col] != EmptyPicked) {
if (Board[Row][Col] == Empty)
Board[Row][Col] = EmptyPicked;
else if (Board[Row][Col] == Treasure) {
Board[Row][Col] = TreasurePicked;
GameOver = true;
Paint(); //To show treasure square
if (MessageBoxYN("Play again?","Game over")==1)
InitGrid();
else
PostQuitMessage(0);
}
NumClicks++;
}
else
MessageBeep(-1);
}
}
//------------------------------------...
void GridClass::Paint()
{
QuitButton.Paint();
SetColor(BLACK);
int Row,Col;
// Draw lines
for (Col = 0; Col %26lt;= GridDimension; Col++)
Line(LeftMargin+Col*BoxSize, TopMargin,
LeftMargin+Col*BoxSize,
TopMargin+GridDimension*BoxSize);
for (Row = 0; Row %26lt;= GridDimension; Row++)
Line(LeftMargin, TopMargin+Row*BoxSize,
LeftMargin+GridDimension*BoxSize,
TopMargin+Row*BoxSize);
// Color in boxes
for (Row=0; Row %26lt; GridDimension; Row++)
for (Col=0; Col %26lt; GridDimension; Col++)
MarkBox(Row, Col, Board[Row][Col]);
// Display results
if (GameOver==true) {
gotoxy(20, GetMaxY()-60);
DrawText("Game over! Score = ");
DrawText(NumClicks);
}
}
//------------------------------------...
//------------------------------------...
class GuiClass {
public:
GuiClass();
void GuiMouseClick(int x, int y); // Action if mouse click
void GuiPaint(); // Repaint the entire window
String Title(); // Title to display
private:
GridClass Game;
};
//------------------------------------...
GuiClass::GuiClass()
{
}
//------------------------------------...
String GuiClass::Title()
{
return ("Treasure hunt!");
}
//------------------------------------...
void GuiClass::GuiMouseClick(int x, int y)
{
Game.MouseClick(x, y);
}
//------------------------------------...
void GuiClass::GuiPaint()
{
Game.Paint();
}
//------------------------------------...
#include %26lt;lvp\gui_bot.h%26gt;
I need help with this c++ code, when you find the treasure, it is suppose to turn red but it doesn't?
http://www.devarticles.com/c/b/Cplusplus...
http://www.codeproject.com/
http://www.cprogramming.com/
#include %26lt;lvp\gui_top.h%26gt;
#include %26lt;lvp\matrix.h%26gt;
#include %26lt;lvp\string.h%26gt;
#include %26lt;lvp\bool.h%26gt;
#include %26lt;lvp\random.h%26gt;
//------------------------------------...
class ButtonClass{
public:
ButtonClass(String Text, int X1, int Y1, int X2, int Y2);
/*Post: A button created with upper-left corner at X1,Y1 and
lower-right corner at X2,Y2 with Text centeredin box */
void Paint();
bool IsHit(int x, int y);
/*Post: true returned if and only if (x,y) is on the button*/
private:
int MyX1,MyY1,MyX2,MyY2;
String MyText;
};
//------------------------------------...
ButtonClass::ButtonClass(String Text, int X1, int Y1, int X2, int Y2)
:MyText(Text),MyX1(X1),MyY1(Y1),MyX2(...
/*Post: Button created with upper-left corner at X1, Y1 and
lower right corner at X2,Y2 with Text centered in box */
{
}
//------------------------------------...
void ButtonClass::Paint()
{
SetColor(BLACK);
Rectangle(MyX1,MyY1,MyX2,MyY2);
gotoxy((MyX1+MyX2)/2, 5+(MyY1+MyY2)/2);
DrawCenteredText(MyText);
}
//------------------------------------...
bool ButtonClass::IsHit(int x, int y)
/*Post: true returned if and only if point (x,y) is on the button */
{
return (x%26gt;=MyX1 %26amp;%26amp; x%26lt;=MyX2 %26amp;%26amp; y%26gt;=MyY1 %26amp;%26amp; y%26lt;=MyY2);
}
//------------------------------------...
//------------------------------------...
class GridClass {
public:
GridClass();
void Paint();
void MouseClick(int x, int y);
void InitGrid();
private:
const int GridDimension; // # of rows and columns in grid
// Constants for board; must all differ
const int Empty, EmptyPicked, Treasure, TreasurePicked;
matrix%26lt;int%26gt; Board; // Uses above constants
int TreasureRow, TreasureCol;
bool GameOver;
int NumClicks;
int BoxSize; // Pixels per box
int LeftMargin; // Pixels from left
int TopMargin; // Pixels from top
void XYToRowCol(int x, int y, int %26amp;Row, int %26amp;Col);
void MarkBox(int Row, int Col, int BoxContents);
ButtonClass QuitButton;
};
//------------------------------------...
GridClass::GridClass()
: GridDimension(5),
Empty(0), EmptyPicked(-1), Treasure(1), TreasurePicked(2),
Board(GridDimension, GridDimension,0),
NumClicks(0), GameOver(false),
BoxSize(GetMaxY()/2/GridDimension), // Fill half of y
LeftMargin((GetMaxX()-BoxSize*GridDim...
TopMargin(GetMaxY()/4),
QuitButton("I give up!",10,10,100,40)
{
randomize();
TreasureRow = random(GridDimension);
TreasureCol= random(GridDimension);
Board[TreasureRow][TreasureCol] = Treasure;
}
//------------------------------------...
void GridClass::InitGrid()
/*Post: Grid initialized for a new game */
{
NumClicks = 0;
GameOver = false;
for (int Row=0; Row %26lt; GridDimension; Row++)
for (int Col=0; Col %26lt; GridDimension; Col++)
Board[Row][Col] = Empty;
TreasureRow = random(GridDimension);
TreasureCol = random(GridDimension);
Board[TreasureRow][TreasureCol] = Treasure;
}
//------------------------------------...
void GridClass::XYToRowCol(int x, int y, int %26amp;Row, int %26amp;Col)
/* Post: Row and Column corresponding to x, y returned,
or -1 returned if x, y is not on the board */
{
int DistFromLeft = x - LeftMargin;
Col = (DistFromLeft+BoxSize)/BoxSize-1;
int DistFromTop = y - TopMargin;
Row = (DistFromTop+BoxSize)/BoxSize-1;
if (Col %26lt; 0 || Col %26gt;= GridDimension ||
Row %26lt; 0 || Row %26gt;= GridDimension) {
Row = -1;
Col = -1;
}
}
//------------------------------------...
void GridClass::MarkBox(int Row, int Col, int BoxContents)
/* Post: Row, Col box in appropriate color */
{
SetColor(BLACK); // For outline
SetFillColor(WHITE);
if (BoxContents==EmptyPicked)
SetFillColor(GRAY);
else if (BoxContents==TreasurePicked)
SetFillColor(RED);
FilledRectangle(Col*BoxSize+LeftMargi... Row*BoxSize+TopMargin,
(Col+1)*BoxSize+LeftMargin,
(Row+1)*BoxSize+TopMargin);
}
//------------------------------------...
void GridClass::MouseClick(int x, int y)
{
int Row, Col;
if (QuitButton.IsHit(x,y)){
GameOver = true;
Board[TreasureRow][TreasureCol] = TreasurePicked;
Paint(); //To show the treasure square
MessageBox("Come back again!","Quit button clicked");
PostQuitMessage(0);
}
else{
XYToRowCol(x, y, Row, Col);
if (Row != -1 %26amp;%26amp; Col!= -1 %26amp;%26amp; Board[Row][Col] != EmptyPicked) {
if (Board[Row][Col] == Empty)
Board[Row][Col] = EmptyPicked;
else if (Board[Row][Col] == Treasure) {
Board[Row][Col] = TreasurePicked;
GameOver = true;
Paint(); //To show treasure square
if (MessageBoxYN("Play again?","Game over")==1)
InitGrid();
else
PostQuitMessage(0);
}
NumClicks++;
}
else
MessageBeep(-1);
}
}
//------------------------------------...
void GridClass::Paint()
{
QuitButton.Paint();
SetColor(BLACK);
int Row,Col;
// Draw lines
for (Col = 0; Col %26lt;= GridDimension; Col++)
Line(LeftMargin+Col*BoxSize, TopMargin,
LeftMargin+Col*BoxSize,
TopMargin+GridDimension*BoxSize);
for (Row = 0; Row %26lt;= GridDimension; Row++)
Line(LeftMargin, TopMargin+Row*BoxSize,
LeftMargin+GridDimension*BoxSize,
TopMargin+Row*BoxSize);
// Color in boxes
for (Row=0; Row %26lt; GridDimension; Row++)
for (Col=0; Col %26lt; GridDimension; Col++)
MarkBox(Row, Col, Board[Row][Col]);
// Display results
if (GameOver==true) {
gotoxy(20, GetMaxY()-60);
DrawText("Game over! Score = ");
DrawText(NumClicks);
}
}
//------------------------------------...
//------------------------------------...
class GuiClass {
public:
GuiClass();
void GuiMouseClick(int x, int y); // Action if mouse click
void GuiPaint(); // Repaint the entire window
String Title(); // Title to display
private:
GridClass Game;
};
//------------------------------------...
GuiClass::GuiClass()
{
}
//------------------------------------...
String GuiClass::Title()
{
return ("Treasure hunt!");
}
//------------------------------------...
void GuiClass::GuiMouseClick(int x, int y)
{
Game.MouseClick(x, y);
}
//------------------------------------...
void GuiClass::GuiPaint()
{
Game.Paint();
}
//------------------------------------...
#include %26lt;lvp\gui_bot.h%26gt;
I need help with this c++ code, when you find the treasure, it is suppose to turn red but it doesn't?
http://www.devarticles.com/c/b/Cplusplus...
http://www.codeproject.com/
http://www.cprogramming.com/
Can some one with this C code???
#include %26lt;signal.h%26gt;
#include %26lt;stdio.h%26gt;
#include %26lt;stdlib.h%26gt;
#include %26lt;sys/types.h%26gt;
void segment_fault_handler(int x)
{
*((int *)((int)(%26amp;x))+0)=x;
printf("line 17");
}
int main()
{
int r2 = 0;
signal(SIGSEGV, segment_fault_handler);
r2 = *( (int *) 0 );
printf("Ran instruction\n");
return 0;
}
this compiles and but when i try to run the .exe file i get a segmentation fault error, it does print out "Line 17" once, can someone please try to help debug this.
Can some one with this C code???
it looks like it is doing exactly what you want it to do.
Trying to dereference the null pointer will case a seg fault. That's handled but your handler doesn't really do anything so the program will still crash. You can't just return to where the error occurred.
#include %26lt;stdio.h%26gt;
#include %26lt;stdlib.h%26gt;
#include %26lt;sys/types.h%26gt;
void segment_fault_handler(int x)
{
*((int *)((int)(%26amp;x))+0)=x;
printf("line 17");
}
int main()
{
int r2 = 0;
signal(SIGSEGV, segment_fault_handler);
r2 = *( (int *) 0 );
printf("Ran instruction\n");
return 0;
}
this compiles and but when i try to run the .exe file i get a segmentation fault error, it does print out "Line 17" once, can someone please try to help debug this.
Can some one with this C code???
it looks like it is doing exactly what you want it to do.
Trying to dereference the null pointer will case a seg fault. That's handled but your handler doesn't really do anything so the program will still crash. You can't just return to where the error occurred.
Plllllllllllzzzzzzzzzzzzzz help i need a c++ code that calculate the cos of x without using the power,cos.....
or any other function
Plllllllllllzzzzzzzzzzzzzz help i need a c++ code that calculate the cos of x without using the power,cos.....
This is actually not terribly difficult. You need to use the taylor expansion of the cosine function:
cos(x)=1-x^2/2!+x^4/4!-x^6/6!...to infinity, or:
sum from n=0 to inf of [(-1)^n*x^2n]/(2n)!
The true cosine of x would require to sum those terms to infinity, but for a computer you only need a few of the first ones to get a good enough approximation (for the most part, 10 should be plenty)
This looks like a homework assignment, so I won't write this in C++ for you, but I'll tell you how to do it. A simple program (not in C++) would go something like this:
x=1.5705 (this would be the x you are taking a cos of)
ans=1;
xnum=1;
sign=1;
for i from 1 to 10
__sign=sign*(-1);
__xnum=x*x*xnum;
__xden=1;
__dummy=2*i;
__for j from 1 to dummy
____xden=xden*j;
__end
__ans=ans+sign*(xnum/xden)
end
ans;
This requires that x be in radians. Each iteration of the external loop calculates a term in the infinite series, with the variable "sign" keeping track of whether the term should be positive or negative, the variable "xnum" tracks and calculates what the numerator of the term should be (x^2n), and the variable "xden" calculates the value in the denominator (2n!) for each term. At the end of the external loop these terms are combined with the previous value of "ans" to give you a better approximation. If you want more accuracy, you simply need to increase the number of times the external for loop executes.
Reply:use any infinite series, just make sure that you go to say, 10 significant digits...
Reply:?????????????
Plllllllllllzzzzzzzzzzzzzz help i need a c++ code that calculate the cos of x without using the power,cos.....
This is actually not terribly difficult. You need to use the taylor expansion of the cosine function:
cos(x)=1-x^2/2!+x^4/4!-x^6/6!...to infinity, or:
sum from n=0 to inf of [(-1)^n*x^2n]/(2n)!
The true cosine of x would require to sum those terms to infinity, but for a computer you only need a few of the first ones to get a good enough approximation (for the most part, 10 should be plenty)
This looks like a homework assignment, so I won't write this in C++ for you, but I'll tell you how to do it. A simple program (not in C++) would go something like this:
x=1.5705 (this would be the x you are taking a cos of)
ans=1;
xnum=1;
sign=1;
for i from 1 to 10
__sign=sign*(-1);
__xnum=x*x*xnum;
__xden=1;
__dummy=2*i;
__for j from 1 to dummy
____xden=xden*j;
__end
__ans=ans+sign*(xnum/xden)
end
ans;
This requires that x be in radians. Each iteration of the external loop calculates a term in the infinite series, with the variable "sign" keeping track of whether the term should be positive or negative, the variable "xnum" tracks and calculates what the numerator of the term should be (x^2n), and the variable "xden" calculates the value in the denominator (2n!) for each term. At the end of the external loop these terms are combined with the previous value of "ans" to give you a better approximation. If you want more accuracy, you simply need to increase the number of times the external for loop executes.
Reply:use any infinite series, just make sure that you go to say, 10 significant digits...
Reply:?????????????
Where does const variable in c code in memory reside?
It sits in the heap that is allocated to your program by the OS. It doesn't reside anywhere special, it is just marked read only. There are ways around that if you really try.
Where does const variable in c code in memory reside?
I think it's compiled into the static data area of the executable. Sorry that's not very specific, but that's as much as I know.
bloom
Where does const variable in c code in memory reside?
I think it's compiled into the static data area of the executable. Sorry that's not very specific, but that's as much as I know.
bloom
Can anyone send me a C++ code which produces a prism,polygon which rotates to show its different faces?
it should include some graphical applications!! i would llike if it asks the user to enter the necessary inputs and display the area.Thanks a lot !!!
Can anyone send me a C++ code which produces a prism,polygon which rotates to show its different faces?
You will probably have to use DirectX or OpenGL and try and create your own user interface; It shouldn't be too hard, but you would have to create your own GUI interface for input from either a mouse or keyboard (mouse would be easier). Check out some game development sites; By the way, C++ code that does that would be extremely long, and couldn't be shown in an answer on this site. You might try going to a development forum and asking people for help, but it's not going to be easy at all.
Reply:Yeah i agree it will be long and not look as good as it would be done by some other simple graphics program alone with minimum coding or no coding. Whoever gave u this assignment is tormenting you, seriously.
Show us the assignment
Can anyone send me a C++ code which produces a prism,polygon which rotates to show its different faces?
You will probably have to use DirectX or OpenGL and try and create your own user interface; It shouldn't be too hard, but you would have to create your own GUI interface for input from either a mouse or keyboard (mouse would be easier). Check out some game development sites; By the way, C++ code that does that would be extremely long, and couldn't be shown in an answer on this site. You might try going to a development forum and asking people for help, but it's not going to be easy at all.
Reply:Yeah i agree it will be long and not look as good as it would be done by some other simple graphics program alone with minimum coding or no coding. Whoever gave u this assignment is tormenting you, seriously.
Show us the assignment
Can someone give the visual c++ code to delete a particular content in a file?
Please help me!
Can someone give the visual c++ code to delete a particular content in a file?
You have not specified anywhere near enough information.
- what type of content (text? formatted text? binary?)
- remove from the content from the beginning? end? middle?
- how to identify the content to remove (vs. what to leave)?
- can we make a copy of the file, or must this operation be done in-place (i.e. on the original file)?
Can someone give the visual c++ code to delete a particular content in a file?
You have not specified anywhere near enough information.
- what type of content (text? formatted text? binary?)
- remove from the content from the beginning? end? middle?
- how to identify the content to remove (vs. what to leave)?
- can we make a copy of the file, or must this operation be done in-place (i.e. on the original file)?
Can anyone give me a c-code for evaluating an infix expression using stack without converting it to postfix?
/*Program to evaluate Conversion of INFIX to POSTFIX*/
#include%26lt;iostream.h%26gt;
#include%26lt;conio.h%26gt;
#include%26lt;stdio.h%26gt;
#include%26lt;string.h%26gt;
#include%26lt;stdlib.h%26gt;
void main()
{
char in[30],post[30],stack[30],st[10];
int ch,j=0,top=0,len,temp,var,var1,stack1[30...
clrscr();
cout%26lt;%26lt;"Enter a notation in infix form";
gets(in);
stack[0]='(';
len=strlen(in);
in[len]=')';
for(int i=0;i%26lt;=len;i++)
{
ch=in[i];
if(ch==42||ch==43||ch==45||ch==47)
{
if(in[i]=='*'||in[i]=='/')
{
ch=100;
}
if(in[i]=='+'||in[i]=='-')
{
ch=101;
}
if(ch%26gt;=stack[top])
{
top++;
stack[top]=in[i];
}
if(ch%26lt;stack[top])
{
if(stack[top]!=40)
{
post[j]=stack[top];
stack[top]=in[i];
j++;
}
}
}
if(ch%26gt;=48%26amp;%26amp;ch%26lt;=57)
{
post[j]=in[i];
j++;
}
if(ch==40)
{
top++;
stack[top]='(';
}
if(ch==41)
{
while(1)
{
if(int(stack[top])==40)
{
break;
}
else
{
post[j]=stack[top];
top--;
j++;
}
}
top--;
}
}
cout%26lt;%26lt;"\nPost Fix notation is";
for(i=0;i%26lt;j;i++)
cout%26lt;%26lt;post[i];
top=0;
for(i=0;i%26lt;j;i++)
{
ch=post[i];
if(ch%26gt;=48%26amp;%26amp;ch%26lt;=57)
{
top++;
stack1[top]=ch-48;
}
if(ch==42||ch==43||ch==45||ch==47)
{
var=stack1[top];
top--;
var1=stack1[top];
top--;
switch(ch)
{
case 42:
res=var1*var;
break;
case 43:
res=var1+var;
break;
case 45:
res=var1-var;
break;
case 47:
res=var1/var;
break;
}
top++;
stack1[top]=res;
}
}
cout%26lt;%26lt;"\nEvaluation of PostFix Expression is";
cout%26lt;%26lt;stack1[top];
getch();
}
This is the code.Gud luck.
#include%26lt;iostream.h%26gt;
#include%26lt;conio.h%26gt;
#include%26lt;stdio.h%26gt;
#include%26lt;string.h%26gt;
#include%26lt;stdlib.h%26gt;
void main()
{
char in[30],post[30],stack[30],st[10];
int ch,j=0,top=0,len,temp,var,var1,stack1[30...
clrscr();
cout%26lt;%26lt;"Enter a notation in infix form";
gets(in);
stack[0]='(';
len=strlen(in);
in[len]=')';
for(int i=0;i%26lt;=len;i++)
{
ch=in[i];
if(ch==42||ch==43||ch==45||ch==47)
{
if(in[i]=='*'||in[i]=='/')
{
ch=100;
}
if(in[i]=='+'||in[i]=='-')
{
ch=101;
}
if(ch%26gt;=stack[top])
{
top++;
stack[top]=in[i];
}
if(ch%26lt;stack[top])
{
if(stack[top]!=40)
{
post[j]=stack[top];
stack[top]=in[i];
j++;
}
}
}
if(ch%26gt;=48%26amp;%26amp;ch%26lt;=57)
{
post[j]=in[i];
j++;
}
if(ch==40)
{
top++;
stack[top]='(';
}
if(ch==41)
{
while(1)
{
if(int(stack[top])==40)
{
break;
}
else
{
post[j]=stack[top];
top--;
j++;
}
}
top--;
}
}
cout%26lt;%26lt;"\nPost Fix notation is";
for(i=0;i%26lt;j;i++)
cout%26lt;%26lt;post[i];
top=0;
for(i=0;i%26lt;j;i++)
{
ch=post[i];
if(ch%26gt;=48%26amp;%26amp;ch%26lt;=57)
{
top++;
stack1[top]=ch-48;
}
if(ch==42||ch==43||ch==45||ch==47)
{
var=stack1[top];
top--;
var1=stack1[top];
top--;
switch(ch)
{
case 42:
res=var1*var;
break;
case 43:
res=var1+var;
break;
case 45:
res=var1-var;
break;
case 47:
res=var1/var;
break;
}
top++;
stack1[top]=res;
}
}
cout%26lt;%26lt;"\nEvaluation of PostFix Expression is";
cout%26lt;%26lt;stack1[top];
getch();
}
This is the code.Gud luck.
Help with a very simple C# code.?
I am just learning as you'll be able to tell by my question. I need to....
Create a project with a single text box. In the Resize event of the form, show the Width of the form in
the text box. I have Visual Studios 2008.
Thanks to any help in advance!!!
Help with a very simple C# code.?
Bashar Y was almost there :) but it's a little different.
In C# it would be:
textbox1.Text = this.Width.ToString();
or Height of course, like he said.
Make sure you don't forget ToString() behind it,
C# is a little stricter than VB ;)
Reply:pkey i have visual basic but i can help you in visual basic i use this "
textbox1.text =me.width
you can use heigh too..
dogwood
Create a project with a single text box. In the Resize event of the form, show the Width of the form in
the text box. I have Visual Studios 2008.
Thanks to any help in advance!!!
Help with a very simple C# code.?
Bashar Y was almost there :) but it's a little different.
In C# it would be:
textbox1.Text = this.Width.ToString();
or Height of course, like he said.
Make sure you don't forget ToString() behind it,
C# is a little stricter than VB ;)
Reply:pkey i have visual basic but i can help you in visual basic i use this "
textbox1.text =me.width
you can use heigh too..
dogwood
What is wrong with my C++ code?
#include %26lt;iostream%26gt;
#include %26lt;iomanip%26gt;
using namespace std;
int main ()
{
int i,k,n=1,m;
cout%26lt;%26lt;"Enter height"%26lt;%26lt;setw(11)%26lt;%26lt;":";
cin%26gt;%26gt;n;
for(m=0; m%26lt;2; m++)
{
for(i=1; i%26lt;=n; i++)
{
if(m==0)
{
for(k=1; k%26lt;=n-1; k++)
{
cout%26lt;%26lt;"";
}
for(k=1; k%26lt;=2*i; k++)
{
cout%26lt;%26lt;"^";
}
}
if(m==1)
{
for(k=1; k%26lt;=i; k++)
{
cout%26lt;%26lt;"";
}
for(k=1; k%26lt;(n-i)*2; k++)
{
cout%26lt;%26lt;"^";
}
}
cout%26lt;%26lt;endl;
}
}
return 0;
}
My errors,
pyr2.obj : error LNK2005: _main already defined in pyramid.obj
Debug/pyramid.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
pyramid.exe - 2 error(s), 0 warning(s)
What is wrong with my C++ code?
It looks like you have a pyr2.cpp and pyramid.cpp file that both define the function main. If you are linking these two files together only one of them can define the function main.
Reply:What's probably the problem is that main is defined as
int main( int argc, char *argv[])
by having main(), it thinks you're trying to redefine it.
Reply:May be you can post your requirements at http://expert.ccietutorial.com/
and let many programmers bid for your project.
You can hire whoever you like.
Do not pay any money afront however.
Reply:You are linking more than one file with a main function in it.
#include %26lt;iomanip%26gt;
using namespace std;
int main ()
{
int i,k,n=1,m;
cout%26lt;%26lt;"Enter height"%26lt;%26lt;setw(11)%26lt;%26lt;":";
cin%26gt;%26gt;n;
for(m=0; m%26lt;2; m++)
{
for(i=1; i%26lt;=n; i++)
{
if(m==0)
{
for(k=1; k%26lt;=n-1; k++)
{
cout%26lt;%26lt;"";
}
for(k=1; k%26lt;=2*i; k++)
{
cout%26lt;%26lt;"^";
}
}
if(m==1)
{
for(k=1; k%26lt;=i; k++)
{
cout%26lt;%26lt;"";
}
for(k=1; k%26lt;(n-i)*2; k++)
{
cout%26lt;%26lt;"^";
}
}
cout%26lt;%26lt;endl;
}
}
return 0;
}
My errors,
pyr2.obj : error LNK2005: _main already defined in pyramid.obj
Debug/pyramid.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
pyramid.exe - 2 error(s), 0 warning(s)
What is wrong with my C++ code?
It looks like you have a pyr2.cpp and pyramid.cpp file that both define the function main. If you are linking these two files together only one of them can define the function main.
Reply:What's probably the problem is that main is defined as
int main( int argc, char *argv[])
by having main(), it thinks you're trying to redefine it.
Reply:May be you can post your requirements at http://expert.ccietutorial.com/
and let many programmers bid for your project.
You can hire whoever you like.
Do not pay any money afront however.
Reply:You are linking more than one file with a main function in it.
Can anyone give me da C++ code for printing jobs of a printer. Add,cancel a printing job etc...???
Printing job should have job ID,Name of da file,status(cancel,pause),priority level of da job.Also need a windows form application to insert details of da printing job.
Can anyone give me da C++ code for printing jobs of a printer. Add,cancel a printing job etc...???
ChaRox honey I don't have time to do that but here is your link learn from it.
http://www.google.co.uk/search?hl=en%26amp;q=s...
Can anyone give me da C++ code for printing jobs of a printer. Add,cancel a printing job etc...???
ChaRox honey I don't have time to do that but here is your link learn from it.
http://www.google.co.uk/search?hl=en%26amp;q=s...
How would you describe excellent C# code?
Plz help, was asked in a microsoft interview and need 2 b specific
How would you describe excellent C# code?
-readable
-good use of whitespace
-liberally commented
-use of lots of modulation (many functions defined)
-logical modulation
-reuse of code
-consistent indentation
How would you describe excellent C# code?
-readable
-good use of whitespace
-liberally commented
-use of lots of modulation (many functions defined)
-logical modulation
-reuse of code
-consistent indentation
How to compile and run c++ code from command prompt in Windows XP ?
borland and microsoft offer free compilers as well.
you can use the borland one with command prompt. Open a command prompt window, start -%26gt; all programs -%26gt; accessories -%26gt; command prompt.
read the instructions that come with the compiler to find out how to get it to run.
How to compile and run c++ code from command prompt in Windows XP ?
you can download cygwin (or something similar) and download gcc to go with it.
Add the gcc to your path
you can then open a command prompt and invoke gcc to compile your c++ code.
Reply:I don't think this is possible. Download a free compiler instead.
redbud
you can use the borland one with command prompt. Open a command prompt window, start -%26gt; all programs -%26gt; accessories -%26gt; command prompt.
read the instructions that come with the compiler to find out how to get it to run.
How to compile and run c++ code from command prompt in Windows XP ?
you can download cygwin (or something similar) and download gcc to go with it.
Add the gcc to your path
you can then open a command prompt and invoke gcc to compile your c++ code.
Reply:I don't think this is possible. Download a free compiler instead.
redbud
How do i split my c++ code into various source files?
im using eclipse with CDT. my program works right now as a single source file. i want to split into various, so is easier to keep coding. i have problems with includes and stuff. what is the right way to do this? i didnt find any tutorial for this.. thanks
How do i split my c++ code into various source files?
Separate out the functions, according to what makes sense to you, into additional .cpp files. You can right-click on the project name to add the new files. Write declarations for those functions in a header file or files (e.g. filename "mystuff.h"). Then in whichever .cpp files use those functions, put #include "mystuff.h" at the top. Name the .h file or files in a way organized to relate to the .cpp files whose functions they declare. Think about how you would most conveniently re-use the functions later.
How do i split my c++ code into various source files?
Separate out the functions, according to what makes sense to you, into additional .cpp files. You can right-click on the project name to add the new files. Write declarations for those functions in a header file or files (e.g. filename "mystuff.h"). Then in whichever .cpp files use those functions, put #include "mystuff.h" at the top. Name the .h file or files in a way organized to relate to the .cpp files whose functions they declare. Think about how you would most conveniently re-use the functions later.
What's wrong with this C code?
main(){
char tablero[7][7];
tablero[4][4]="Hola";
printf("Tablero en 5E vale: %d",tablero[4][4]);
getch();
It doesn't take the text string "HOLA", why is that? I want an array [][] where I can store words. Thanks.
What's wrong with this C code?
The first statement,
char tablero[7][7];
creates a 2 dimensional array of letters. The second statement,
tablero[4][4]="Hola";
is effectively trying to insert 4 characters into a space (4, 4) only meant to hold 1 character. Probably what you would want to do would be say,
char tablero[]="Hola";
in this case, tablero[3] would = "a" and tablero[1..2] would = "ol".
Alternatively, you could make that a character pointer array,
char *tablero[7][7]; would would be a 2 dimensional array of character pointers. in this case you could say
*tablero[4][4]="Hola";
and then the pointer at 4, 4 would point to the word.
Reply:Each item in the two dimensional array can only hold one character.
You might try setting tablero[4][0] to "hola" but you'll also need an extra spot for the \0, to indicate end of string.
My Mistake that won't work. You could create a char *wordList[6] which is an array of pointers, and then set wordList[0]="test";
Reply:The type of "Hola" is "const char*", the type of tablero[4][4] is char. What you probably want to do is this:
int main(int argc, char* argv[])
{
const char* table[7];
table[4] = "Hola";
printf("table[4] = \"%s\"\n",table[4]);
return 0;
}
Reply:make tablero a struct
char tablero[7][7];
tablero[4][4]="Hola";
printf("Tablero en 5E vale: %d",tablero[4][4]);
getch();
It doesn't take the text string "HOLA", why is that? I want an array [][] where I can store words. Thanks.
What's wrong with this C code?
The first statement,
char tablero[7][7];
creates a 2 dimensional array of letters. The second statement,
tablero[4][4]="Hola";
is effectively trying to insert 4 characters into a space (4, 4) only meant to hold 1 character. Probably what you would want to do would be say,
char tablero[]="Hola";
in this case, tablero[3] would = "a" and tablero[1..2] would = "ol".
Alternatively, you could make that a character pointer array,
char *tablero[7][7]; would would be a 2 dimensional array of character pointers. in this case you could say
*tablero[4][4]="Hola";
and then the pointer at 4, 4 would point to the word.
Reply:Each item in the two dimensional array can only hold one character.
You might try setting tablero[4][0] to "hola" but you'll also need an extra spot for the \0, to indicate end of string.
My Mistake that won't work. You could create a char *wordList[6] which is an array of pointers, and then set wordList[0]="test";
Reply:The type of "Hola" is "const char*", the type of tablero[4][4] is char. What you probably want to do is this:
int main(int argc, char* argv[])
{
const char* table[7];
table[4] = "Hola";
printf("table[4] = \"%s\"\n",table[4]);
return 0;
}
Reply:make tablero a struct
Where do I start writing C++ code & how to compile & run?
The best suggestion, if you want to teach yourself is to find plenty of stuff to read. Look online and in the bookstores. Find some beginner stuff that you may be able to understand. You will also in doing this find good compiler suggestions. Now, I do suggest that if you don't do any programming as of now that you start with something eaiser. Like Perl, PHP or something. You will also learn some C++ while doing this.
http://www.myputerdr.com/index.html
http://www.myputerdr.com/index.html
Can someone give me the C++ code for input & output.?
#include %26lt;iostream%26gt;
main ()
{
int ival;
// read value if ival from input stream after prompting
cout %26lt;%26lt; "Enter value: ";
cin %26gt;%26gt; ival;
}
Can someone give me the C++ code for input %26amp; output.?
If you want the user to type something in, it would be
cin %26gt;%26gt; X;
if you want to then put X on the screen, it would be
cout %26lt;%26lt; X;
sundew
main ()
{
int ival;
// read value if ival from input stream after prompting
cout %26lt;%26lt; "Enter value: ";
cin %26gt;%26gt; ival;
}
Can someone give me the C++ code for input %26amp; output.?
If you want the user to type something in, it would be
cin %26gt;%26gt; X;
if you want to then put X on the screen, it would be
cout %26lt;%26lt; X;
sundew
Anyone know the best way to learn C++ code, the book puts me to sleep (how to learn C++ in 21 days)?
Just practice on your own and have fun. Search the internet for fun stuff to do on c++.
How to call/load .net dll(C#) from c++ code?
Go to the C++ project in Visual Studio.
In the solution explorer, right click the project and choose References option. It will show a form where you can click on a button named 'Add new References'. Now in the .NET tab you will see the standard .net DLL, while you can click on Browse to load a custom made dll (your own code's DLL)
In the solution explorer, right click the project and choose References option. It will show a form where you can click on a button named 'Add new References'. Now in the .NET tab you will see the standard .net DLL, while you can click on Browse to load a custom made dll (your own code's DLL)
Saturday, May 22, 2010
I wanted to get a C code, which implements data link protocol using sliding window.?
the book published by Andrew S. Tanenbaum named: Computer Networks, Fourth Edition contains in a very detailed level a C implementation of sliding windows operations.
In my opinion, the best available
In my opinion, the best available
Does n e one have a c/c++ code for calculating the cofactors of a nxn matrix?
I haven't found any readily cooked one, if you want I can help you, are you familiar with c/c++ code?
baby breath
baby breath
How can i change a Java code to a C++ code ???
Just change the syntax. You most likely will have to rewrite it, unless you find a progam that can convert the syntax between languages.
Can you translate this C code into english?I have problems on understanding it?
#include %26lt;stdio.h%26gt;
#include %26lt;math.h%26gt;
/*------------------------------------...
/* DEFINITIONS DES FONCTIONS UTILISÉES LORS DU PROGRAMME */
/*------------------------------------...
/*------------------------------------...
/* Fonction saisie : saisie d'un nombre flottant */
/* parametres : var une chaine de caractères */
/* Resultat : x un flottant */
/* Effet de bord : demande une entree a l'utilisateur*/
/*------------------------------------...
float saisie (char var[])
{
float x;
printf ("Entrez la valeur de %s : ",var);
scanf ("%f",%26amp;x);
return x;
}
/*------------------------------------...
/* Fonction sinus : calcul du sinus d'un */
/* flottant x a epsilon pres */
/* parametres : x un flottant, epsilon */
/* un flottant representant une précision donnee */
/* Resultat : y un flottant tel que y */
/* = x - x^3/3! + x^5/5! - x^7/7! + */
/* Effet de bord : affichage de : Le nombre */
/* de terme calcule est : ? */
/*------------------------------------...
float sinus (float x, float epsilon)
{
float sinusx; /* variable contenant le n ième terme de la serie */
float somme=0; /* contient la valeur du sinus calculé */
double exposant=x; /* contient la valeur de x^(2*nbterme-1) du n ième terme */
int nbterme=0,i; /* compteur */
double factoriel=1; /* contient la factoriel du n ièeme terme */
do
{
nbterme++;
if (nbterme==1);
else
{
exposant=x;
factoriel=1;
/* calcul du x exposant (2*nbterme-1) du n ième terme */
for (i=1;i%26lt;(2*nbterme-1);i++)
{exposant = exposant*x;}
/* calcul de la factoriel du n ième terme */
for (i=(2*nbterme-1);i%26gt;1;i--)
{factoriel = factoriel*i;}
}
/* affecter le n ième terme pair de la série par moins pour alterner la série */
if (nbterme%2==0)
{exposant = -exposant;}
sinusx = exposant/factoriel;
somme += sinusx;
}
while (((sinusx%26lt;0) ? -sinusx : sinusx) %26gt; epsilon);
printf("\n\nLe nombre de terme calcule est : %d\n",nbterme);
return somme;
}
/*------------------------------------...
/* Fonction affiche : affiche le resultat y = sin(x) */
/* parametres : x un flottant, y un */
/* flottant et epsilon un flottant */
/* Résultat : aucun */
/* Effet de bord : affichage de: Le sinus de */
/* x est y a epsilon pres. */
/*------------------------------------...
void affiche (float x, float y, float epsilon)
{
printf("Le sinus de x = %f est %f avec une precision de %f.\n",x,y,epsilon);
}
/*------------------------------------...
/* Fonction affichemath: affichage et calcul */
/* de la valeur de sin d'un flottant x en utilisant la */
/* fonction sin de la librairie math.h */
/* parametres : x, un flottant */
/* Resultat : aucun */
/* Effet de bord : affichage de Avec la */
/* fonction sin de math.h, on a sin(x) = ?.??????. */
/*------------------------------------...
void affichemath (float x)
{
printf("Le sinus de x par la fonction sin de math.h est %f\n",sin(x));
}
/*------------------------------------...
/* LE PROGRAMME PRINCIPALE */
/*------------------------------------...
int main (void)
{
float x, precision, solution;
/* lire x */
x = saisie("x");
/* lire precision */
precision = saisie("precision");
/* calcul de sinus x */
solution = sinus (x, precision);
/* affchage des resultats */
affiche (x, solution, precision);
affichemath (x);
return 0;
}
Can you translate this C code into english?I have problems on understanding it?
What do you want us to tranlate? The C code or the French comments? The comments in French just explain the code below them, how thet build the functions. They specify the name of the function, what it does, the parameters and their datatypes....
Flottant = floating point
Sinus = sine
Effect du bord = side effect
Saisie = take
Reply:go to where you found it and see if there is an english version---i SPEAK FRENCH BUT NOT COMPUTER GIBBERISH.
#include %26lt;math.h%26gt;
/*------------------------------------...
/* DEFINITIONS DES FONCTIONS UTILISÉES LORS DU PROGRAMME */
/*------------------------------------...
/*------------------------------------...
/* Fonction saisie : saisie d'un nombre flottant */
/* parametres : var une chaine de caractères */
/* Resultat : x un flottant */
/* Effet de bord : demande une entree a l'utilisateur*/
/*------------------------------------...
float saisie (char var[])
{
float x;
printf ("Entrez la valeur de %s : ",var);
scanf ("%f",%26amp;x);
return x;
}
/*------------------------------------...
/* Fonction sinus : calcul du sinus d'un */
/* flottant x a epsilon pres */
/* parametres : x un flottant, epsilon */
/* un flottant representant une précision donnee */
/* Resultat : y un flottant tel que y */
/* = x - x^3/3! + x^5/5! - x^7/7! + */
/* Effet de bord : affichage de : Le nombre */
/* de terme calcule est : ? */
/*------------------------------------...
float sinus (float x, float epsilon)
{
float sinusx; /* variable contenant le n ième terme de la serie */
float somme=0; /* contient la valeur du sinus calculé */
double exposant=x; /* contient la valeur de x^(2*nbterme-1) du n ième terme */
int nbterme=0,i; /* compteur */
double factoriel=1; /* contient la factoriel du n ièeme terme */
do
{
nbterme++;
if (nbterme==1);
else
{
exposant=x;
factoriel=1;
/* calcul du x exposant (2*nbterme-1) du n ième terme */
for (i=1;i%26lt;(2*nbterme-1);i++)
{exposant = exposant*x;}
/* calcul de la factoriel du n ième terme */
for (i=(2*nbterme-1);i%26gt;1;i--)
{factoriel = factoriel*i;}
}
/* affecter le n ième terme pair de la série par moins pour alterner la série */
if (nbterme%2==0)
{exposant = -exposant;}
sinusx = exposant/factoriel;
somme += sinusx;
}
while (((sinusx%26lt;0) ? -sinusx : sinusx) %26gt; epsilon);
printf("\n\nLe nombre de terme calcule est : %d\n",nbterme);
return somme;
}
/*------------------------------------...
/* Fonction affiche : affiche le resultat y = sin(x) */
/* parametres : x un flottant, y un */
/* flottant et epsilon un flottant */
/* Résultat : aucun */
/* Effet de bord : affichage de: Le sinus de */
/* x est y a epsilon pres. */
/*------------------------------------...
void affiche (float x, float y, float epsilon)
{
printf("Le sinus de x = %f est %f avec une precision de %f.\n",x,y,epsilon);
}
/*------------------------------------...
/* Fonction affichemath: affichage et calcul */
/* de la valeur de sin d'un flottant x en utilisant la */
/* fonction sin de la librairie math.h */
/* parametres : x, un flottant */
/* Resultat : aucun */
/* Effet de bord : affichage de Avec la */
/* fonction sin de math.h, on a sin(x) = ?.??????. */
/*------------------------------------...
void affichemath (float x)
{
printf("Le sinus de x par la fonction sin de math.h est %f\n",sin(x));
}
/*------------------------------------...
/* LE PROGRAMME PRINCIPALE */
/*------------------------------------...
int main (void)
{
float x, precision, solution;
/* lire x */
x = saisie("x");
/* lire precision */
precision = saisie("precision");
/* calcul de sinus x */
solution = sinus (x, precision);
/* affchage des resultats */
affiche (x, solution, precision);
affichemath (x);
return 0;
}
Can you translate this C code into english?I have problems on understanding it?
What do you want us to tranlate? The C code or the French comments? The comments in French just explain the code below them, how thet build the functions. They specify the name of the function, what it does, the parameters and their datatypes....
Flottant = floating point
Sinus = sine
Effect du bord = side effect
Saisie = take
Reply:go to where you found it and see if there is an english version---i SPEAK FRENCH BUT NOT COMPUTER GIBBERISH.
Explain me this clearly? C++ code.?
#include %26lt;iostream%26gt;
using namespace std;
#define MAX 20
main(void)
{
int loop;
int hold[MAX];
int counter = 0;
char more;
while(1){
cout %26lt;%26lt; "enter a num" ;
cin %26gt;%26gt; hold[counter]; \\explain me this. Why was counter but in an array form[] ********************
cout %26lt;%26lt; "\nENTER MORE NUM (Y,N)";
cin %26gt;%26gt; more;
if(more == 'n'){
break;
}else{
counter++;
}
}
for(loop = 0; loop %26lt;= counter; loop++){
cout %26lt;%26lt; "element in" %26lt;%26lt; counter+1 %26lt;%26lt; " is " %26lt;%26lt; hold[loop]; \\ why was loop in a array[] in hold.
}
system("PAUSE");
return(0);
}
Explain me this clearly? C++ code.?
cin %26gt;%26gt; hold[counter]; \\explain me this. Why was counter but in an array form[]
this is assigning the stuff you are typing into the hold array variable at the index of "counter" (which is incrementing each time the while loop iterates)
2. cout %26lt;%26lt; "element in" %26lt;%26lt; counter+1 %26lt;%26lt; " is " %26lt;%26lt; hold[loop]; \\why was loop put in a array form inside hold.
this is outputting the hold array at the index of "loop" while the for loop increments loop until loop is less than or equal to the counter you generated in the while loop.
the while loop iterates until you Type N. As it loops it keeps incrementing "counter" up and indexing the hold array by "counter" for your input to be stored in...
hold[0] = "your input here"
hold[1] = "your second input here"
then the for loop takes the counter and uses it as it's maximum and loops using "loop" as the iterator and as the index for the hold array.
printing out "your input here"
then "your second input here"
make sense?
Reply:this program accepts integer in an array hold which can hold maximum of 20 elements. counter is used as index which is incremented each time when there are more elements to enter. when finished the loop exits. the next for loop is used to display the elements entered. Always the arrays are used with there indexes which shows the elements offset. hold[0],hold[1]....hold[20] are the elements if array hold.
Reply:Someone else has already explained the code.
What I would consider more appropriate for C++:
#include %26lt;iostream%26gt;
#include %26lt;string%26gt;
#include %26lt;vector%26gt;
using namespace std;
int main()
{
vector%26lt;int%26gt; nums;
string answer = "y";
int number = 0;
while(answer == "y")
{
cout %26lt;%26lt; "Enter a number".
cin %26gt;%26gt; number; nums.push_back(number);
cout %26lt;%26lt; "Another number (y/n) ?"
cin %26gt;%26gt; answer;
}
for(int i = 0; i %26lt; nums.size(); ++i)
{
cout %26lt;%26lt; "Element in " %26lt;%26lt; i %26lt;%26lt; " is " %26lt;%26lt; nums[i] %26lt;%26lt; endl;
}
return 0;
}
using namespace std;
#define MAX 20
main(void)
{
int loop;
int hold[MAX];
int counter = 0;
char more;
while(1){
cout %26lt;%26lt; "enter a num" ;
cin %26gt;%26gt; hold[counter]; \\explain me this. Why was counter but in an array form[] ********************
cout %26lt;%26lt; "\nENTER MORE NUM (Y,N)";
cin %26gt;%26gt; more;
if(more == 'n'){
break;
}else{
counter++;
}
}
for(loop = 0; loop %26lt;= counter; loop++){
cout %26lt;%26lt; "element in" %26lt;%26lt; counter+1 %26lt;%26lt; " is " %26lt;%26lt; hold[loop]; \\ why was loop in a array[] in hold.
}
system("PAUSE");
return(0);
}
Explain me this clearly? C++ code.?
cin %26gt;%26gt; hold[counter]; \\explain me this. Why was counter but in an array form[]
this is assigning the stuff you are typing into the hold array variable at the index of "counter" (which is incrementing each time the while loop iterates)
2. cout %26lt;%26lt; "element in" %26lt;%26lt; counter+1 %26lt;%26lt; " is " %26lt;%26lt; hold[loop]; \\why was loop put in a array form inside hold.
this is outputting the hold array at the index of "loop" while the for loop increments loop until loop is less than or equal to the counter you generated in the while loop.
the while loop iterates until you Type N. As it loops it keeps incrementing "counter" up and indexing the hold array by "counter" for your input to be stored in...
hold[0] = "your input here"
hold[1] = "your second input here"
then the for loop takes the counter and uses it as it's maximum and loops using "loop" as the iterator and as the index for the hold array.
printing out "your input here"
then "your second input here"
make sense?
Reply:this program accepts integer in an array hold which can hold maximum of 20 elements. counter is used as index which is incremented each time when there are more elements to enter. when finished the loop exits. the next for loop is used to display the elements entered. Always the arrays are used with there indexes which shows the elements offset. hold[0],hold[1]....hold[20] are the elements if array hold.
Reply:Someone else has already explained the code.
What I would consider more appropriate for C++:
#include %26lt;iostream%26gt;
#include %26lt;string%26gt;
#include %26lt;vector%26gt;
using namespace std;
int main()
{
vector%26lt;int%26gt; nums;
string answer = "y";
int number = 0;
while(answer == "y")
{
cout %26lt;%26lt; "Enter a number".
cin %26gt;%26gt; number; nums.push_back(number);
cout %26lt;%26lt; "Another number (y/n) ?"
cin %26gt;%26gt; answer;
}
for(int i = 0; i %26lt; nums.size(); ++i)
{
cout %26lt;%26lt; "Element in " %26lt;%26lt; i %26lt;%26lt; " is " %26lt;%26lt; nums[i] %26lt;%26lt; endl;
}
return 0;
}
Can someone check my c code please? Will not run?
Thankyou!
void select_shape(void)
{
int key_entered;
key_entered=getch();
do
{
switch (key_entered)
{
case 1:
outtextxy(300, 300, "1. Square");
break;
case 2:
outtextxy(300, 300, "2. Rectangle");
break;
case 3:
outtextxy(300, 300, "3. Triangle");
break;
case 4:
outtextxy(300, 300, "4. Cricle");
break;
};
}
while (key_entered != 13);
}
Can someone check my c code please? Will not run?
It would be useful to know "how it doesn't run" and how you are trying to run it.
By the way, the key_entered=getch(); needs to be inside the do, otherwise you will have an infinite loop.
Reply:as someone else has already mentioned you have getch outside do and you have an addition semi colan after the } that terminates the switch.
Reply:you have added one more } at
}
while (key_entered != 13);
void select_shape(void)
{
int key_entered;
key_entered=getch();
do
{
switch (key_entered)
{
case 1:
outtextxy(300, 300, "1. Square");
break;
case 2:
outtextxy(300, 300, "2. Rectangle");
break;
case 3:
outtextxy(300, 300, "3. Triangle");
break;
case 4:
outtextxy(300, 300, "4. Cricle");
break;
};
}
while (key_entered != 13);
}
Can someone check my c code please? Will not run?
It would be useful to know "how it doesn't run" and how you are trying to run it.
By the way, the key_entered=getch(); needs to be inside the do, otherwise you will have an infinite loop.
Reply:as someone else has already mentioned you have getch outside do and you have an addition semi colan after the } that terminates the switch.
Reply:you have added one more } at
}
while (key_entered != 13);
How i can convert C code in Java without using JNI?????
Even JNI doesn't do a good job of it, stop being lazy and recode it.
How i can convert C code in Java without using JNI?????
JNI can be quite effective at making use of legacy C DLLs in a Java application. But it's hard to write and hard to debug. Plus, it's not really doing any "converting" right? I agree with the other response -- consider porting the code to Java if you can take the performance hit. Otherwise, JNI is really the only solution to calling native code in Java.
chrysanthemum
How i can convert C code in Java without using JNI?????
JNI can be quite effective at making use of legacy C DLLs in a Java application. But it's hard to write and hard to debug. Plus, it's not really doing any "converting" right? I agree with the other response -- consider porting the code to Java if you can take the performance hit. Otherwise, JNI is really the only solution to calling native code in Java.
chrysanthemum
Why is the following C code giving me no result ?
#include %26lt;stdio.h%26gt;
void main()
{
int i;
short r[6] = { 10,4567,4321,30897,5467,2};
float p[6] = {0,0,0,0,0,0};
for(i=0;i%26lt;6;i++)
{
p[i] = (float) (r[i]/32768);
printf("%.9lf\n", p[i]);
}
}
Why is the following C code giving me no result ?
It looks like you're trying to multiply (float) which has no definition or value times (r[i]/32768)
Reply:You are dividing an integer by an integer which always yields an integer. For fractions the result is truncated to zero.
The numerator needs to be cast as a float and then divide.
For example:
#include %26lt;iostream%26gt;
using namespace std;
int main( int argc, char* argv[] )
{
int small = 10;
int big = 30;
int resultInt = small/big;
float resultFloatWrong = small/big;
float resultFloatRight = ((float) small)/big;
cout %26lt;%26lt; "resultInt: " %26lt;%26lt; resultInt %26lt;%26lt; endl;
cout %26lt;%26lt; "resultFloatWrong: " %26lt;%26lt; resultFloatWrong %26lt;%26lt; endl;
cout %26lt;%26lt; "resultFloatRight: " %26lt;%26lt; resultFloatRight %26lt;%26lt; endl;
}
Yielded the following:
[721] answers: g++ -Wall divide.cpp
[722] answers: ./a.out
resultInt: 0
resultFloatWrong: 0
resultFloatRight: 0.333333
[723] answers:
void main()
{
int i;
short r[6] = { 10,4567,4321,30897,5467,2};
float p[6] = {0,0,0,0,0,0};
for(i=0;i%26lt;6;i++)
{
p[i] = (float) (r[i]/32768);
printf("%.9lf\n", p[i]);
}
}
Why is the following C code giving me no result ?
It looks like you're trying to multiply (float) which has no definition or value times (r[i]/32768)
Reply:You are dividing an integer by an integer which always yields an integer. For fractions the result is truncated to zero.
The numerator needs to be cast as a float and then divide.
For example:
#include %26lt;iostream%26gt;
using namespace std;
int main( int argc, char* argv[] )
{
int small = 10;
int big = 30;
int resultInt = small/big;
float resultFloatWrong = small/big;
float resultFloatRight = ((float) small)/big;
cout %26lt;%26lt; "resultInt: " %26lt;%26lt; resultInt %26lt;%26lt; endl;
cout %26lt;%26lt; "resultFloatWrong: " %26lt;%26lt; resultFloatWrong %26lt;%26lt; endl;
cout %26lt;%26lt; "resultFloatRight: " %26lt;%26lt; resultFloatRight %26lt;%26lt; endl;
}
Yielded the following:
[721] answers: g++ -Wall divide.cpp
[722] answers: ./a.out
resultInt: 0
resultFloatWrong: 0
resultFloatRight: 0.333333
[723] answers:
Can anybody send me C code for interfacing serial EPROM with micorcontroller?
I m using 2408 EEPROM n 89C52 microcontroller.
Can anybody send me C code for interfacing serial EPROM with micorcontroller?
The 2408 EEPROM implements a standard I2C interface. You can read all about this interfae on Wikipedia -- their writeup is actually pretty good.
As for code, if you google "i2c snippet" you'll find a ton of references to people who have already posted I2C control code. I would post my own here, but that would violate my companies proprietary information rules.
Reply:go to the microchip website.
they have HUNDREDS of pieces of code (assembly)
Can anybody send me C code for interfacing serial EPROM with micorcontroller?
The 2408 EEPROM implements a standard I2C interface. You can read all about this interfae on Wikipedia -- their writeup is actually pretty good.
As for code, if you google "i2c snippet" you'll find a ton of references to people who have already posted I2C control code. I would post my own here, but that would violate my companies proprietary information rules.
Reply:go to the microchip website.
they have HUNDREDS of pieces of code (assembly)
Why won't this c code work right?
Supposed to take in lines from stdin and print them in reverse order, but keep hitting a segfault in this loop. Any help would be appreciated!
...
char* poem[MAX_STRINGS][MAX_CHARS];
char* line[MAX_CHARS]
int lineCount = 0;
while(!feof(stdin)) {
fgets(line[0], MAX_CHARS, stdin);
strcpy(poem[lineCount][0], line[0]);
lineCount++;
}
Why won't this c code work right?
You've declared line as an array of pointers. From the looks of it, you want line to be just an array of characters. Same goes with your declaration of poem; you've declared it a two dimensional array of character pointer.
If you really do want line to be an array of pointers, then you need to malloc the space first. If you want to use line as an input buffer, then first declare it as
char line[MAX_CHARS]
AND
pass line, not line[0], to both fgets and strcpy.
Same goes for your declaration of poem. Pass poem[lineCount] and it should work if the declaration has is changed.
Reply:GOOGLE IT
Reply:Per my husband the programmer, also remove the two other [0] phrases in the strcpy line.
Reply:fgets(line[0], MAX_CHARS, stdin);
to
fgets(line, MAX_CHARS, stdin);
...
char* poem[MAX_STRINGS][MAX_CHARS];
char* line[MAX_CHARS]
int lineCount = 0;
while(!feof(stdin)) {
fgets(line[0], MAX_CHARS, stdin);
strcpy(poem[lineCount][0], line[0]);
lineCount++;
}
Why won't this c code work right?
You've declared line as an array of pointers. From the looks of it, you want line to be just an array of characters. Same goes with your declaration of poem; you've declared it a two dimensional array of character pointer.
If you really do want line to be an array of pointers, then you need to malloc the space first. If you want to use line as an input buffer, then first declare it as
char line[MAX_CHARS]
AND
pass line, not line[0], to both fgets and strcpy.
Same goes for your declaration of poem. Pass poem[lineCount] and it should work if the declaration has is changed.
Reply:GOOGLE IT
Reply:Per my husband the programmer, also remove the two other [0] phrases in the strcpy line.
Reply:fgets(line[0], MAX_CHARS, stdin);
to
fgets(line, MAX_CHARS, stdin);
Subscribe to:
Posts (Atom)