I have an assignment due shortly and need some help.
Here is the assignment information :
For this assignment, you’ll need to:
1. Develop a short C++ program.
2. Compile it.
3. Run it & debug if necessary.
4. Submit the working C++ source code file in D2L as Programming Assignment 1.
The “Writing Programs” document under Content in D2L has information about writing your programs for this course. If you want to work on your own computer, you need to install an application, like CodeBlocks to write your programs with. There are tutorials about installing CodeBlocks and using it to complete this assignment in D2L under Content/Tutorials.
Here’s your assignment:
1. Read from 0 to 150 integers from a file named “Temps.txt” and place the contents into an array of integers.
2. Your program must now display the numbers 5 per line on the monitor.
3. Prompt the user for a temperature they would like to search for.
4. Use linear search to find the temperature in the array.
5. Display a message stating at which index the value was found or that it was not found.
6. Sort the contents of the array in ascending order.
7. Display the sorted array with 5 numbers per line.
8. Compute the average temperature and display the results on the monitory.
9. Submit your working C++ file as Programming Assignment 1 in D2L. Refer to the Student D2L 101 course or Student Guides on the Course Home page in D2L for more information on how to do this.
Additional Requirements:
• A named constant MAXSIZE must be used in the program
• Make sure and check for and handle an empty data file
• The file may have more than 150 values, so you must check for this condition
• Include all needed error checking
• Use functions appropriately
• Include required comments/documentation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
// preprocessor directives
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
// user-defined constants
// user-define string data type - room for NULL character
int main()
{
const int MAXSIZE = 150;
int numbers[MAXSIZE];
int count = 0;
ifstream inputFile;
inputFile.open("Temps.txt");
while (count < MAXSIZE && inputFile >> numbers[count])
{
count++;
}
inputFile.close();
for (int index = 0; index < count; index++)
{
cout << numbers(index) << " ";
}
return 0;
}
|