Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[C++ Programming Question] I tried to find my middle value in my array. So, I tried to use sizeof(array) / sizeof(array[0]) but it is not

[C++ Programming Question]

I tried to find my middle value in my array. So, I tried to use

sizeof(array) / sizeof(array[0])

but it is not working as well

Could you help me to fix it?

My middle value function located at void middleValue(int array[]) << here

Here is my code

#include #include // Input/Output with Files , ifstream(read from file) + ofstream(write on file) using namespace std; class Random { private: public: void allValues(int array[]) { cout << "Show all values" << endl; for(int i =0; i < 1000; i++) { cout << array[i] << endl; } } void sumValues(int array[]) { cout << "Output the sum of all values" << endl; int sum = 0; for(int i = 0; i < 1000; i++) { sum += array[i]; } cout << sum < highValue) { highValue = array[i]; } } cout << highValue < array[j+1]) { temp=array[j]; array[j]=array[j+1]; array[j+1]=temp; } } } cout << "Output all values thar sorted in Bubble sort" << endl; for(int k = 0; k < 1000; k++) { cout << array[k] << endl; } } void linearSearch(int array[]) { int searchValue, flag; cout << "Input what values do you want to find: " << endl; cin >> searchValue; flag = 0; for(int i = 0; i < 1000; i ++) { if(array[i] == searchValue) { cout << searchValue << "is located at" << i+1 << endl; flag = 1; //return; } } if(!flag) { cout << searchValue << "is not exsited in array" << endl; } } }; int main() { int ranNum; //random number const int arraySize = 1000; // Fixed array size int array[arraySize]; int choice; // Used in Menu Part ofstream outfile; //Write on File outfile.open("randomfile"); srand(time(0)); // producing a series of pseudo-random integers /**If we generate a sequence of random number with rand() function, it will create the same sequence again and again every time program runs */ cout << "Writing data to file..." << endl; for (int i = 0; i < 1000; i++) { ranNum = (rand() % 1000) + 1; //cout << ranNum << " "; outfile << ranNum << " "; } outfile.close(); ifstream file; file.open("randomfile"); file.seekg(0, ios::beg); cout << "Reading data from file..." << endl; for (int i = 0; i < 1000; i++) { file >> array[i]; // Push into my array } file.close(); cout << "===========================================================" << " "; Random rd; // random rd is not working wtf? /** * Here while passing the array as parameter, we just need to send * the name of the array without its size */ do { cout << "1.Show All Values" << endl; cout << "2.Show Sum of All Values" << endl; cout << "3.Show All Odd Values" << endl; cout << "4.Show All Even Values" << endl; cout << "5.Show Middle Value" << endl; cout << "6.Show First Element value" << endl; cout << "7.Show Last Element Value" << endl; cout << "8.Show Highest Value" << endl; cout << "9.Show Lowest Value" << endl; cout << "10.Sorting array by using bubble sort" << endl; cout << "11.Finding value by using Linear Search" << endl; cout << "12.Terminate Program" << endl; cout << "Input Your Choice: " << endl; cin >> choice; switch(choice) { case 1: rd.allValues(array); break; case 2: rd.sumValues(array); break; case 3: rd.oddValue(array); break; case 4: rd.evenValue(array); break; case 5: rd.middleValue(array); break; case 6: rd.firstValue(array); break; case 7: rd.lastValue(array); break; case 8: rd.highestValue(array); break; case 9: rd.lowestValue(array); break; case 10: rd.sortValue(array); break; case 11: rd.linearSearch(array); break; case 12: cout << "Terminate Program" << endl; } }while(choice != 12); return 0; } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions

Question

3. Write a policy statement to address these issues.

Answered: 1 week ago