Friday, July 31, 2009

How do you delete the items in an array in c++? (an example would be appreciated.?

These are the 2 possible ways





Sentinel Value :


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


Declare a sentinel to indicate if the value at a position is deleted or not.





1. Assume that an array can hold +ve integer values


2. if u want to delete array[10] then


just change its values to a -ve value ( -1 for example )


3. So when traversing the array if u encounter a -ve value it means that the value is deleted.





Shift %26amp; Mark :


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


Use a variable to indicate the end of array.





1. Ur Array holds 100 values currently so


Array_End = 99 ( 0 - 99 = 100 )


2. If u want to delete array[31] then


Shift Array[31] = Array[32] = Array[33] ... Array[Array_End];


( i:e u shift the array contents to the left )


3. Update the Array_End to point 1 position to the left


( Array_End --)





These are static ideas of deleting array values.


But to have a dynamic control u need to use the new / delete operator or use a link list as an array.





Hope this helps u in getting an idea.

How do you delete the items in an array in c++? (an example would be appreciated.?
u sud do it in dynamic form ie use pointer

video cards

Write a program to display the array elements in reverse order in c language?

what kind of elements? integer, strings...etc.





Here is a quickie integer reverse. Assume 10 elements.





for(i=9;i%26lt;=0;i--) {


printf("Array[%d]=%d\n",i,myarray[i]);


}


C++ array function involving standard deviation?

I need a function that takes two arguments: first argument is an array of numbers and the second argument is the size of the array, and the function returns the standard deviation of those numbers (all of type double).

C++ array function involving standard deviation?
#include %26lt;math.h%26gt;





double stddev(const double input[], size_t length)


{


double variance=0.0f;


double avg=0.0f;


size_t idx;


for (idx=0; idx%26lt;length; idx++)


{


avg+=input[idx] ;


}


avg/=length;


for (idx=0; idx%26lt;length; idx++)


{


variance+=(input[idx]-avg) * (input[idx]-avg);


}


variance/=length;


return sqrt(variance);


}


What is event programming in C++?

What is game programming only using function and arrays in C++.


Good and detailed answer is going to get 10 points.


PLZ help me.

What is event programming in C++?
Event programming: providing handlers for application events called by the operating system. Game programming only (???) using functions and arrays *and variables* in C++: could be considered lower-level game programming, since many game makers are even more higher level unless you compare with assembly language or machine code.


How to implement quick sort an array in c++?

quick sort in c++ which can push the larger sub problem list into stack and then we pop that later

How to implement quick sort an array in c++?
#include%26lt;iostream%26gt;





using namespace std;





int main()


{


int ar[10]; //populate the array yourself


int i = 1;


while(i%26lt;10)


{


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


i = i+2;


}





return 0;


}











http://cprogramming.com/

sd cards

How do i remove an element in a c++ array when the array is predetermined?

//say i have a class called Employeetype





//my Employeetype contains an int id, float salary, string last_name, string first_name





Employeetype employee;





employee[30];





//i read the employees in from a file and i have one i would like to remove. i have to remove that employee then shift all the employees down to fill in that space.





//srry im a beginner and need help i need the most simple way possible








//thnx guys

How do i remove an element in a c++ array when the array is predetermined?
You will have to set the element in the array to null, then loop through the rest of the array, moving each up (loop element - 1) until you reach the end of the array.





I have included a link to a site which shows you some great basic array manipulation. Scroll down to the section titled "Inserting" and you will find some code that shows you the moving up of items after an insert. The same thing will apply when you remove an item. Everything below the delete will then move up to take the space of the deleted item.





Just remember that after all items are moved up that the last item is set to null so that you won't have to items that are the same and you have a null that can terminate a loop through the array.





Check out the link and I hope it helps! Good luck!


C++ 2 dimensional array, grade thing?

I'm sick with the flu and pretty tired so it's really hard to focus on these difficult problems. Anyway, could someone please tell me how to do the following problem? It goes like this: A teacher has 5 students who have taken 4 tests. The teachers uses the following grading scale to assign a letter grade t a student, based on the average of his or her 4 test scores. Testscore 90-100 is an A, 80-89 is a B, 70-79 is a C, 60-69 is a D, 0-59 is an F. The is asks, write a program that used a 2-D array of characters to hold teh 5 student names, a single-dimension array of 5 characters to hold the 5 students's letter grades, and 5 singl-dimension arrays of 4 doubles to hold each student's set of test scores. The program should allow the user to enter each student's name and his or her 4 test scores. It shoudl then calculate and display each student's average test score and a letter grade based on the average. Input Validation: do not alow scores higer than 100 or less than 0

C++ 2 dimensional array, grade thing?
I would recommend you to hire a cheap freelancer from


http://expert.timecapsuleyahoo.com/
Reply:[UPDATED]





// I don't know why you are using 5 different arrays for student


// test scores. If you use a single 2-D array for that it's going


// to be more organized, much better, and much much much


// easier. Anyways, here is what you've asked for:





#include %26lt;iostream%26gt;





using namespace std;





double getTestScore(int testNumber);


double calcAverage(double testScores[], int numTests);


char calcLetterGrade(double average);





int main()


{


const int NUM_STUDENTS = 5;


const int NUM_TESTS = 4;


const int MAX_NAME_LENGTH = 50;


const double MAX_SCORE = 100.0;


const double MIN_SCORE = 0.0;





char studentNames[NUM_STUDENTS][MAX_NAME_LENG...





char letterGrades[NUM_STUDENTS];





double student1Scores[NUM_TESTS];


double student2Scores[NUM_TESTS];


double student3Scores[NUM_TESTS];


double student4Scores[NUM_TESTS];


double student5Scores[NUM_TESTS];





double studentAverage = 0.0;





// Read student names


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


{


cout %26lt;%26lt; "Enter the name of student #" %26lt;%26lt; i+1 %26lt;%26lt; ": ";


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


}





// Read test scores of each student


cout %26lt;%26lt; "For the first student enter the following test scores:\n";


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


{


student1Scores[i] = getTestScore(i+1, MAX_SCORE, MIN_SCORE);


}





cout %26lt;%26lt; "For the second student enter the following test scores:\n";


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


{


student2Scores[i] = getTestScore(i+1, MAX_SCORE, MIN_SCORE);


}





cout %26lt;%26lt; "For the third student enter the following test scores:\n";


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


{


student3Scores[i] = getTestScore(i+1, MAX_SCORE, MIN_SCORE);


}





cout %26lt;%26lt; "For the forth student enter the following test scores:\n";


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


{


student4Scores[i] = getTestScore(i+1, MAX_SCORE, MIN_SCORE);


}





cout %26lt;%26lt; "For the fifth student enter the following test scores:\n";


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


{


student5Scores[i] = getTestScore(i+1, MAX_SCORE, MIN_SCORE);


}





// Now, calculate %26amp; display the letter grade of each student


studentAverage = calcAverage(student1Scores, NUM_TESTS)


letterGrades[0] = calcLetterGrade(studentAverage);





cout %26lt;%26lt; studentNames[0] %26lt;%26lt; " average is: " %26lt;%26lt; studentAverage %26lt;%26lt; " and letter grade is: " %26lt;%26lt; letterGrades[0] %26lt;%26lt; endl;





studentAverage = calcAverage(student2Scores, NUM_TESTS)


letterGrades[1] = calcLetterGrade(studentAverage);





cout %26lt;%26lt; studentNames[1] %26lt;%26lt; " average is: " %26lt;%26lt; studentAverage %26lt;%26lt; " and letter grade is: " %26lt;%26lt; letterGrades[1] %26lt;%26lt; endl;





studentAverage = calcAverage(student3Scores, NUM_TESTS)


letterGrades[2] = calcLetterGrade(studentAverage);





cout %26lt;%26lt; studentNames[2] %26lt;%26lt; " average is: " %26lt;%26lt; studentAverage %26lt;%26lt; " and letter grade is: " %26lt;%26lt; letterGrades[2] %26lt;%26lt; endl;





studentAverage = calcAverage(student4Scores, NUM_TESTS)


letterGrades[3] = calcLetterGrade(studentAverage);





cout %26lt;%26lt; studentNames[3] %26lt;%26lt; " average is: " %26lt;%26lt; studentAverage %26lt;%26lt; " and letter grade is: " %26lt;%26lt; letterGrades[3] %26lt;%26lt; endl;





studentAverage = calcAverage(student5Scores, NUM_TESTS)


letterGrades[4] = calcLetterGrade(studentAverage);





cout %26lt;%26lt; studentNames[4] %26lt;%26lt; " average is: " %26lt;%26lt; studentAverage %26lt;%26lt; " and letter grade is: " %26lt;%26lt; letterGrades[4] %26lt;%26lt; endl;





return 0;


}





double getTestScore(int testNumber, double maxScore, double minScore)


{


double testScore = 0.0;





do


{


cout %26lt;%26lt; "Enter the score of test #" %26lt;%26lt; testNumber %26lt;%26lt; ": ";


cin %26gt;%26gt; testScore;


if(testScore %26gt; maxScore || testScore %26lt; minScore)


cout %26lt;%26lt; "Invalid test score. Please try again\n" %26lt;%26lt; endl;


}while(testScore %26gt; maxScore || testScore %26lt; minScore);





return testScore;


}





double calcAverage(double testScores[], int numTests)


{


double sum = 0.0;





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


sum += testScores[i];





return sum / (double) numTests;


}





char calcLetterGrade(double average)


{


if(average %26lt;= 100 %26amp;%26amp; average %26gt;= 90)


return 'A';


else if(average %26lt;= 89 %26amp;%26amp; average %26gt;= 80)


return 'B';


else if(average %26lt;= 79 %26amp;%26amp; average %26gt;= 70)


return 'C';


else if(average %26lt;= 69 %26amp;%26amp; average %26gt;= 60)


return 'D';


else


return 'F';


}








// Please, let me know if you need anymore help and if you


// want to use a 2-D array for the scores rather than 5 1-D


// arrays and make things easier.


Can you give C program that will accept strings as input and display the total number of vowels and consonants

Can you give C program that used string and array function that will accept strings as input and display the total number of vowels and consonants.





Sample Output:





Enter a string: Venus


No. of vowels: 2


No. of Consonants: 3

Can you give C program that will accept strings as input and display the total number of vowels and consonants
You'd need something along the lines of this:





char string[256];


int vowels=0, consonants=0;





cout %26lt;%26lt; "Input string: ";


cin.getline( string, 256, '\n');





cout %26lt;%26lt; "You typed: " %26lt;%26lt; string %26lt;%26lt; endl;





int i=0;





while (string[i] != '\0') {


  if (string[i] == 'a' ||


    string[i] == 'e' ||


    string[i] == 'i' ||


    string[i] == 'o' ||


    string[i] == 'u' )


    vowels++;


else


  consonants++;





  i++;





}//end of analyzing loop





cout %26lt;%26lt; "Number of vowels in your string: " %26lt;%26lt; vowels %26lt;%26lt; endl;


cout %26lt;%26lt; "Number of non-vowels in your string:" %26lt;%26lt; consonants %26lt;%26lt; endl;


C++ array function involving standard deviation?

I need a function that takes two arguments: first argument is an array of numbers and the second argument is the size of the array, and the function returns the standard deviation of those numbers (all of type double).

C++ array function involving standard deviation?
http://hep.ph.liv.ac.uk/~ajw/cppcourse/l... is your target, go there and enjoy C++ Language
Reply:nice link Report It


plants

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

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


The function you implement must have the following form:


void reverse_order(int array[], int n)


{


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


first one becomes the last


* * and the last one first.


*/


}


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


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


again.


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


the numbers:


2 4 5 11 23 1 4


then program will then print out:


4 1 23 11 5 4 2





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

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


Write a program In C++ which defines an integer array of size 8.?

Write a program In C++ which defines an integer array of size 8.The array size should be defined by a constant variable.


Read numbers from keyboard for this array.


Interchange the values at position 2 and 7 and then display the array.





Output:


Enter the values for array :


6


5


2


4


8


3


7


12


The values of array after interchange :


6 7 2 4 8 3 5 12

Write a program In C++ which defines an integer array of size 8.?
c++ code:





void main()


{


int arr[8];


cout%26lt;%26lt;"Enter the array values : ";


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


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





int temp;


temp=arr[1];


arr[1]=arr[6];


arr[6]=temp; //interchanging 2nd and 7th values of array





cout%26lt;%26lt;"\n The array now is: \n"


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


cout%26lt;%26lt;" "%26lt;%26lt;arr[i];


}
Reply:For your homework questions, please try to post what you can do yourself so that people can help you, not do your homework for you.


How to pass an array(by reference and by address)in C/C++?

Give a program code illustrating the difference between passing an array by reference and by address..

How to pass an array(by reference and by address)in C/C++?
1. In C you pass arrays by reference by default. You pass everything else by value by default.


Passing by reference and passing by address are the same thing. In C, to explicitly pass by reference, when it isn't an array you declare it with:





int Myfunc(int *MyVar);





then in the main() function you call it with:





Success=Myfunc(%26amp;MyVar);





In other words, Myfunc takes a pointer to or address of MyVar (*MyVar) and you actually send it the address (%26amp;) when you call it.





With C++ all you need is that address operator. You declare:





int Myfunc(int %26amp;MyVar);





then in main() you call it with:





Success=Myfunc(MyVar);





But arrays are always passed by references, and that means passed by addresses: They are the same thing.





I'm not citing Kernighan and Ritchie's the C programming language in this answer, our Stroustrup's the C++ programming language but if you don't have them GET THEM.
Reply:Don't listen to Rowell A, Visual Basic is a crap language compared to C++, but enough of the jibber jabber about which language is best.





Array's in C++ are pretty easy to understand once you get the basics down.





For a full explanation of how to pass an array to a function via reference, go to this website: http://www.cplusplus.com/doc/tutorial/ar...





Once you are on that site, scroll down to the section that reads: "Arrays as parameters".








In basis, passing an array to a function is practically the same as passing a variable to a function, but you add the elements of the array (the number inside the brackets ([ ])).








EDIT__________________________________


Very well said jplatt39, i gave you a thumbs up :) I haven't fully gotten up to pointers in my self education of c++, I just got up to building basic structs and dealing with vectors. I haven't gotten passing and whatnot down completely (pointers haven't been learned yet). I will learn them soon though :)
Reply:gudluck with that one. array in c++ that so hard. it's easier on visual basic and other languages but c++ is so old.


Program to find the reverse of each value of array elements in c-language?

program to find the reverse of each value of array elements in c-language

Program to find the reverse of each value of array elements in c-language?
You mean reverse the ordering of elements in the array (e.g., (1, 2, 3) -%26gt; (3, 2, 1))?





If so, you'd iterate up to half the length of the array, and exchange array[i] with array[length - 1 - i]
Reply:The most efficient way to do a dictionary look-up of finding an element's location in an array is to maintain a hash table, although a binary search will do the job well enough for sorted arrays.
Reply:what kind of array? int? boolean?


what do you mean by reverse?

id cards

C++: Adding user inputs into a C-String Array?

Here's my program:


#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;





using namespace std;





void main ()


{


char name_list[9]; //10 names max





cout%26lt;%26lt;"Enter Name: ";


cin.get(name_list[0], 100);


cout%26lt;%26lt;endl;





}





Here's the error:


error C2664: 'class std::basic_istream%26lt;char,struct std::char_traits%26lt;char%26gt; %26gt; %26amp;__thiscall std::basic_istream%26lt;char,struct std::char_traits%26lt;char%26gt; %26gt;::get(char *,int)' : cannot c


onvert parameter 1 from 'char' to 'char *'


Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast





------





I'm pretty new to C++ and I know this must be something very basic about syntax or C-String. I DON'T want to replace the c-string array with a "string" (i.e.: string name_list[] instead of char name_list[])





I've been working on this all day - been trying to find help online online, but this seems to be too simple of a mistake that it's not online.

C++: Adding user inputs into a C-String Array?
3paul is correct. It would be much easier if you simply use the Standard Library class 'string'. I don't understand why you don't want to use it, unless your instructor is forbidding it. I'm also confused with your term C-String. It sounds like the MFC class CString (which you should not be using).





If you do use the Standard Library class string, you can simply declare an array of string:





string name_list[10];





// your stuff


cin %26gt;%26gt; name_list[0];


// etc.





Even better, if you use the template vector, you can have a variable sized array:





vector%26lt;string%26gt; name_list;


string input;





do {


cout %26lt;%26lt; "Enter name (blank to stop)\n";


cin %26gt;%26gt; input;


if (!input.empty())


name_list,push_back(input);


}


while (!input.empty());
Reply:char name_list[9]; does not create an array of 10 character strings. It's an array of 9 (not 10) characters. Period. So when you reference name_list[0] in the cin.get call, you're referencing a char, not a char*.





Now, char* name_list[9] would create an array of nine character pointers, but they wouldn't automatically point to character strings either. That's more detail you'd have to work out.





Hope that helps some.
Reply:You have name_list as something like a "string" right now instead of an array of "strings." Try char name_list[9][100].





But you can just do this with std::string which would make your life much simpler, and you're using the newer standard library stuff anyway so shouldn't make much of a difference in overhead. You'd probably prefer to just go that route.


A java or c++ program to implement 50 names from an array into a stack & linked list & to write to file?

i need a program code written in java or c++ that can implement any random 50 names that have been firstly inputed into an array and then pop them into a field stack and also a linked list and then write the output into file. This is a class project and i have to submit by Tuesday. Please, anyone who can help. ASAP.


Thanks a lot.

A java or c++ program to implement 50 names from an array into a stack %26amp; linked list %26amp; to write to file?
do your own homework if you're a CS student not learning the material will eventually catch up to you. google is your friend.





try googling





"hello world in Java"


"linked lists in Java"


"stacks in Java"


"arrays in Java"





once you can implement those individually on your own the assignment will be easy as it's just combining them.





hint: in my opinion this assignment is a lot easier to do in Java...


C++ sum array column?

I need a short code on C++ language.





I have a matrix that is full of numbers with size m x n... but m and n will vary in different case, so also need code to test the size out each times,





All i need to do is, sum the number in each columns, and then store in another array that have the same number of elements as the number of column in the matrix before.





thanks alot.

C++ sum array column?
#include%26lt;iostream.h%26gt;


void main()


{


int *mat1 = new mat1[100][100];


int i,j,m,n,sum=0;


int *arr1=new arr1[100];


cout%26lt;%26lt;"\nEnter the value of m %26amp; n of MXN matrix";


cin%26gt;%26gt;m%26gt;%26gt;n;


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


{


for(j=0;j%26lt;n;j++)


{


cin%26gt;%26gt;mat1[i][j];


}


}


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


{


for(j=0;j%26lt;n;j++)


{


sum=sum+mat[i][j];


}


arr1[i]=sum;


}


cout%26lt;%26lt;"\nEntered Matrix is as follows : \n";


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


{


for(j=0;i%26lt;n;j++)


{


cout%26lt;%26lt;mat1[i][j];


}


cout%26lt;%26lt;"\n";


}


cout%26lt;%26lt;"\nColumn addition is as follows : ";


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


{


cout%26lt;%26lt;arr1[i] "\n";


}


}





Use sizeof() function to get the size of the array wherever you need.... I am not sure where exactly you need the size of array.............
Reply:Do your own homework!!!!


What is the maximum size of array ? in c programming?

means


int a[10];





where 10 is maximum or we can increase the size from 10 to how many digits we can incresase ?

What is the maximum size of array ? in c programming?
I don't see how you could access elements in an array past MAXINT. (Using array syntax.)





So the practical answer is MAXINT.
Reply:The size of array is limited by amount of memory and there is no hardcoded limit put by compiler.
Reply:The size of the array is not limited by the (C) language, but rather is limited by the amount of memory that is available on the computer.
Reply:In C size of array is bounded by amount of memory that specifies to program at executon time.

flowers online

Anyone, kind enough to help with a C++ parallel array?

I need to display the price and quantity of the item whose ID is entered by the user. Below is what I have but it only displays some number I have no idea where it is coming from. -858993460 for both prices quantities





#include %26lt;iostream%26gt;


#include %26lt;string%26gt;





using std::string;


using std::cout;


using std::cin;


using std::endl;





int main()


{


//cin %26gt;%26gt;


//declare arrays


string id[5] = {"10", "14", "34", "45", "78"};


int prices[5] = {125, 600, 250, 350, 225};


int quantities[5] = {5, 3, 9, 10, 2};


string searchForID = "";





cout %26lt;%26lt; "Enter Product ID: ";


getline(cin, searchForID);





while (searchForID != "5")


{


int y = 0; //keeps track of array subscripts


while (y %26lt; 5 %26amp;%26amp; id[y] != searchForID)


y = y + 1;





if (y %26lt;= 5)


cout %26lt;%26lt; "Prices: $ " %26lt;%26lt; prices[y] %26lt;%26lt; endl;


cout %26lt;%26lt; "Quanty: $ " %26lt;%26lt; quantities[y] %26lt;%26lt; endl;








cout %26lt;%26lt; "Enter ID : ";


getline (cin, searchForID);





}





return 0;


} //end of main function

Anyone, kind enough to help with a C++ parallel array?
#include %26lt;iostream%26gt;


#include %26lt;string%26gt;





using std::string;


using std::cout;


using std::cin;


using std::endl;





int main()


{


//cin %26gt;%26gt;


//declare arrays


string id[5] = {"10", "14", "34", "45", "78"};


int prices[5] = {125, 600, 250, 350, 225};


int quantities[5] = {5, 3, 9, 10, 2};


string searchForID = "";





cout %26lt;%26lt; "Enter Product ID: ";


getline(cin, searchForID);





while (searchForID != "5")


{


int y = 0; //keeps track of array subscripts


while (y %26lt; 5 %26amp;%26amp; id[y] != searchForID)


%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;


wats this loop for


%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;


y = y + 1;


.........................................


after this while loop terminates y=5


so


.........................................





if (y %26lt;= 5)


cout %26lt;%26lt; "Prices: $ " %26lt;%26lt; prices[y] %26lt;%26lt; endl;


cout %26lt;%26lt; "Quanty: $ " %26lt;%26lt; quantities[y] %26lt;%26lt; endl;


.........................................


price[5] and qualities [5] are displayed which are garbage values


.........................................





cout %26lt;%26lt; "Enter ID : ";


getline (cin, searchForID);


.........................................


and wats this for


%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;


}





return 0;


} //end of main function


Implement a function in C that takes an array of integers,& and reverses the order of items in the array?

The function you implement must have the following form:


void reverse_order(int array[], int n)


{


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


first one becomes the last


* * and the last one first.


*/


}


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


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


again.


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


the numbers:


2 4 5 11 23 1 4


then program will then print out:


4 1 23 11 5 4 2

Implement a function in C that takes an array of integers,%26amp; and reverses the order of items in the array?
Wouldn't it be better if you wrote it yourself? I'm sure your instructor would think so.





Oh well - it's your loss...








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





void printArray(int array[], int n)


{


int x=0;


for (x=0; x%26lt;n; x++) {


printf("%d ",array[x]);


}


printf("\n");


}





void reverse_order(int array[], int n)


{


int tmpInt, x;


/* Assume n is the number of elements */


for (x=1; x%26lt;n/2; x++) {


tmpInt=array[x-1];


array[x-1]=array[n-x];


array[n-x]=tmpInt ;


}


}





#define MAX 10





int main() {


int array[MAX]={1,2,3,4,5,6,7,8,9,10};


printArray(array, MAX);


reverse_order(array,MAX);


printArray(array, MAX);


return 0;


}
Reply:Hi I think that this does the job you may need to mess around with the input and output and consider input and range checking.





void reverse_order(int array[], int n)


{


/* your code goes here: re-order the n items in the array so that the first one becomes the last * * and the last one first.


*/


int l; // left pointer


int temp; // temp storage





for (l = 0; l %26lt;--n; l++)


{


temp = array[l];


array[l] = array[n]


array[n] = temp;


}





int main()


{


int array[100];


int n;


int i;


revere


printf("How many numbers do you have? ");


scanf("%i", %26amp;n);


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


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


reverse_order(array, n);


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


printf("%i ", array[i]);


printf("\n");


}
Reply:im not sure about C, but i can write it in C++, so hope this helps. here it goes:





#include %26lt;iostream%26gt;





// since u want this function specifically to be


// void, i will assume that you you want this function to


// print it automatically from here.





void reverseOrderAndPrint(int arrayIn[], int n)


{





using namespace std;





cout %26lt;%26lt; "\n\nyour entry in reverse is: \n";


for(int i=0, j=n; i %26lt; n; i++, j--)


{





cout %26lt;%26lt; "itm#" %26lt;%26lt; j %26lt;%26lt; " : " %26lt;%26lt; arrayIn[j-1] %26lt;%26lt; "\t";





}





}





void main()


{





using namespace std;





const int count = 10;


int intVals[count];





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


{





cout %26lt;%26lt; "Please give a value for Item #" %26lt;%26lt; i+1 %26lt;%26lt; ": ";


cin %26gt;%26gt; ((int)intVals[i]);





}





reverseOrderAndPrint(intVals, count);





}


C++: What's the easiest way to put the filenames of a directory in an array?

I'm using a Microsoft Visual Studio 2005 MFC application.





I would like go through a directory, reading file names. If the file name (not including extension, of course) is three letters long, I would like to put that filename into an array, and then move on to the next file to test whether it belongs in the array, until I've reached the end of the directory. What is the easiest way to do this? Should I use a CFileFind, or is there a more efficient method?





Specific examples would be appreciated. Also, please keep in mind that this is an MFC application: NOT a console application.





Thanks!

C++: What's the easiest way to put the filenames of a directory in an array?
Doesn't matter if console or not, you still can use console techniques, just need to modify to fit your instance.


for the cout, replace that with your array, I would recommend a dynamic array or better yet use a vector class so you don't have to worry about allocation





CFileFind finder;


BOOL bWorking = finder.FindFile("*.*");


while (bWorking)


{


bWorking = finder.FindNextFile();


cout %26lt;%26lt; (LPCTSTR) finder.GetFileName() %26lt;%26lt; endl;


}
Reply:Ugh...Truthfully, I'd recommend that you program Windows with the Windows API instead of using the stupid Microsoft MFC or Borland VCL frameworks because they both produce incredibly bloated, slow code. They also don't teach you how to really program the operating system since they are bloated, slow wrappers which EVENTUALLY calls the Windows API functions. Anyways...





The 1st thing that comes to mind is the size of your array. Normally, you would have to write code so that the allocated memory block or array for the file names is large enough for a good number of file names (this can waste memory), or you have to write code that will dynamically allocate another block of memory when your 1st buffer gets full. Something to keep in mind...





As far as getting the file names, do something like this:


1) Call CFileFind::FindNextFile(). Set a flag if it returns 0 (last file in directory).


http://msdn2.microsoft.com/en-us/library...





2) Call CFileFind::GetFileName().


http://msdn2.microsoft.com/en-us/library...





3) In a loop, read the file name and copy it to array/memory block if necessary.





4) If the flag wasn't set, go back to step 1.


What is the max array size of Array in C?

ie int array[MAX]... What is the maximum value i can assign to MAX ?

What is the max array size of Array in C?
http://www.thescripts.com/forum/thread21...





You can determine a guaranteed minimum if you know sizeof int. The actual limit depends on the implementation.
Reply:32,768 Usually- depends on the compiler you are using.
Reply:some around 35000, depends on the compiler you are using.

flower seeds

Program to find the reverse of each value of array elements in c-language?

program to find the reverse of each value of array elements in c-language

Program to find the reverse of each value of array elements in c-language?
I'm not sure what you mean by 'reverse'.





Generally with an array you can use a for loop to iterate through it.


Using C++ what is the easiest way to write a recursive function to sort an array in ascending order?

I just googled for it and there's a recursive merge sort here.





void mergeSort(int numbers[], int temp[], int array_size)


{


m_sort(numbers, temp, 0, array_size - 1);


}








void m_sort(int numbers[], int temp[], int left, int right)


{


int mid;





if (right %26gt; left)


{


mid = (right + left) / 2;


m_sort(numbers, temp, left, mid);


m_sort(numbers, temp, mid+1, right);





merge(numbers, temp, left, mid+1, right);


}


}





void merge(int numbers[], int temp[], int left, int mid, int right)


{


int i, left_end, num_elements, tmp_pos;





left_end = mid - 1;


tmp_pos = left;


num_elements = right - left + 1;





while ((left %26lt;= left_end) %26amp;%26amp; (mid %26lt;= right))


{


if (numbers[left] %26lt;= numbers[mid])


{


temp[tmp_pos] = numbers[left];


tmp_pos = tmp_pos + 1;


left = left +1;


}


else


{


temp[tmp_pos] = numbers[mid];


tmp_pos = tmp_pos + 1;


mid = mid + 1;


}


}





while (left %26lt;= left_end)


{


temp[tmp_pos] = numbers[left];


left = left + 1;


tmp_pos = tmp_pos + 1;


}


while (mid %26lt;= right)


{


temp[tmp_pos] = numbers[mid];


mid = mid + 1;


tmp_pos = tmp_pos + 1;


}





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


{


numbers[right] = temp[right];


right = right - 1;


}


}

