.Using OOP, write a C++ program that will read in a file of names. The file is called Names.txt and should be located in the current directory of your program. Read in and store the names into an array of 30 names. Sort the array using the selection sort or the bubblesort code found in your textbook. List the roster of students in ascending alphabetical order. Projects using global variables or not using a class and object will result in a grade submission of 0. The Names used for the Names.txt are: Jackie, Sam, Bill, Tom, Mary, Paul, Zev, Barb, John, Sharon, Dana, Dominic, Steven, Padro,,Katey, Kathy, Darius, Angela, Mimi,Jesse Kenny, Lynn, Hector, Brittany, Jenn, Joe, Chloe, Geena, Sylvia, Dean. I tried this solution on this question and it had a lot of errors. I checked each solution in Microsoft Visual Studio and none runs properly. They have errors even though im told they run properly. When I run these solutions, I do not see a output visible. THis project is due tomorrow.
#include <iostream>
#include <fstream>
using namespace std;
void sort(string values[], int numValues){
int i, j;
string temp;
// outer loop to travel through the all elements
for (i = 0; i < numValues - 1; i++) {
// inner loop to compare the outer loop elements
for (j = 0; j < numValues - i - 1; j++)
// if element at j< than j+1 than swap both
if (values[j].compare(values[j + 1])>0) {
// swap logic
temp = values[j];
values[j] = values[j+1];
values[j+1] = temp;
}
}
}
int main()
{
fstream inputFile;
int count;
string name;
count = 0;
string arr[30];
inputFile.open("Names.txt");
if (inputFile.fail()){
cout << "File open error....";
}
else{
while (!inputFile.eof()){
inputFile >> name;
arr[count]=name.substr(0,name.length()-1);
count++;
}
inputFile.close();
sort(arr,count);
for(int i=0;i<count;i++)
cout<<arr[i]<<endl;
}
return 0;
}
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me
.Using OOP, write a C++ program that will read in a file of names. The file...
Using c++ Write a program that reads in a list of up to 25 first names from an input file nameData.txt and allows the user to display the name data, sort it in ascending or descending order, count the number of occurrences of a given name, or exit the program. The input file consists of a single names per line with each line terminated with an end of line (i.e. using Enter key to end the line). Your program should...
C++ I need a program that will read a list of names from a data file and store them in an array. You will then sort the array by last name using a quicksort, and display the results, one name per line.Each line has a first name and a last name.The file has 40 names in it right now, but the array should be able to accommodate up to 50 names.txt***************************************************** Barbara Wright Ian Chesterton Steven Taylor Sara Kingdom Dodo...
Problem 2. Write a program that reads in the file names.txt from data\ on the flashdrive and counts all of the unique first names in the file. Find the name that occurs the most. a. Note: you will want to import the filename as args[0] to avoid hardcoding the filename. If you have the exact number of elements in your array as your data (read it in a method) returning the Array. then you can use Arrays.sort(myArray) to sort the...
The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...
==============C++ or java================Write a modularized, menu-driven program to read a file with unknown number of records.Create a class Records to store the following data: first and last name, GPA , an Id number, and an emailInput file has unknown number of records; one record per line in the following order: first and last names, GPA , an Id number, and emailAll fields in the input file are separated by a tab (‘\t’) or a blank space (up to you)No error...
Homework 1- Merge Files: 1. Design a class named MergeFiles 1 Three file names are passed as command-line arguments to MergeFiles as follows: java MergeFiles filel file2 mergedFile II. MergeFiles reads names stored in files file and file2 III. Merges the two list of names into a single list IV. Sorts that single list V. Ignores repetitions VI. Writes the sorted, free-of-repetitions list to a new file named mergedFile.txt VII. The names in all three files are stored as one...
C++ Objective: Write a program to read a pre-specified file containing salespersons' names and daily sales for some number of weeks. It will create an output file with a file name you have gotten from the user that will hold a summary of sales data. Specifications: 1. You should do a functional decomposition to identify the functions that you will use in the program. These should include reading and writing the files, tallying and showing statistics, etc. 2. The program...
Using C programming For this project, you have been tasked to read a text file with student grades and perform several operations with them. First, you must read the file, loading the student records. Each record (line) contains the student’s identification number and then four of the student’s numerical test grades. Your application should find the average of the four grades and insert them into the same array as the id number and four grades. I suggest using a 5th...
IN C++ Write a program in c++ that will read from a file the following sentence: The quick brown fox jumps over the lazy dog Each word must be read into one location in an array beginning with the first element. You must declare an array as follows: char *words [9] ; // this is an array of c- strings. HINT words[0] will contain "the" words[1] will contain "quick" write a function int length (const char *a) to determine the...
In C++ This program will read a group of positive numbers from three files ( not all necessarily the same size), and then calculate the average and median values for each file. Each file should have at least 10 scores. The program will then print all the scores in the order that they were input, showing each number and what percentage it is above or below the average for each file. Note: Finding the average doesn’t require an array. Finding...