Efficient C++ Data Read/Write Program for Employee Pay Increase Calculation

  • Comp Sci
  • Thread starter jimmyv12
  • Start date
  • Tags
    C++ Data
In summary, The conversation is about a program that copies three people's information and calculates their new pay after a pay increase. The program has experienced an issue where person two's information is incorrect and person three's information is a copy of person two. The person is asking if there is anything they can add to fix this issue and later figures out that the issue was caused by a typo in the input file.
  • #1
jimmyv12
10
0
Alright, so basicly I'm writing a program that will copy three people's first and last name, current pay, and pay increase %. Then, write it to a file that gives their name, and new pay after the increase has been applied to the current pay. When I launch the program, then open the output file to see if it worked, person one works fine, then, for person two, it gives the name, and pay increase, but with person one's %. Then person three is just a copy of person two.

Is there anything I need to add in between each person's code to help fix this? I would show my code but I have no idea how to copy it from pico(I'm using telnet with my school). So if anyone would like to see the code and knows how to do that, I'll happily show the code.
 
Physics news on Phys.org
  • #2
okay nevermind I figured it out, I just had to re-write the input file because I guess I had a typo
 
  • #3


Hi there,

I understand the importance of efficient data processing and analysis. It seems like you have encountered a problem with your program where the pay increase % for person two and three is not being properly calculated and displayed.

To fix this issue, I would suggest adding a "reset" or "clear" function in between each person's code. This will ensure that the data from the previous person is not carried over to the next person's calculations. Additionally, make sure to properly assign and update the variables for each person's data.

If you are having trouble copying your code from pico, you can try using a text editor or IDE (integrated development environment) to write and edit your code. This will also make it easier for others to read and understand your code.

I hope this helps and good luck with your program!
 

1. How do I read data from a file in C++?

To read data from a file in C++, you can use the ifstream class and its associated methods. First, you will need to open the file using the open() method, passing in the name of the file as a parameter. Then, you can use the getline() method to read each line of the file and store it in a variable. Finally, don't forget to close the file using the close() method when you're finished reading the data.

2. How can I write data to a file in C++?

To write data to a file in C++, you can use the ofstream class and its associated methods. First, you will need to open the file using the open() method, passing in the name of the file as a parameter. Then, you can use the write() method to write data to the file. Finally, don't forget to close the file using the close() method when you're finished writing the data.

3. How do I handle errors when reading or writing data in C++?

To handle errors when reading or writing data in C++, you can use try-catch blocks to catch any exceptions that may occur. You can also use the fail() method to check if there was an error while reading or writing data. Additionally, you can use the good() method to check if the file was successfully opened and is ready for reading or writing.

4. Can I read and write different types of data in the same file in C++?

Yes, you can read and write different types of data in the same file in C++. You can use the getline() method to read strings, the >> operator to read numeric values, and the write() method to write data to the file. Just make sure to specify the correct data types when reading and writing.

5. Is there a limit to the amount of data I can read or write in C++?

There is no specific limit to the amount of data you can read or write in C++. However, the amount of data you can read or write may be limited by the available memory on your computer. It is important to properly manage your memory when reading and writing large amounts of data to avoid any potential errors or crashes.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
15
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
14
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • Programming and Computer Science
Replies
22
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
2K
Back
Top