Using C++ what is the easiest way to write a recursive function to sort an array in ascending order?
1+1=2 Gitt it!!!???


How can use class or structure and dynamic arrays for following problem and how to sort the aggregrate marks w

with their names as well ( not only the marks also with names in acsending order)?





there can be minimum of 1 student or maximum 40 students ina class.it is mandatory for all students to take 4 subjacts every semester namely mathematics, science,history and english for the final exam students can get marks between 0 and 100.


a c++ program to accept number of students in the cladss, all student's names and final exam marks foe each subject.Print the names of students,mark foreach subject,and aggregate in acsending order of the aggregrate marksfor the final exam.

How can use class or structure and dynamic arrays for following problem and how to sort the aggregrate marks w
If you have access to STL, you could use a multi-map to store the aggregate along with the names as the key and the rest as the value. Eventually, you would print out the results in the right format. You could use a comma separation between various values in both the key and the value.


You could also store the name with the marks in a class and create such objects to a vector. A sort function on this vector should give you the required result, provided you define your operator%26lt; appropriately.


How do i put a string into an array in c language?

declare it as an array

How do i put a string into an array in c language?
create a character array and copy the string into the array?

anther

Code in c to remove duplicate elements from the soreted array?

1,2,33,4,5,3 ---%26gt; 1,2,4,5

