Question

In: Computer Science

C programming: Assume you have the following spreadsheet as example.csv. This .csv file can have more...

C programming:

Assume you have the following spreadsheet as example.csv. This .csv file can have more than 1000 lines of data.

time latitude longitude depth mag
2020-10-19T23:28:33.400Z 61.342 -147.3997 12.3 1.6
2020-10-19T23:26:49.460Z 38.838501 -122.82684 1.54 0.57
2020-10-19T23:17:28.720Z 35.0501667 -117.6545 0.29 1.51
2020-10-19T22:47:44.770Z 38.187 -117.7385 10.8 1.5
2020-10-19T22:42:26.224Z 54.4198 -159.9943 18.7 2.9
2020-10-19T22:39:38.900Z 18.004 -66.761 14 2.87

Read the spreadsheet which is example.csv file in your new c program and then sort the above data by latitude in ascending order. Use bubble or insertion sort and time it. Please do not hard code anything, especially do not hard code .csv file.

Solutions

Expert Solution

Dear Student I understand you need help with the following program on Insertion Sort/Bubble Sort and arrange them(latitude) in ascending order.Given below is the following program in bubble sort to arrange the latitudes in ascending order.

#include <stdio.h>

void swap(int *xp, int *yp)

{

    int temp = *xp;

    *xp = *yp;

    *yp = temp;

}

//The above function basically swaps the lower value of latitude mentioned in the csv file.

// A function to implement bubble sort

void bubbleSort(int arr[], int n)

{

   int i, j;

   for (i = 0; i < n-1; i++)      

       // Last i elements are already in place   

       for (j = 0; j < n-i-1; j++)

           if (arr[j] > arr[j+1])

              swap(&arr[j], &arr[j+1]);

}

//Given Below is the function to print an array

void printArray(int arr[], int size)

{

    int i;

    for (i=0; i < size; i++)

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

    printf("\n");

}

int main()

{

    int arr[] = {61.342, 38.838501,35.0501667, 38.187, 54.4198,18.004};

    int n = sizeof(arr)/sizeof(arr[0]);

    bubbleSort(arr, n);

    printf("Sorted array: \n");

    printArray(arr, n);

    return 0;

}

Output:-

Sorted array:
18.004 35.0501667 38.187 38.838501 54.4198 61.342

This program gives the following Output Hope I resolved your problem using the following program given.I hope this will help you understand the topic better.


Related Solutions

In this programming assignment, you will write a program that reads in the CSV file (passenger-data-short.csv),...
In this programming assignment, you will write a program that reads in the CSV file (passenger-data-short.csv), which contains passenger counts for February 2019 on 200 international flights. The data set (attached below) is a modified CSV file on all International flight departing from US Airports between January and June 2019 reported by the US Department of Transportation. You write a program that give some summary statistics on this data set. Create a header file named flights.h. In this file, you...
Write a C++ function that reads a .csv file(file contains rows of string(name) and number) into...
Write a C++ function that reads a .csv file(file contains rows of string(name) and number) into a vector and loop through that vector and find the max number.
{PYTHON }You have a CSV file containing the location and population of various cities around the...
{PYTHON }You have a CSV file containing the location and population of various cities around the world. For this question you'll be given a list of cities and return the total population across all those cities. Write a function named "total_population" that takes a string then a list as parameters where the string represents the name of a CSV file containing city data in the format "CountryCode,CityName,Region,Population,Latitude,Longitude" and the second parameter is a list where each element is itself a...
{PYTHON }You have a CSV file containing the location and population of various cities around the...
{PYTHON }You have a CSV file containing the location and population of various cities around the world. For this question you'll be given a list of cities and return the total population across all those cities. Write a function named "total_population" that takes a string then a list as parameters where the string represents the name of a CSV file containing city data in the format "CountryCode,CityName,Region,Population,Latitude,Longitude" and the second parameter is a list where each element is itself a...
C++ Programming Create a C++ program program that exhibits polymorphism. This file will have three class...
C++ Programming Create a C++ program program that exhibits polymorphism. This file will have three class definitions, one base class and three derived classes. The derived classes will have an inheritance relationship (the “is a” relationship) with the base class. You will use base and derived classes. The base class will have at least one constructor, functions as necessary, and at least one data field. At least one function will be made virtual. Class members will be declared public and...
Write a C++ Program that does the following: As you can see, there is a file...
Write a C++ Program that does the following: As you can see, there is a file named "invoice1_test1.txt". You are to use this file as your input file for your program. Do the following: 1. Sort the file by last name using an array. You can use any of the sorting algorithms we have previously used in class. You may use the string data type to store text data. 2. Compute the following: a. The total balance due using the...
Using C programming I have a file that contains earthquake data that I will copy and...
Using C programming I have a file that contains earthquake data that I will copy and paste below. I want to use either bubble or insertion sort to sort the file by latitude in ascending order, then create a new file containing the sorted data. example file to sort: time,latitude,longitude,depth,mag,magType,nst,gap,dmin,rms,net 2020-10-17T17:22:03.840Z,32.877,-116.2991667,0.31,1.16,ml,21,119,0.07747,0.26,ci 2020-10-17T17:17:29.980Z,34.1611667,-116.452,2.75,0.87,ml,17,66,0.05224,0.22,ci 2020-10-17T17:03:54.460Z,33.5396667,-116.4613333,8.66,0.63,ml,18,126,0.06084,0.16,ci 2020-10-17T16:55:01.080Z,63.254,-151.5232,8,1.4,ml,,,,0.9,ak
Assume that you have a printer that can print an average file in two minutes. Every...
Assume that you have a printer that can print an average file in two minutes. Every two and a half minutes a user sends another file to the printer. Assuming both inter-arrival and service time follow the exponential distribution, in steady state condition, (a) As an average, how long does it take before a user can get their output? (10 points) (b) To speed things up you can buy two similar printers that is exactly the same as the one...
How do I write a C++ program to call a frequency table from a csv file,...
How do I write a C++ program to call a frequency table from a csv file, using vector? Data given is in a csv file. Below is part of the sample data. Student ID English Math Science 100000100 80 90 90 100000110 70 60 70 100000120 80 100 90 100000130 60 60 60 100000140 90 80 80
C Programming: Write a program that accepts 2 arguments, an input file and an output file....
C Programming: Write a program that accepts 2 arguments, an input file and an output file. The program is to store in the output file the contents of the input file in reverse. If the input file looks like this: Hello World.\n This is Line 2\n This is the end.\n then the output file should look like this: \n .dne eht si sihT\n 2 eniL si sihT\n .dlroW olleH The main program should look like this: int main(int argc, char...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT