SOURCE CODE
#include <iostream>
#include <fstream>
using namespace std;
int main(){
fstream myFile;
myFile.open("read.txt");
double array[75];
int i = 0,n;
if( myFile.is_open() )
{
while( myFile >> array[i] )
{
i++;
}
}
cout <<" There were " << i << " values in the
file";
n=i;
cout <<" The original data in the file was:" <<
endl;
for( i = 0; i < n; i++)
{
cout << array[i] << "\t";
}
cout << endl << endl;
for( i = 0; i < n; i++)
{
for(int j = (i + 1); j < n; j++)
{
if(array[i] > array[j])
{
double temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
cout <<" The sorted data is: " <<
endl;
for( i = 0; i < n; i++)
{
std::cout << array[i] << "\t";
}
for(int count = 0; count < n; count ++){
myFile << array[count] << endl ;
}
std::cout << std::endl;
return 0;
myFile.close();
return 0;
}
OUTPUT
There were 24 values in the file The original data in the file
was:
0.076 10.886 -5.648
-12.023 -12.224 6.882
0.226 0.039 16.193
4.916 3.978 17.877
-6.045 8.966 10.351
-0.437 4.157 -9.658-9.48
3.049 9.223 27.855
-4.669 3.873
The sorted data is:
-12.224 -12.023 -9.658
-9.48 -6.045 -5.648
-4.669 -0.437 0.039
0.076 0.226 3.049
3.873 3.978 4.157
4.916 6.882 8.9669.223
10.351 10.886 16.193
17.877 27.855
SCREENSHOT
please give a up vote if u feel helpful.
Lab 8 Lab8-input.txt 0.076 10.886 5·648 12.023 12.224 6.882 0.226 0.039 16.193 4.916 3.978 17.877...
Thank you! /*Lab 8 : Practicing functions and arrays Purpose: */ #include<iostream> #include<fstream> using namespace std; int read_function(int array[], int, int); int main() { int array[300], numba; read_function(array[300]); cout << "Enter a whole number between 2-20: " << endl; cin >> numba; read_function(numba); return 0; } int read_funtion (int arr[300], int num, int Values) { int sum=0; ifstream array_file; array_file.open("Lab8.dat"); for(int i=0; i < 300; i++) { array_file >> arr[i]; cout << arr[i]; sum += i; } cout << sum;...
LAB8.DAT IS LISTED BELOW 154 -6 279 215 404 391 -166 199 -302 -469 244 0 -20 405 110 118 359 305 77 -317 -260 387 -471 -10 -332 479 213 0 -29 -440 182 -458 -429 22 -403 318 318 222 -350 160 19 473 149 300 -46 -68 325 -417 -367 -327 -109 331 303 -440 -101 27 -83 157 128 -208 -68 -485 484 -333 -394 -128 -302 -10 -161 452 420 -447 238 -231 -77 48 443 -82 483 -199 201 166 39 198 167 -322 -372 499 -329 -467 61 382 169 -310 -131 -39 482 -344 356 145 -124 -309 -72 -18 -379 90 -274 -115 83 -248 -210 117 -235 324 483 230 -156 84 -392 406 380 318 -239 94 -477 -75 -187 -339 -321 -77 -406 99 -29 196 200 139 -466 -431 -180 31 154 -92 320 218 469 31 -175 -394 111 279 -77 -409 -234 -346 -219 -60 27 -43 375 18 444 138 458 -259 176 -211 172 195 -432 -245 -276 168 344 -156 281 175 -493 102 -113 416 -499 -38 -76 -39 270 -178 285 -29 -464 -324 222 -27 -347 -159 107 -308 238 -257 417 -231 266 -311 -213 -409 76 183 47 -74 144 148 179 136 445 -291 209 -264 -381 107 -50 -41 162 270 -150 162 -84 342 333 -244 113 82 41 370 -235 -182 -381 440 146 -21 139 45 147 44 221 22 494 -281 -394 -390 -436 -95 -52 -134 264 128 272 433 473 -308 -361 196 -406 25 30 361 -15 -107 171 241 20 -152 -350 Goals: Practicing arrays and functions Create a program that will read values from a file called Lab8.dat (posted on Canvas) and store it into an array using a function other than main. The number of values in the file is less than 300 and all the values are whole numbers. The actual number of values stored in the file should be returned to the function call Your program should contain another...
C++ i want Lab#3 done can u make clear code so I could understand it. Lab#2The objective of this lab is compare the populations of various cities that lie in between Toledo and Dayton on I-75. Write a program that produces a bar illustrating the populations. The program should read the name of the city and its population from a file. Have the program continue this process until the end of file is reached. For each city, your program should...
For this c++ assignment, Overview write a program that will process two sets of numeric information. The information will be needed for later processing, so it will be stored in two arrays that will be displayed, sorted, and displayed (again). One set of numeric information will be read from a file while the other will be randomly generated. The arrays that will be used in the assignment should be declared to hold a maximum of 50 double or float elements....
This lab is to give you more experience with C++ Searching and Sorting Arrays Given a file with data for names and marks you will read them into two arrays You will then display the data, do a linear search and report if found, sort the data, do a binary search. Be sure to test for found and not found in your main program. Read Data Write a function that reads in data from a file using the prototype below....
Practical 5: Write a program that implements several sorting algorithms, and use it to demonstrate the comparative performance of the algorithms for a variety of data sets. Need Help With this Sorting Algorithm task for C++ Base Code for sorting.cpp is given. The header file is not included in this. Help would be much appreciated as I have not started on this due to personal reasons #include <cstdlib> #include <iostream> #include <getopt.h> using namespace std; long compares; // for counting...
Lab Topics • The basics of Array object Use the following Coding Guidelines • When declaring a variable, you usually want to initialize it. Remember you cannot initialize a number with a string. Remember variable names are case sensitive. Use tabs or spaces to indent code within blocks (code surrounded by braces). Use white space to make your program more readable. Use comments after the ending brace of classes, methods, and blocks to identify to which block it belongs. Problem...
Program 7 Arrays: building and sorting (100 points) Due: Friday, October 30 by 11:59 PM Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be...
In Java(using BlueJ) Purpose Purpose is to practice using file input and output, and array list of objects. Also, this lab specification tells you only what to do, you now have more responsibility to design how to do it. Problem description You are given a text file called 'Students.txt' that contains information on many students. Your program reads the file, creating many Student objects, all of which will be stored into an array list of Student objects, in the Students...
1. Your project will include the following three files: A header file: dynamicArray.h that includes a list of function prototypes as enumerated in the next section. An implementation file: dynamicArray.cpp that implements the functions declared in the header file. A test driver file: dynamicArray-main.cpp that includes the main() function so that you can test all the functions you've implemented above. 2. The header file dynamicArray.h will include the following list of functions: constructing a dynamic array of the specified size...