Code in c to remove duplicate elements from the soreted array?
I too want to learn C.......


I'm keeping a watch on this question................
Reply:Have u tried anything so far? And one more thing the example u have shown does not contain duplicate elements (unless there is a typo ofcourse)
Reply:u can delete duplicates during the sorting prozedur.





There are many kind of sorting algorithmen like by bublesorting....and during the compairing in the sorting prozedure if the same value comes u can delete it :


//sample


if(A[i] == A[lauf]){


copy A withot A[i] and let them sort


}


Is it possible to make an array of structures in C?

how do declare it? how does it work?

Is it possible to make an array of structures in C?
Take a look at this,





struct day


{


char month[3];


int day;


int year;


};


void PrintIt( struct day bd );





void main(void)


{


-------%26gt; struct day Birthday[15]; %26lt;----Array of Structures





Birthday[2].month[0]=3D=92J=92;


Birthday[2].month[1]=3D=92a=92;


Birthday[2].month[2]=3D=92n=92;


Birthday[2].day=3D21;


Birthday[2].year=3D1970;





PrintIt(Birthday[2]);





}


void PrintIt( struct day bd )


{


printf (=93\nMonth %c%c%c =94, bd.month[0], bd.month[1] bd.month[2]);


printf (=93Day %d =94, bd.day );


printf (=93Year %d=94, bd.year);


}
Reply:Once you've declared a struct, you can use it like any primitive type. You can have an array of them, linked list of them, etc... Even jagged or multi-dimensional arrays are possible.
Reply:You declare an array of structures the same way you would declare an array of integers or an array of characters. Just remember to include struct when specifying the datatype:





