1. Engineering
  2. Computer Science
  3. short c program please write it ive tried everything but...

Question: short c program please write it ive tried everything but...

Question details

Short C++ program. Please write it. I've tried everything but I'm getting stumpedSpecinics: 1. Yaur program shauld take a single ommand line argumant: the name af a file to read in. a. This file needs to be stored in the arme directcry as your programi. b. The file should store up t0 100 integers on their own lines, with no other text. You can use the fie named numhers.tt on Mocdle, or create your can ycu prefer c. If there is any ernor i opering the file then print the belaw statermert std::cout << Failed to open the Ne. « std: erat; 2. Create an array of integers to store at least 100 intogers 3. Write a function caled i It should take tiree arguments a sarted amay of numbers at least 100 long, the acbual number of nlled entries in that array, and a naw value to be added to that array. t shauid than inset tha new value into tha corract pat so that the aay rermains sorted. t should returrı the new size of te array. This unction can be declared the following way. int insertIntoSortedireay int nyAreayl, int nunEnteles, int nevalue) Cambria Body CSCI 2270 Data Structures Instructors: Shayon Gupta, Ashutosh Trivedi, Maciej Zagrodzki Assignment 1, January 2019 4. Back in the man function, apen the fle that was passed via the command ine and use the getline function o read the integers one by one. Sicre theee integers in a sorled aray by pessing them to tha insertintoSortedArmray function described above. . Each time a nunber is read in, print out the whole array separated by cammas. For example if the file contained the numbers 1. 6, 2, 12, and 5 in that order, it should output Testcas0 1: 12 Your Output: 1, 2, B 1,2,6,12 1, 2, 5,6, 12 antTranscribed:

Your program should take a single command line argument: the name of a file to read in

. a. This file needs to be stored in the same directory as your program. b. The file should store up to 100 integers on their own lines, with no other text. You can use the file named “numbers.txt” on Moodle, or create your own if you prefer c. If there is any error in opening the file then print the below statement std::cout << “Failed to open the file.” << std::endl;

2. Create an array of integers to store at least 100 integers.

3. Write a function called insertIntoSortedArray. It should take three arguments - a sorted array of numbers at least 100 long, the actual number of filled entries in that array, and a new value to be added to that array. It should then insert the new value into the correct spot so that the array remains sorted. It should return the new size of the array. This function can be declared the following way:

4. Back in the main function, open the file that was passed via the command line and use the getline function to read the integers one by one. Store these integers in a sorted array by passing them to the insertIntoSortedArray function described above.

5. Each time a number is read in, print out the whole array separated by commas. For example if the file contained the numbers 1, 6, 2, 12, and 5 in that order, it should output:

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution