C++ :: Read Data From A File Then Store / Search And Display Using Classes And Arrays
Apr 12, 2013
A company uses two text files: one to store employees' details and another to log their sign in/out time.
The details file - called details.txt" has the following format: ID, Name, Date of Birth, SSN, Department, Position - separated by spaces.
An extract from the file looks like this:
10 alice 4/23/1972 123-45-6789 support assistant
3 bob 6/7/1980 111-12-1134 logistics manager
1 carol 10/2/1963 987-123-1143 admin ceo
2 dave 10/3/1974 902-22-8914 admin cfo
17 erin 6/13/1991 126-83-1942 technology supervisor
15 frank 2/22/1987 303-12-1122 logistics assistant
"timelog.txt" contains daily logs of when employees arrive and leave. It has the following format: ID, Date, Arrival Time, Departure Time - separated by spaces. An extract from the file looks like this:
I have to write a program that searches for specific records using some search parameter, and displays them. Ok first i have to read the data from the files and store them. this is what i have so far....
#include <iostream> //Accesses libaries for console input and output
#include <fstream> //Needed to access the fstream object to read files
#include <string> //Needed to access the string class
#include <cstdlib>
[Code] ....
I know my class and array code is totally wrong i dont know how to store the data for the info is in integer and string form... do i use strings, arrays?
Read the input file of data ( employees.txt) and store them in arrays. This company can have up to 55 employees [b]i need to do these following in these program:
Write a function to read the input file and store the data in arrays. Write a function to calculate regular pay. Write a function to calculate overtime pay Write a function to calculate gross pay. Write a function to bubble sort the employees into order by last name, first name. Write any swap functions that are needed. Write a function to write output to a file called payroll.txt
Format of file is EMPLOYEES.TXT[/b]
Hours Pay Rate Employee Number First Name Last name 40.0 10.00 A1234 Jane Adams 50.0 10.00 L8765 Mary Lincoln 25.5 10.85 W7654 Martha Washington 52.0 15.75 A9876 John Adams 45.0 25.00 W1235 George Washington 40.25 55.00 L9087 Abraham Lincoln 30.0 9.75 T9876 William Tell 42.5 12.50 M7654 Missy Muffett 30.0 10.00 P8765 Peter Piper
how I can read information from a text file into an array so afterwards I can display the array and it will show the contents of the text file?
the information inside my text files consist of names and numbers like so: "Collins,Bills 80" should I separate the numbers and names into two separate text files one for names and one for numbers?
How would i write a functor for this code. The code is written to read data from a file and store in a multimap.
The data has numbered lines. E.g.: 1 This is a string 2 This is a string too
So the aim is to store each word in the line with the number and then to enter a word to search for the line numbers it appears on. I do not know how to go about and write a functor
#include<iostream> #include<sstream> #include<fstream> #include<cstdlib> #include<map> using namespace std; int main() { multimap<int, string>myMap;
I am currently working on a problem where I read a file into a 2D array, and display data. If you saw my code earlier, this is the same problem, but I am now further along.
The file (90 characters) looks like this: S R R S R R R R S S ....
The "R" resembles rainy days, the "S" resembles sunny days, and the "C" resembles cloudy days. There are 90 characters in the file. The first 30 are for the month of June, the next 30 are for the month of July, and the last 30 are for the month of August. The 31st day of the months are NOT included.
I read the data into a 3 x 30 array, where the row indicates the month (0 = June, 1 = July, 2 = August) and the column indicates the number of days in each month.
Now I need to create a function that creates a report and displays, for each month AND for the whole 3 month period: 1) The number of rainy days 2) The number of cloudy days 3) The number of sunny days 4) Which of the 3 months had the largest number of rainy days
Here is my code so far:
#include <iostream> #include <fstream> #include <string> using namespace std; const int MONTHS = 3;//Number of months
[Code] .....
There are no compiling errors, but I am not getting the data I want. My rCount and cCount variables end up being 0, and my sCount variable is 90.
start writing a program to store some information and then have it recalled. I would like to be able to store a list of the video games I own because i thought it would be fun :)
Trying to do a homework assignment for a class and how to read a file into an array. I've looked in our book and on several other forums and cant seem to find any examples of this. Below is the assignment I'm working on. I have a shell of the program that I can get to run, but getting a .txt file to read into an array is something I cant seem to figure out how to do.
Write a program to read N data items into two arrays, X and Y, of size 20. Store the product of the corresponding pairs of elements of X and Y in a third array Z, also of size 20. Print a three column table that displays the arrays X, Y, and Z. Then compute and print the square root of the sum of the items in array Z. Compute and print the average of the values in array Z and print all values above the average of array Z. Determine the smallest value in each array using only one function.
Use the two data files named DATAX.TXT and DATAY.TXT.
You must use functions for the reading of the data, computing the average, printing the three column table and printing the values above average.
i've been trying to figure out to search for a word in a text file and then display everything in the same row as the word found int ie this is whats in the file
john doe 3/21/1920 tech support review team 45,000
so user wants to find tech..and everything associated with it.
so program search for tech, when it does it then display the whole row.
john doe 3/21/1920 tech support review team 45,000
I can figure out how to search for a word, but no clue how to get it to then print out the row. This is all I can figure out to do.
ifstream FileSearch; FileSearch.open("employee"); if(FileSearch.is_open()) {string letters;// search word would be store here string row; ??stores entire row as string while(1)
#include <iostream> #include <fstream> using namespace std; int main() { int r = 0; int c = 0; int num[17][15] = { 0 }; [Code] ...
// Here is my code for displaying the data from the text file into a 2d array and height next to it, but I am not able to diaplay the height from 60 to 76 next to the row of the 2d array, as shown in the table below. This is my program:
Recently the health authorities have listed a new way to calculate the body mass index (BMI) of an individual. Values of 20 – 24 are classified as normal, 25-29 as overweight, and 30-34 as heavy.
The table below is a portion of a typical BMI table.
So I have to read from a file, and store the information in separate variables. My problem is that for some of the information I need multiple words, and for others I don't, so I cant simply store 1 word into a variable and store the next in another in so on. To demonstrate what I mean let me give an example.
Dog Cat Blue Bird Snake White Horse
I am able to store "Dog","Cat","Blue","Bird"...etc in variables but I don't know how to make it so I can store "Dog" in one variable, "Cat" in a second variable. and "Blue Bird" in a third variable. "Snake" would be the 4th and "White Horse" would be the fifth. How can I read a file and manipulate the pointer to grab what I need?
Im trying to read and store several students information so that i can have an options menu where i can enter a student number and the program prints all the information stored about that student. The way i have it set up now, doesn't work for this because all info is reinitialized to stud1. Is there another way to store this info other than defining stud1, stud2,.....,stud200?
How data actually store in the File. Like do data store just in one line or at different places for example in array data store in adjacent memory block while in struct data store at different memory block.?
I can't get my code to compile, i need to read in lines from a file and store them in variables. Then i have to construct instances of my class for how many lines there are in the file and take those variables into them.
I'm getting this error :
"a2.cpp:40: error: cannot convert `Employee' to `Employee*' in assignment"
#include<iostream> #include<string> #include<fstream> void displayInfo(); using namespace std; class Employee{
how to read and display the content of a text file in my console application using C++. The file contains 25 lines and 3 columns. The first column is "Rank" (numerical values from 1 to 25) the second column is "Name" (25 teams name) and the third column "value" has the amount of point each team is worth. Looking for code for reading and displaying all this information ....
Write a program that reads from total.dat file and displays its contents to the console. The program should allow the user to add new entries to the file.
So far this is what I've got and I'm not sure if I even started right.
#include <iostream> #include <fstream> using namespace std; int main () { ifstream dataIn; ofstream dataOut; dataIn.open("total.dat"); cout << dataIn; return 0; }
I'm supposed to read a text file and display it in the output. I have it down except my formatting. I just cannot get it to just skip one line rather than multiple. I know why though because my char has a max of 11 and if I put a character lets say mango, it is going to fill in the rest with white spaces. It's supposed to display like this:
Mango Strawberry Grapes
But instead I get something like this
Mango
Melon
Grapes
I am using isspace but it's not working.
//source code
#include <iostream> #include <iomanip> #include <cstdlib> #include <cmath> #include <fstream> using namespace std; class CFile
How is it possible to store the related data of a program C++ into an external file (like as .txt) and retrieve it?
I want to write c++ program that can contain data members " id and phone"
like as Code: class profile { private: int id,phone; public: void retriever() { cout<<"Enter your ID: "; cin>>id; cout<<"Your Phone number is "<< phone; }; }
avoiding formats in above class, purpose is to store data already in txt file with different id and phone numbers and it is to be retrieved by matching id number to txt file and viewing its related phone number.
The program is supposed to read a formatted .txt file and store the data into their respective [Class] Members. It will then output the data collected onto screen.I overloaded ifstream and istream. When I call for file>>ptr[i] to read the data, something goes wrong. It prompts me to input data (which is in istream overload).The Data in .txt file is as follows;