struct MyStruct; //declaration


.


.


.


struct MyStruct arrStruct[SOME_NUM]; //array of structures


C++ Array Related?

Hi,





I have declared two arrays


double a[100][20];


double b[100][20];





Always when I try to access Array a it gives me access violation. If I comment array a b works fine.





What may be the reason. This variable I have declared in VC++ dll. I am using VC++ express edition.

C++ Array Related?
Not enough information. Are these arrays global or local variables? Do you export them? From where do you try to access them -- from within dll or from external app?..
Reply:you need declare other variables that will represent to your arrays...





your variables are


double a[100][20]


double b[100][20]





there must be another variable representing your


[100] and [20]





like:


int i


int b





and it looks like this one:


a[i][b]





and of course, you cannot access your array without data placed on your variables or particular array...





send me the code...
Reply:need to see the rest of the code particularly where you are accessing the data


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

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


The function you implement must have the following form:


void reverse_order(int array[], int n)


{


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


first one becomes the last


* * and the last one first.


*/


}


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


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


again.


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


the numbers:


2 4 5 11 23 1 4


then program will then print out:


4 1 23 11 5 4 2


__,_._,___

Need help with implementing C that takes an array of integers,%26amp; and reverses the order of items in the array?
simple in the reverse function just make another array that will copy the orignal array backwards


j=0;


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


modarray[j] = origarray[i];


j++;


}
Reply:Well now you have the reverseArray function. Does it all work now????


;-)
Reply:Use a for loop


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





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

tomato plants

C++ array help?

can anyone help me make a simple program that could just show


"record found" or "record not found" in the output by just putting any integer input.





or can anyone help me find a site that could teach me about inheritance or arrays

C++ array help?
use an if else statement.....





int main()


{


int n;





cin%26gt;%26gt;n





if (n%26gt;2)


cout%26lt;%26lt;"record found";





else


cout%26lt;%26lt;"record not found";





return 0


}
Reply:c++ array, would help you, but I would need to install a compiler





http://www.codersource.net/c++_arrays_tu...
Reply:for your first question:


no, not just anyone, it has to be someone with some knowledge in C++





for your second question:


yes probably anyone could help you find a site.


How to put in arrays into multidimensional arrays? (php)?

I have 2 arrays, $a, $b. I want to create a multidimensional array with these two arrays, as well as an index.





I've tried several things, but nothing is working - In my searches, nothing was found either. Here's my most recent attempt at a solution:





for($x=0;$x%26lt;sizeof($a);$x++)


{


$c = array(id =%26gt; $x, array( "A1" =%26gt; $a[$x],


"B1" =%26gt; $b[$x]));


}





Any help is appreciated.

How to put in arrays into multidimensional arrays? (php)?
Do you want a 2-dimensional array that contains these 2 arrays? If so, this should work:





$c = array($a, $b);





or





$c = array("A1" =%26gt; $a, "B1" =%26gt; $b);
Reply:Use objects not arrays.


How can a I create an array of points in C# that I can use to make an arc that I want????

i am building a picture of a node in a b tree. i have it all complete but now i want to be able to add individual colors to each data cell. it looks like the way to do this is by creating a region and then shading that region. now, shading the rectangles in the node is no problem. however shading the two cells on the end wich have semi circles as half of their border is where I am lost.





I see that I can create a region by using an array of points. I get the concept of this but I dont know how to generate the array of points for the arc that I want. ....can you help me?

How can a I create an array of points in C# that I can use to make an arc that I want????
Look up Graphics.FillEllipse.


Basically, fill a circle on either end of your rectangle that halfway overlaps the rectangle.


How I Can write code in C++ that will declare, initialize, and fill in an array of objects of type int. After

How I Can write code in C++ that will declare, initialize, and fill in an array of objects of type int. After your code executes, the array should look as follows.





0 2 4 6 8 1012141618

How I Can write code in C++ that will declare, initialize, and fill in an array of objects of type int. After
int myArray[10];





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


myArray[x] = 2*x;


}
Reply:Im also studying the C language!Good luck to us!
Reply:int iArray[] = new int[]{0,2 ,4, 6 ,8 ,10,12,14,16,18}


int i = 0;


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


cout%26lt;%26lt;i;
Reply:check out http://www.pscode.com for great sample codes.

petal

How to write a function (reverseDiagonal) that reverses both diagonals of a two dimensional array (in c++) ?

the original two dimensional array was





21 26 31 36


41 46 51 56


61 66 71 76


81 86 91 96





has to look like this after the function runs





96 26 31 38


41 71 66 56


61 51 46 76


36 86 91 21





if you look between the two ... you can see what is meant by the reverse diagonal part ....





i have pondered over this for a few days and all the different thigns i try fail misserably ...





can anyone help ...???





Please ....

How to write a function (reverseDiagonal) that reverses both diagonals of a two dimensional array (in c++) ?
Here is how you would walk one diagonal. The other is just an simple modification of the first walk.





for (int r =0, c = 0; r %26lt; HEIGHT/2 %26amp;%26amp; c %26lt; WIDTH/2; r++, c++){


swap( array[r][c] , array[HEIGHT - r - 1][ WIDTH - c - 1] );


}





For the second you do essentially the same thing but you would initialize it differently, invert the test for c, and decrement c instead of incrementing it.





for (int r = 0, c = WIDTH -1; r %26lt; HEIGHT/2; c %26gt; WIDTH/2; r++, c--){


swap( array[r][c], array[HEIGHT - r - 1][ WIDTH - c ];


}





You could avoid some of the math by adding two other variables that started at the opposited corner and then moved in. Your test would then be to see when their values crossed.


Here's how that would look with the first loop





for (r_0 = 0, c_0 = 0, r_1 = HEIGHT - 1, c_1 = WIDTH - 1; r_0 %26gt; r_1 %26amp;%26amp; c_0 %26gt; c_1; r_0++, c_0++, r_1--, c_1--){


swap(array[r_0][c_0], array[r_1][c_1]);


}


C#: How can I get text displayed in the console window to compare to an array?

How can I get text displayed in the console window to compare to an array? For example, I have a list displayed in the console like the one below


A 1


A 2


A 3





Now how can I get this list to compare with an array like the one below...and return something saying that it (list above) is contained in the array below


B 1


B 2


B 3





A 1


A 2


A 3





C 1


C 2


C3

C#: How can I get text displayed in the console window to compare to an array?
Just make it loop for each array you wish to display, or run functions for each sequentially.


C++programme to accept 10 elements into an array then find out a particular number?

it is a c++ programme about arrays

C++programme to accept 10 elements into an array then find out a particular number?
#include%26lt;iostream.h%26gt;


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





void main()


{


int a[10],ele,i;


clrscr();


printf("\n");


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


{


printf("Enter a[%d] - ",i);


scanf("%d",%26amp;a[i]);


}


printf("Enter number to be searched - ");


scanf("%d",%26amp;ele);


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


{


if(a[i]==ele)


break;


}


if(i%26lt;10)


printf("Number is present");


if(i==10)


printf("Element not present");


getch();


}





It will work for you...


How can i create a palindrome program in c++ by just using array?

i just really need it for my project. i don't know how to do it using array. i made it by reversing the string but my professor told me that i should use an array. thanks in advance.. :)

How can i create a palindrome program in c++ by just using array?
just givin' the code


char c[50];


int l=strlen(c);


int flag


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


{if (c[i]==c(l-i-1))


flag=1;


else flag =0;


if (flag==0)


break;}

garden sheds

Can some body help me, why i am getting error in this array c pgm?plz help me.thanks in advance.?

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


{


void print(int *arr_beg, int *arr_end);





while(arr_beg! = arr_end)


{


printf("%i",*arr);


++arr_beg;


}


}





void main()


{


int arr[] = {0,1,2,3,4,5,6,7,8,9}


print(arr,arr+9);


}

Can some body help me, why i am getting error in this array c pgm?plz help me.thanks in advance.?
1)instead of *arr you should write *arr_beg(in print line 3)


2) ; is missed in you main(first line)


3)correct the place of {} as the person above said


hope it helps
Reply:soem little problems with {}.. try this one:


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





void print(int *arr_beg, int *arr_end){


while(arr_beg! = arr_end)


{


printf("%i",*arr);


++arr_beg;


}


}





void main()


{


int arr[] = {0,1,2,3,4,5,6,7,8,9}


print(arr,arr+9);


}


Saving the enter key in array..c++??

cin.get cant do that nor can cin%26gt;%26gt;


so how do i do it??

Saving the enter key in array..c++??
cin%26gt;%26gt;"here witte the arry as you predifine"





this can save your arry.


C++ array update help?

How do you write a function that will update an array.


for example: if i have "int x[20]" as my array and when a question prompted asking "Enter new digit" then store the new digit in the array x[1] following the array x[0]. And if i want the questions to loop and keep asking me to enter new digit and store it x[2], x[3], etc respectively. How should i write a function that will keep updating the array. The digit in those particular arrays only can be use once and it can not be change.





again, how do i write a function that indicate an invalid digit or an used digit if i store a digit in a used array?





for example (not sure if its right)


while "new digit" is equal to the array digit that i first stored in, prompt a message saying the digit has been use and try again.





And another thing, how do you write a function to test if the digit in the particular array is true and if its not, prompt a message saying digit not use yet.





please help me. im stuck

C++ array update help?
Let's use your example where you have int x[20]; You can use another variable, int index = 0; to specify where it should start inserting numbers, each time you insert a number set the array value at index to the value and increment index:





const int ARRAY_SIZE = 20;


int x[ARRAY_SIZE];


int index = 0;





int newDigit;





// get the digit here





x[index++] = newDigit;


if (index == ARRAY_SIZE)


{


// tell user they can't add anything else here


}
Reply:This should do the trick.





void main()


{


int array[20];


bool bExists;





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


{


do {


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


bExists = false;


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


{


if( array[i] == array[j] )


{


bExists = true;


cerr %26lt;%26lt; "Digit already in use";


break;


}


}


} while( bExists );


}


}


How do you check if a spot in a char array has a character there or not (C++)?

I'm having problems couting a character array. It couts the list of characters, plus a bunch of junk after it. So then I need to set up a while statement...





bool notChar = false;


int count = 0;


while(notChar = false) {


cout temp[count];


count++;


if(temp[count] == ???) { notChar = true; }


}





...Any ideas?

How do you check if a spot in a char array has a character there or not (C++)?
char* or char[ ] types typically use a char value of 0 to mark the end of the string.





however, "cout" will stop at this 0 automatically, so you obviously do not have a 0 at the end of the string.





the best bet would be to not use a char* or char[ ] type at all, but use a STL::string type. research the C++ standard tempalte libraries. it has a string type with everything built in.





if you must use char* or char[ ], initialize your array to all 0's and never use the final size'd spot. this is clumsy C programming though, not C++. Use the STL in C++, it prevents many bugs.
Reply:look up isalpha





something like





