C++ :: WHILE Loop Error / In Streaming Data File (with Functions)
Nov 2, 2014
I have a working lab project with a loop error. Code posted in second post. Here's the requirements:
*
- program has to be able to handle file failure
- must loop (prefer to use a while loop here), read in the data, calculates values, etc. and then output the results.
*
The input data file includes
1. a 1 or a 0 indicating that there is a set of employee data following
2. the hourly rate of the employee
3. the humber of hours worked
4. the number of dependents
5. a 1 or a 0 indicating whether the employee is full time (1=full time).
Problem: At first I wouldn't loop back... so I moved the curly brace above the return0;
I need to write a widget that will implement some matrix functions using data from a text file. The input data will be spreadsheet like and fully determined with complete rows and columns. I need to do the following,
1. populate a data structure with the input data (double) to create matrix x 2. transpose the input data matrix x to create x' 3. multiply x * x' to create a square matrix x'x 4. take the determinant of x'x
This is pretty standard linear algebra, but not something I have done in cpp before. Implementation such as the best data types to use to store each of the three matrices, how they are sized, and what library functions may be available for the matrix functions like transpose, multiply, determinant, etc.
I will be removing each data row from the initial input to observe the effect on the determinant in case that has any effect on program design.
My function is only reading the first line of numbers even though I have the loop to keep returning to it in main(). How do I have it read from the file until it runs out of data to retrieve?
File being read
90 83 94 72 65 81
File being sent the data(Only the second average is correct, working on the first)
#include <fstream> #include <iostream> using namespace std; ifstream infile; ofstream outfile; void grades(int&,int&,int&); // Grades from the input file int myavg(int,int,int); // Calculates the Average of the 3 grades
I'm trying to pass several integers into the array idAr[10] from an input file using a for loop and then having them output on the console. The output should look like this:
#include <iostream> #include <fstream> using namespace std;
I'm new to programming and i'm trying to do a certain task. I want to use a for loop to read certain data from a txt file and print them to a console. I'm trying to read student names and their grades.
Something like 3 // 3 represents the number of students. George 97 Sarah 70 Maya 88
I program unix sokcet programming , and part of my code is ti open file from server and open it , but i surprised with this wierd error i dont have any reason for it ?
I have a FILE stream, and I want to create a function that streams a specified number of bytes (up to four bytes) and returns the value of this, as an integar.
For example, supposing that my FILE has the following data, in hex: 74 C8 02 33 F2 7B....... I then want to stream three bytes and store this as an integar. So, I want to stream "04 08 02". The data stored in the integar should then be "00 74 C8 02", because I have not streamed anything into the first byte. By converting the hex to dec, the integar should then be of the value 7653378 (if it is unsigned).
To try to achieve this, I have written the following function. I create an integar and initialise it to zero, then take each byte from the stream, and OR it with my integar. Then, I shift the integar left by 8, and read the next byte, and so on.
The problem is, when I convert "c" to "c_int", it adds on a load of 1's to the left of the "c" data. This then means that the OR comparison changes all those bits in my integar to 1.
How to solve this? I am also wondering whether there is a much more simple way of doing this, rather than having to write my own function....
Code: int StreamFileToInt(FILE *fp, int num_bytes) { char c; int c_int; int x = 0x0000; for (int i = 0; i < num_bytes; i++) {
work for a radio station as their webmaster, and we have been looking into online streaming options for the last few months for our website. Pretty much everyone charges a monthly fee for this type of service and I feel like it is something I am capable of doing myself.
At the station we have a computer dedicated to operating the music/talk. On this computer there is a program that ques all the music, ads, ect.. This would be my audio source: Either the program playing all the music, or the computer itself.
The problem I have been pondering all night is how would I access this input source? The only audio input I am familiar with accessing is .mp3 or .wav files. How can I code my program to access this audio the program is producing and stream it to people on the web?
I have a main .cpp file which contains int main(int argc, char** argv) and 2 included personal headers which correspond to their linked implementation files.
What I am trying to do is use ifstream to pass integer values from a text file into my program, have the program execute, and then output those modified integers back into the same text file. I have tested the "program" portion of my project using declared values. I know that my program does what I have intended for it to do, but I can't seem to properly inject any outside data using files.
Here's what I have (not including all of the unrelated objective code):
Main.cpp
int main(int argc, char** argv) { file File; std::string gameFile = File.findFile(); // prompts user for existing file if(gameFile.size() > 0) { // load saved game std::ifstream in; in.open(gameFile.c_str());
[Code] .....
In game.cpp, I am unsure of Player = new player; and Player = new player(data);. I have never tried doing this. This is simply my best guess of how to make this mess work properly. Hopefully I am close?
Game.h:
#ifndef _GAME_H_ #define _GAME_H_ #include "player.h" class game { std::string loadedGame;
[Code] .....
In game.h, I haven't yet tried anything like player* Player;. As stated in my comments above for game.cpp, I have no clue how to go about this.
In player.cpp, I really have no clue where to start with the issue. I'm not even exactly sure if any values are being passed to these variables. Though, I honestly haven't taken much time to problem solve. I don't want to waste a lot of time just to find out that my attempt is incorrect and/or unconventional.
player.h
#ifndef _PLAYER_H_ #define _PLAYER_H_ class player { public: player(); // default
[Code] ....
So really, my concerns are: Is my attempt mostly correct? If not, why?
I have 2 header files one contains my personType class which works independently as I created it for a previous lab and a binarySearchTree<Type> which allows you to create and do various functions with binary search tree's like inserting, searching,and deleting. Which also works independently usings numbers and strings. But when I have combined the 2 trying to make a binary tree of type personType I am running into this problem I can't seem to figure how to fix. The entirety of my code is provided for these 2 header files.
Error1error C2678: binary '==' : no operator found which takes a left-hand operand of type 'std::istream' (or there is no acceptable conversion)
So I made a library for a whole bunch of functions and when i compile it, it says"Unresolved external symbol_(Name of function here) referenced in function main.
I'm really brand new to C++ and I'm currently learning it for fun. I'm working on prototype functions, and I got an error.
I get an error saying “warning : '<' : signed/unsigned incompatibility” but I haven't defined an unsigned int anywhere. Actually, I don't even really know much about them except that they allow bytes from -127 to 127 instead of 0 to 256 for signed int's if I understood correctly...
The function itself is supposed to make a pointer go to the end of a string and add the Null Byte at the end. There's probably an already-existing way to do so, but I don't know it. Plus it is fun making this.
In the below code I'll be making comments for most lines so you may correct me if I'm not doing what I think I am. Any way, here's the code of my "my_fct.h" header file :
#include <stdio.h> //Includes basic functions necessary in C as 'scanf' or 'printf'. #include <string.h> //Includes string functions such as 'strcpy' or 'strcmp'. #include <iostream> //Not sure about what this does. int strend(char[]); /* Specifies the existence of a function 'strend' that uses a char * string as argument and that returns a value of integer type. */
The program is supposed to read in a string from the user and then output the number of each vowel that the string has. My first function is initializing the vectors, and the one that I'm having trouble with is the function used to read the string from the user and save it.
// FUNCTION PROTOTYPES GO HERE: void init_vectors(vector<char> & vowels, vector<int> & frequencies); string read_text(const string & prompt);
[Code] ....
And I'm getting the error:
freq.cpp: In function ‘std::string read_text(const std::string&)’: freq.cpp:74: error: no matching function for call to ‘getline(std::istream&, const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)’
I'm not too sure if I can't use the function getline here or if there is something wrong with the function prototype itself but I'm pretty sure there isn't an error there as it was given to me.
While trying to redo everything in c i have an error on a do while loop and i don't understand i've corrected everything else but i don't understand why the error occurs even though it says how to fix it it says error expected ) before token -line 18 part of code
Code:
int main(){ Beep (523,1000); // sound at 523 hertz for 1 000 milliseconds char cPresent; do }
[code]....
this is just extra bits i've added on to the assignment but I've worked on the c++ code for a week now i have less than a day to redo it
I am just starting out with loops and I have run into an syntax error and for the life of me I cant find out the issue. Before it has been an issue of me forgetting to close my brackets but I am pretty sure I did that this time. I am trying to have the program keep looping the main menu until the user inputs a correct number.
class Character; class Village; class Character { public: //Functions void charGen(); //Character creation
[Code] .....
According to the Friendship and Inheritance tutorial [URL] ...., that code should work, but it doesn't. I am given an error: undefined reference to questsCompleted
The purpose of this program is to unscramble the user's input. for example if the user entered 'ftooabll' the program would print 'football'. find the error that I am making....
Now, this only works for strings that are contained in the file wordlist. That being said, I would like this to repeat this search multiple times. Currently, the process is being repeated 7 times, but it only works on the first iteration. The code and sample input/output is below.
Sample input/output: (note: all data has been verified to be in the wordlist)
Enter string: 4132dcba abcd1234 Enter string: 4132dcba Enter string: 4132dcba Enter string: 4132dcba Enter string: 4132dcba Enter string: 4132dcba Enter string: 4132dcba
In a record I have IDs of type int but some may repeat. These IDs also got sales of type float. I wish to compare the IDs number of times they appear and of match found accumulate their sales and put it in another struct. However if an ID is found which is new I pass it to a function to initiate sales..but my code never reach second ID, given I am trying with two IDs.. given IDs in transFile
ID Sale
12345 870 90909 100
I enter these two in transFile and match it with masterRecord. 12345 is matched and updated likewise but 90909 is never executed or matched in checkID function..
void sync_trans_files(unsigned short int count, master masterRecord[], char transFile[]){ const short int weeklyemployee=25; //read number of records from transFile; struct trans{