Void deletenumberint array int ptrsize ifptrsize 0

This preview shows page 3 - 5 out of 5 pages.

//delete a number function, uses findNumber() alose. void deleteNumber(int array[], int * ptrSize) { if(*ptrSize == 0) { cerr << "Can't delete number, the array is empty" << endl; } else { int deleteIndex; int deleteValue; cout << "Enter a number you want to delete: "; cin >> deleteValue; if(!findNumber(array, ptrSize, deleteValue)) { cerr << deleteValue << ": Not found." << endl; return; } //making deleteIndex the index of where the number is found. for (int i = 0; i < *ptrSize; i++) { if(*(array + i) == deleteValue) { deleteIndex = i; } } for(int index = deleteIndex; index < *ptrSize; index++) { *(array + index) = *(array + index + 1); } *ptrSize-=1; display(array, ptrSize); } } bool findNumber(int array[], int * ptrSize, int searchValue) { for(int i = 0; i < *ptrSize; i++) { if(*(array + i) == searchValue)
Image of page 3

Subscribe to view the full document.

{ return true; } } return false; } //reads a file void readFile(string filename, int array[], int * ptrSize) { ifstream myfile (filename); if(myfile.fail()) { cerr << "Error: file not found" << endl; return; } int size; int nextInt = 0; myfile >> size; for(int i = 0; i < size; i++) { myfile >> nextInt; *(array + (*ptrSize + i)) = nextInt; } *ptrSize += size; } //sorts the array void sort(int array[], int * ptrSize) { for(int i = 0; i < *ptrSize-1; i++) { for(int j = 0; j < *ptrSize-i-1; j++) { if(*(array + j) > *(array + j+1)) { int temp = *(array + j); *(array + j) = *(array + j+1); *(array + j+1) = temp; } } } } //displays the array void display(int array[], int * ptrSize) { cout << "New array values: "; for(int i = 0; i < *ptrSize; i++) { cout << *(array + i) << " "; } cout << endl; } //search function for printing result void search(int array[], int * ptrSize) { int searchValue; cout << "Enter a number to find: ";
Image of page 4
cin >> searchValue; for(int i = 0; i < *ptrSize; i++) { if(*(array + i) == searchValue) { cout << searchValue << ": Found." << endl; return; } } cerr << searchValue << ": Not Found." << endl; return; } //clear Cin function void clearCin() { cin.clear(); cin.ignore(numeric_limits<streamsize>::max(), '\n'); }
Image of page 5
  • Spring '16
  • Kristof
  • Carriage return, HTTP 404, Link rot

{[ snackBarMessage ]}

Get FREE access by uploading your study materials

Upload your study materials now and get free access to over 25 million documents.

Upload now for FREE access Or pay now for instant access
Christopher Reinemann
"Before using Course Hero my grade was at 78%. By the end of the semester my grade was at 90%. I could not have done it without all the class material I found."
— Christopher R., University of Rhode Island '15, Course Hero Intern

Ask a question for free

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern