[Solved] CSCI 2270 Homework 1 insertIntoSortedArray

$25

File Name: CSCI_2270_Homework_1__insertIntoSortedArray.zip
File Size: 405.06 KB

SKU: [Solved] CSCI 2270 Homework 1 – insertIntoSortedArray Category: Tag:
5/5 - (1 vote)

1A. Write a function called insertIntoSortedArray .

  1. It should take three arguments
    1. myArray[ ] : sorted array that should be able to hold at most 100 integers.
    2. numEntries : the number of elements inserted so far.
    3. newValue : the incoming value to be inserted into the sorted array (i.e.

myArray[]).

  1. The insertIntoSortedArray function should return a count of the elements inserted so

far (i.e. the current size of the array).This function is defined as follows:

int insertIntoSortedArray(int myArray[], int numEntries, int newValue);

31, August 2019

1 B. Write a complete program to do the following :

  1. Reading the file: Your program should take a single command line argument i.e. the

name of the file where the integers are present.

  1. This file needs to be stored in the same directory as your program.
  2. The file should store up to 100 integers on separate lines. You can use the file named txt on Moodle, or create your own if you prefer.
  3. In the main function:
    1. Create an array of integers to store at most 100 integers.
    2. Open the file that was passed via the command line
    3. If there is any error in opening the file then print the below statement std::cout << Failed to open the file. << std::endl;
    4. Use the getline function to read the integers one by one.
    5. Store these integers in a sorted array by passing them to the insertIntoSortedArray function (you can use the code from part 1A).
    6. Each time a new number is read, print out the entire array after insertion.

The Input and Output formats are shown below:

Testcase 1:

FileContents: arr.txt

1

6

2

12

5

Your Output:

1

1, 6

1, 2, 6

1, 2, 6, 12

1, 2, 5, 6, 12

31, August 2019

Problem 2

Overview: In this question, you will write a program that:

  1. Reads a .csv file with up to 100 lines and columns containing information on national parks.
  2. Stores the information in an array of structs.
  3. Write the lines where the area of the park is greater than the minimum value into the output .csv
  4. Prints the content of the entire array.

Specifics:

Create an array that holds the Park struct objects. Use the following struct declaration:

struct Park { string parkname; string state; int area;

};

2A. Write a function named addPark:

  1. The addPark function has the following signature:

// length: Number of items currently stored in the array void addPark(Park parks[], string parkname , string state, int area, int length);

  1. Instantiate a struct and store the parkname, state, area values in it.
  2. Add the struct to the parks

2B. Write a function named printList:

  1. The printList function has the following signature:

// length: Number of items in the array

void printList(const Park parks[], int length);

  1. Loop through the parks
  2. Print out each element of the parks array in the following format.

<PARKNAME> [<STATE>] area: <AREA> using the below cout statement

std::cout << park.parkname << [ << park.state << ] area: << park.area <<

std::endl;

Example, Acadia National Park [ME] area: 47390

2C. Write a complete program which includes the following:

  1. The park struct and the addPark, printList functions coded above.
  2. A main() function defined as below:
    1. Your main() should handle three command line arguments: the name of the input .csv file, the name of the output .csv file and a minimum area respectively.
    2. Input and output files need to be stored in the same directory as your program.
    3. Read from the input file, csv :
      1. Each line of the file can be read using getline
      2. Parse each line using stringstream and convert each entry into its appropriate data type. parkname should be a string, state should be a string, and area should be an integer. (Hint: Use stoi, stof functions to convert from strings to numbers)
      3. Call addPark function to update the parks
    4. Call the printList function after the array has been filled with data.
    5. Write into output .csv file:
      1. Write the <parkname>, <state>, <area> of the parks, whose

<area> is more than the minimum_area (read from command line) into the output .csv file.

  1. Make sure you close the file when you are done.

Check next page for sample input and output.

Assignment 1

31, August 2019

Sample Input and Output:

Testcase 1:

File Contents: data.csv

Acadia National Park, ME, 47390

Arches National Park, UT, 76519

Badlands National Park, SD, 242756

Big Bend National Park, TX, 801163

Biscayne National Park, FL, 172924

Your print Output:

Acadia National Park [ME] area: 47390

Arches National Park [UT] area: 76519

Badlands National Park [SD] area: 242756

Big Bend National Park [TX] area: 801163

Biscayne National Park [FL] area: 172924

Your output.csv file with minimum area 200000 should contain the following:

Badlands National Park, SD, 242756

Big Bend National Park, TX, 801163

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CSCI 2270 Homework 1 insertIntoSortedArray
$25