if (!isalpha(int(temp[count])) notChar = true;





can't recall what header file.

garden design

2 simple programs in C++. & also a basic doubt. please make it simple as i am a beginner.?

C++ : should main() b defined compulsarily?can it b inside a class? also in array c[]={1,2,3} what will be c[1]?


define a class to represent a book in a library with datamembers: book number, Book Name, Author, Publisher,Price, no. of copies, No.ofcopies issued.


member function : (i) to assign initial values (ii) issues book after checking for its availability.


(iii) to return a book. (iv) to display book information.





Define a class ELECTION with the following speciations. with a suitable main() fumction also to declare 3 objects of ELECTION type %26amp; find the winner %26amp; display the details.


private members: candidate_name, party, votes_received


public memberfumctions: enterdetails()-input data


Display()- to display winner


winner()- to return details of the winner through the object after comparing the votes received by the 3 candidates.

2 simple programs in C++. %26amp; also a basic doubt. please make it simple as i am a beginner.?
"C++ : should main() b defined compulsarily"





Not sure what you mean.





"can it b inside a class?"





Not in C++, no it must be global. You can do this though:





int main(int argc, char **argv)


{


return Program.Main(argc, argv);


}





static class Program


{


static int main(int argc, char **argv)


{


return 0;


}


}





"also in array c[]={1,2,3} what will be c[1]?"





Arrays in C are 0-based, so c[1] is the second element, in this case the value is 2.





The rest of your questions sound like homework and I'm not going to ruin your learning experience.


How do I check data from a file in c++ using dev?

I am writing a program in c++ and I would like to compare the data(words ) which are in a file to the data within an array. I would like to ask I could do it. please help me I am learning C++ and all my reseach didn't give me a satisfying result. thanks

How do I check data from a file in c++ using dev?
Consider using a stl::map or equivalent. You read in a word from the file and then check to see if the map has the word.





Also, consider joining a YahooGroup that specializes in C/C++ programming. Answers is not a good place to learn to program and you'll get the benefits of being part of a community with shared interests and goals.


Finding Biggest Value in array (C Programming)?

I have integer data in data.dat. Assume the data b[19] = {1,2,3,4,5,6,7,8,9,10,9,8,7,6,5,4,3,2,1}... Then I write the program to read the data from the file. Success! but, I can't find the biggest value. This is the part of finding the biggest value:





a=0 /*init value of a = 0 so it can check the value below*/


for(i=0;i%26lt;19;i++) /*20 data in the array of b*/


{


if(a%26gt;b[i]){ /*check the condition*/


printf("This is the biggest value: %d\n",a)


}


a = b[i]; /*store the current value of b to a so it can check in the next loop*/


}





but i get back these result:





This is the biggest value: 10


This is the biggest value: 9


This is the biggest value: 8


This is the biggest value: 7


This is the biggest value: 6


This is the biggest value: 5


This is the biggest value: 4


This is the biggest value: 3


This is the biggest value: 2





I know the problem: it only check the value before not all.





Please help me.....

Finding Biggest Value in array (C Programming)?
oSourceM has put it wrong.. SOrry mate!!





but the right code wud go like this....





big = b[0];


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


{


if (big%26lt;b[i])


big=b[i];


}


printf("biggest value = %d\n",big);





the variable big contains the largest value in the array...





if the array consist n elements...





big = b[0];


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


{


if (big%26lt;b[i])


big=b[i];


}





Enjoy!! I hope you got what you needed.....
Reply:a=0; c=0; //c for the biggest value


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


{


a=b[i];


// checks if the first value from array is bigger


// than the second and etc.


if (a%26gt;b[i+1])





{c=a;}


}


printf ("print here the biggest value")





hope You will get the point.





Good luck


Can anyone hep me with this c programming question?

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


below:


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


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


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


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


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


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


which the stack grew during the operation.

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


Finding the mode of an array C++?

I have a vector that records the number of occurances based on user input, but I cannot figure out how to find the mode of that data here is my code listing the occurances and what I have so far for the mode:





cout%26lt;%26lt;"Roll"%26lt;%26lt;" "%26lt;%26lt;"Count"%26lt;%26lt;endl;


for(num = 1; num %26lt;=50;num++){


cout%26lt;%26lt;num%26lt;%26lt;" "%26lt;%26lt;Count[num]%26lt;%26lt;endl;


}





void Mode(CountType %26amp;Count, int %26amp;num, int %26amp;i)


{





int pos_mode;


int mode;


for(pos_mode = 1; pos_mode %26lt;=50;pos_mode++){


if (Count[pos_mode] %26gt; Count[num]){


mode = pos_mode;





}

















}


cout%26lt;%26lt;"The mode is: "%26lt;%26lt;mode;


}

Finding the mode of an array C++?
Try this:





I'm assuming CountType to be integer.





void Mode(CountType* Count)


{


//first sort the count array yourself





int n = 0;


int count = 0;


int max = 0;


int mode = 0;





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


{





if(n != Count[i])


{


n = Count[i];


count = 1;


}


else


{


count++;


}





if(count %26gt; max)


{


max = count;


mode = n;


}





}





cout%26lt;%26lt;"Mode: "%26lt;%26lt;mode%26lt;%26lt;endl;


}








Don't forget to sort the array first, it is important.


There are n1/2 copies of an element in the array c[1..n]. Every other element of c occurs exactly once. If the

Ok, half the question appears to be missing. But I suggest you post this in mathematics next time, based on how your question starts it looks like set theory to me.


Thursday, July 30, 2009

In C# how do I search an array to see if it already contains a particular number?

The user enters a number. I have have to search through the array to see if it already contains this number. If it does, then it will be disregarded so that their are only unique numbers in the array. If the number is not already in the array, it will add it to the array.





I have the array already denifined by the number that the user inputs, I just do not know how to search the array to see if that number is there or not. I was using if statements to compare the number to each element of the array, but that would get rid of both copies of the number instead of keeping one. Please help!

In C# how do I search an array to see if it already contains a particular number?
With Array.IndexOf you can easily check the existence of an element without using predicates. Use the following code as a guideline:





type[] myArray = whatever;





if (Array.IndexOf(myArray, theNumber) != -1)


{


// The number already exists in the array


}


else


{


// The number does not exist in the array


}
Reply:I don't know C#, but here's pseudocode:





boolean isInArray(int array[], int number)


{


for (x=0; x%26lt;=array.length;x++)


{


if (array[x] == number)


return true;


}


return false;


}





Then call that method in another function to put the number in or not depending on if it's true or not. You would also want to use a Vector (i'm not sure about C#'s array abilities but arrays are typically static meaning you can't add more elements after it's declared) so you can dynamically add more elements for as long as the person inputs numbers. Vectors work roughly the same way as arrays, but the number of elements can be dynamically changed. That and the vectors will have their own methods (at least they do in Java which C# imitates).

credit cards

Which of the following statements about Java arrays and ArrayLists are true?

I. Arrays are similar to objects, but technically are not true objects.


II. Once an ArrayList’s size is set, it cannot be changed without reconstructing it.


III. Arrays can directly hold primitive types as well as objects.


IV. Array indexing begins at 0, but ArrayList indexing begins at 1.





A. I and III only


B. I, II and III only


C. II and III only


D. I, II and IV only


E. I, II, III and IV

Which of the following statements about Java arrays and ArrayLists are true?
You need to be able to look up the documentation in Sun's JavaDoc API documentation for ArrayList which is a class that comes with Java Standard Edition (Java SE).





http://java.sun.com/j2se/1.5.0/docs/api/





Arrays are part of the Java language. All arrays are objects. Array elements may either be objects or primitives.





There are really only two types of concrete data in Java, objects and primitives.





If you have any more questions, I can help you if you send an email to me.
Reply:A. l and lll only


How do I make a C program?

How do I make a C program that solves a system of three linear equations with three unknowns using determinant of the third order (3*3). Be guided by the following:


1. Use two dimensional arrays in programs.


2. Prompt the user for the input of numerical coefficients and constants of the three equations.


3. The program must contain at least three functions (not including main):


a. A function that computes;


b. A function that displays the matrices; and


c. A function that temporarily stores and replaces values in the matrices ;


4. The program should display the four matrices and the values of the three unknowns should be displayed.

How do I make a C program?
You've got all the instructions in your question. You do know C language, right? So grab a pen and paper and start with your first sentence and then keep asking English language questions until you have all the sub requirements covered. By this point C language will have started to creep into your writing and you will soon have a programme ready to be put into the computer.





Carry on

brandon flowers

Converting string to character array (C++)?

How do I convert the string held in the variable TEXT to a character array called TEXT2[30].

Converting string to character array (C++)?
strcpy( TEXT2, TEXT.c_str() );





if TEXT is a static string, or...





strcpy( TEXT2, TEXT-%26gt;c_str() );





if TEXT is a pointer to a string





Be sure that the length of TEXT is less than 30 chars, also, else results will be...unusual.


What could I do to copy a string into a multiple array string in c++?

I am writing a program in c++, I would like to copy a srting into a multiple array string. i have used the srtcpy() function but Iam getting an error message telling me that :


-invalid conversion from 'char' to 'char*'


-initializing argument 1 of 'char*' strcpy(char*, const char*).








//this is what I get as message. and here is my program:


# include%26lt;iostream%26gt;


#include%26lt;string%26gt;


using namespace std;


int main()


{int namsize;


char names[20][20], newname[18] ;


cout%26lt;%26lt;"what is the size of your name";


cin%26gt;%26gt;namsize;


cout%26lt;%26lt;" please enter the name";


cin.getline(newname,namsize);


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


strcpy(names[i][1],newname[i]);


system("pause");


return 0;


}


please could you help me to solve this problem? thanks

What could I do to copy a string into a multiple array string in c++?
do strcpy(names[i],newname) instead of


strcpy(names[i][1],newname[i])


and the for loop should go from 0 to 19.





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


strcpy(names[i],newname);








( i am assuming you want to create 20 copies of the same name in the array)


strcpy has the loop built into it. you just need to pass the pointer to the char array to it ,terminated by null of course.(If u din get the last part, its ok)
Reply:this is a syntax error! you need spaces between char names [20] [20]..that should work!
Reply:/*


just do copy of one string onto the next


eg. shown below is a c++ code


*/


# include%26lt;iostream%26gt;


#include%26lt;string%26gt;


using namespace std;





int main()


{





int namsize;





string names="fanda", newname ;


newname=names;





cout %26lt;%26lt;"\nnames: "%26lt;%26lt;names;


cout%26lt;%26lt;"\nnewname: "%26lt;%26lt;newname;


cout%26lt;%26lt;endl;





system("pause");


return 0;


}
Reply:You are using C++. Seriously consider using std::vector and std::string. Then you don't have to ask really odd questions like "what is the size of your name".





Also consider joining a YahooGroup for C/C++ programming instead of using Yahoo Answers for questions like this. You'll learn a LOT more that way by being part of a community who shares the same interests and goals.


Programming an array c++?

write a program that reads in an array of type int. your program determines how many enteries are used. the output is to be a two - column list. the first column is a list of the numbers and the second is the count of times it occurrs. list should be sorted largest to smallest in the first column.

Programming an array c++?
Good luck doing your own homework!!


In C++, if i have 2 lines of integers separated by spaces from a source file, how do i read them into 2 arrays

for example:


0 2 6 7 8 2 5 4 7 5 8 0 9 2 6 4 8 3 5 6 7 8 3 4 5 8 1 2 3 0


0 0 0 0 0 8 9 3 2 4 6 9 1 2 4 6 5 9 8 7 5 6 9 1 9 8 7 4 6 5

In C++, if i have 2 lines of integers separated by spaces from a source file, how do i read them into 2 arrays
are they guaranteed to only be one digit? If so, you could use getc - get character. Otherwise, you could use gets - get string and use strtkn() - string token and break up the string based on spaces, or you could walk through the string yourself.

video cards

Can someone explain arrays easier then this?

i am learning Arrays in C++ but I don't really know what it means.PLease help me on arrays.


This is the program i am working on:





#include %26lt;iostream%26gt;





using namespace std;





int main(){





int myArray[3];





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


cin %26gt;%26gt; myArray[0];





cout %26lt;%26lt; "Enter a second number: ";


cin %26gt;%26gt; myArray[1];





myArray[2] = myArray[0]+myArray[1];





cout %26lt;%26lt; "The sum is: " %26lt;%26lt; myArray[2];





system("pause");





}.

Can someone explain arrays easier then this?
I think learning by example is the easiest.





int myArray[3] means you have declare an array call: myArray and the data type is integer and total capacity of it is 3.





It is just like you declare a normal variable, just that array simplify your programming.





You could declare the 3 integer variable to store the values instead of an array but practically it is too much work and hard to maintain.





So, an array is an easy way for you to store related data using the same variable array name.





Example:





int myBankAccount1, myBankAccount2, myBankAccount3;





as compare to: int myBankAccount[3];





Now let say you need to initialize each bank account to start with 0:





so in the coding:





myBankAccount1 = 0;


myBankAccount2 = 0;


myBankAccount3 = 0;





and in array case:





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


myBankAccount[i] = 0;








Now imagine you are dealing with 10,000 bank accounts. Then you will realise you have to use Array to handle it better than just declare 10,000 variables.
Reply:Here's a page with some basic explanations -





http://www.codersource.net/c++_arrays_tu...





Joyce


http://www.DesignByJoyce.com/
Reply:Arrays act as a container for values of similar data types (actually the addresses of the values) Think of an array as a box of index cards each numbered from front to back. Each card can hold only one value but the box keeps all these similar values in one place where you can find or use those values.


How to initialise a 2D array in C++?

Hello,





How do I initialise a global 2D arary in C++?





First, I declared the 2D array outside of the main function.


int data[32][5];





Then in the main function, I initialized the array:





data[32][5] = {{0,0,0,0,0},


{0,0,0,0,1},{0,0,0,1,0},{0,0,0,1,1},{0...


......................................... integers here)..........


{1,1,1,1,1}};





The above is what I typed into visual c++ 2005. After the comma of every 5th bracket, I pressed 'Enter' to go to a new line.





However, when I compiled, there were syntax errors saying that there are missing ; before '{' or '}' .





What is the syntax error?

How to initialise a 2D array in C++?
is your declaration is correct


it should be defined as:





public int data[][];


public int main()


{


data[32][5]={{.......}{.......}{.........


}


Help! Print offsets for elements of an array! For C Programming!?

int main(void)


{


int array[10] = { 101, 102, 103, 104, 105, 106, 107, 108, 109, 110};


int *ptr = %26amp;array[0];


int i;





printf("\nArray @ %p\n\n", ptr);





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


printf( "Array[%d] @ %p = %d\n", i, %26amp;array[i], *ptr);


}


--------------------------------------...





thats what i have but when i debug it, each element in the array comes out to be 101 (instead of 101, 102...110).





I have this much, what am i doing wrong?





Also how do i print each adress's offset???





This is C, not C++

Help! Print offsets for elements of an array! For C Programming!?
You aren't incrementing your pointer...





int main(void) {


intarray[10] = { 101, 102, 103, 104, 105, 106, 107, 108, 109, 110};


int *ptr = %26amp;array[0];


int i;





printf("\nArray @ %p\n\n", ptr);





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


printf( "Array[%d] @ %p = %d\n", i, %26amp;array[i], *ptr);


ptr++;


}





return 0;


}
Reply:*ptr is always going to be 101. If you want to get the offset from the beginning of the array, you could subtract ptr from the element position %26amp;array[i] and get the offset.


Can anyone tell me a how get summing of the elements of array in C programming?

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


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


void main()


int i,n;


float a[50],sum=0;


clrscr();


printf("enter No. of elements in the array);


scanf("%d",%26amp;n);


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


scanf("%f",%26amp;a[i]);


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


sum=sum+a[i];


printf("Sum of no.s in the array is %f",sum);


getch();


}

Can anyone tell me a how get summing of the elements of array in C programming?
a loop





sum = 0;


for( i = 0; i %26lt; "size of array"; i++) sum += array[i];
Reply:How about a for loop?





sum = 0;


for( i = 0; i %26lt; 100; i++) sum += array[i];
Reply:if you want to add all elements of an array than u wud hav to take an array and using for loop enter the elements. after that processing each element u wud hav to add that.





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


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


void main()


{


int arr[12],i,sum=0;


printf("Enter the elements\n");


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


{


scanf("%d",%26amp;arr[i]);


sum=sum+arr[i];


}


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


printf("%d",arr[i]);


}

sd cards