C++ :: Write A Program That Reads Data From A File?

Feb 26, 2013

Write a program that reads data from a file (use the attached data file). These data are a student name and 3 test scores. The program should calculate the average of the 3 test scores, and display the name, 3 test scores, and the average to the monitor.

Useful tips:
a) Include the following header files: iostream, fstream, iomanip, and string
b) The name of the data file is “datafile.txt”, you need to save the file in the same folder of the source file.
c) use the manipulators (setw, setprecision, setfill, showpoint, fixed) to format the average with 1 digits after decimal point as following.
d) Use character ‘ ’ for tab.

View 3 Replies


ADVERTISEMENT

C++ :: Write Program For Class That Reads From Input File?

Mar 7, 2013

I am trying to write a program for class that reads from an input file the month, year & total collected. I am using notepad for the input file.

This is what the notepad file looks like
-----------------------------------
March 2013 63924.62

Why does it give me random numbers in the output rather than what the notepad has?

Also, the outfile is completely blank.

#include <iostream>
#include <iomanip>
#include <fstream>

[Code].....

View 2 Replies View Related

C/C++ :: Write A Program That Reads Four Float Numbers From The Input Text File

Apr 3, 2015

I need to write a program that reads four float numbers from the input.txt file, then it prints out the greatest of the four numbers into the output.txt file. I did everything, but the numbers don't print out.

#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream inFile;
ofstream outFile;
float number1, number2, number3, number4;

[Code]...

View 2 Replies View Related

C++ :: Write Program That Reads Group Of Chars?

Nov 28, 2014

Write a program that reads a group of chars till $. Then, compute # of vowels, # of digits, # of word and # of special chars. Your program should display all required results.

So in what way should I do it? Loop, array, ...?

View 13 Replies View Related

C/C++ :: Application Which Reads Input From Server And Write To A File

May 6, 2014

Currently I'm working on a application which reads the input from the server and write to a file. Message stored in server : idle_message="维杰PC时钟" key_prompt="在按键"

Server will send a xml reply with encode type as "UTF-8". In my code I'm store in a char array. [ char * ch = "idle_message="缁存澃PC鏃堕挓" key_prompt="鍦ㄦ寜閿" msg came from server and copied from vs2005 watch point] After this I'm writing the same to a file in my desk using the API WriteFile. When i open the file in Editplus below is the content.

idle_message="维杰PC时钟" key_prompt="在按键" Again I'm trying to read the file and storing into the char array. Below is the content viewed by the watchpoint in VS2005.

idle_message="缁存澃PC鏃堕挓" key_prompt="鍦ㄦ寜閿? I'm trying to find the starting and ending chinese char and I'm converting that char to wchar_t using the API mcstowcs() for display, its coming as completely junk chars.

I can able to every place the chinese char are different. how to overcome this problem.

View 6 Replies View Related

C/C++ :: Program That Reads Data From A Text Document And Allows To Modify

Apr 30, 2015

I'm trying to make a program that reads data from a text document and allows me to modify it. I am stuck with the display() function. I can get the printf statement to display all my array values except the char AD value. When I include flight[i].AD it causes the program to crash. When I run the program to only display the AD variable I get a bunch of weird symbols. I'm not sure where the program is going wrong because it seems to be storing values properly except for the AD variable.

#include <fstream>
using namespace std;
//named constants
const int MAX=100; //maximum flights
const int SIZE=20; //maximum characters
//struct definition
struct FlightType
{
char name[SIZE];

[Code]...

View 1 Replies View Related

C/C++ :: Program That Reads A File?

Jan 21, 2015

I wrote the following program:

#include "stdafx.h"
#include "string.h"
#include "ctype.h"

[Code].....

View 1 Replies View Related

C :: Program That Reads Number Of Digits From File?

Jan 16, 2014

I've been working on a program that displays the number of digits in each line of a file, but I feel stuck. Take for example a file that contains these characters:

6347aaa9
54j
811111
6a
709

And I'm trying to display a result like this

1 //that's the number of the line 5 //the number of digits
2 2
3 6
4 1
5 3

Here's what I've written so far:

Code:
#include<stdio.h>
int main() {
char a=0;
int number_of_digits=0, linescount=0, num, number_of_digits_per_line=0;
FILE *inputFile;
if(!(inputFile=fopen("C:TestTest.txt","r")))

[Code]..

I also thought of using fgets and strlen but I am not very good with them and couldn't get the program to work correctly. It did work but it displayed all characters, letters included, not only digits.

View 2 Replies View Related

C :: Program That Reads In TXT File And Searches Through Text For Keyword?

Nov 8, 2014

I'm working on a program that reads in a .txt file and searches through the text for a keyword. If it gets a hit on the keyword, the line number where the keyword is located and the line that contains the keyword is printed out. What I have now doesn't catch every occurance of the keyword "a".

Code:

#include <stdio.h>
#include <string.h>
int main(int argc, char **argv) {

[Code]......

View 4 Replies View Related

C/C++ :: Login Program That Reads Username And Password From Text File

Feb 14, 2015

I am trying to make a simple login program that reads username and password from a text file.

In my text file I have:

name1;pass1
name2;pass2
name3;pass3
name4;pass4
name5;pass5

Everything is working okay with name1 and pass1, but if I try to log in with different credentials, for example name2 and pass2 it says "invalid details"

Here is my code:

string user, chuser;
string pass, chpass;
string los;
ifstream loginData("logindata.txt");
cout << "Please type in your username:" << endl;
getline(cin, user);

[code].....

View 5 Replies View Related

Visual C++ :: Program That Reads Numbers From A File And Calculates Average

Mar 13, 2014

[URL] .....

Here is my code and basically these are the steps. I feel like we have something good to work on but we keep getting errors.

a. Data to the program is input from a file of an unspecified length; that is, the program does not know in advance how many numbers are in the file.

b. Save the output of the program in a file.

c. Modify the function getNumber so that it reads a number from the input file (opened in the function main), outputs the number to the output file (opened in the function main), and sends
the number read to the function main. Print only 10 numbers per line.

d. Have the program find the sum and average of the numbers.

e. Modify the function printResult so that it outputs the final results to the output file (opened in the function main). Other than outputting the appropriate counts, this new definition of the function printResult should also output the sum and average of the numbers.

View 12 Replies View Related

C++ :: Program That Reads Text From A File And Outputs Each Line To The Screen - I/O Streams

Jun 15, 2013

I seem to be missing a concept or 2 here ... I am tasked with writing a program that reads text from a file and outputs each line to the screen as well as to another file PRECEDED by a line number ...

In addition, I have to Print the line number at the start of the line and right-adjusted in a field of 3 spaces ...

Follow the line number with a colon then 1 space, then the text of the line.

Another kicker, is I have to grab the data 1 character at a time and write code to ignore leading blanks on each line.

Here is what I have so far:

#include <iostream>
#include <conio.h>
#include <fstream>
#include <string>
#include <cstdlib>
#include <cctype>
using namespace std;
int main() {
char next;
int count = 0;

[Code] ....

View 7 Replies View Related

C++ :: Input Data From File / Write Data To File

Mar 8, 2013

Ben has been administering a MBTI personality test. Now he has all the responses, but the task of scoring and compiling results seems daunting. The personality test* is a series of 70 questions for which the available responses are ‘A’ and ‘B’. Based upon the answers to the 70 questions, a personality profile is determined, categorizing the degree to which the responses place the person on four scales:

Extrovert vs. Introvert (E/I)
Sensation vs. iNtuition (S/N)
Thinking vs. Feeling (T/F)
Judging vs. Perceiving (J/P).

Each of the 70 questions relates to one of the four scales, with an ‘A’ response indicating the first of the corresponding pair (E, S, T, or J) and a ‘B’ indicating the second (I, N, F, or P). For instance, an ‘A’ response on the question: At a party do you:

A. Interact with many, including strangers
B. Interact with a few, known to you indicates an Extrovert rather than an Introvert; just the opposite for a ‘B’.

For this test, each question is designed to influence one of the four scales as follows:
questions 1, 8, 15, 22, 29 … are used to determine E/I,
questions 2, 9, 16, 23, 30 … and 3, 10, 17, 24, 31 … to determine S/N,
questions 4, 11, 18, 25, 32 … and 5, 12, 19, 26, 33 … to determine T/F, and
questions 6, 13, 20, 27, 34 … and 7, 14, 21, 28, 35 … to determine J/P.
Notice these come in sequences of “every 7th” question.

The goal of the test is to determine which end of each of the four scales a person leans, and to thus classify him/her based on those leanings (e.g., as ENFJ, INTJ, etc.). Since Ben would also like an indication of how strongly the test taker fell into each of the four, the program should print the percentage of ‘A’ responses for that scale.

Input for this program should come from a file responses.txt. The first line of the file will contain a single integer, n, indicating the number of test results to follow. Each of the following n lines will contain the first name of the test taker, a single blank, his/her last name, a single blank, then the 70 responses he/she gave on the test. Although the test instructions indicate that the results are most valid when all questions are answered, sometimes respondents leave questions blank. In that case, a dash appears at the corresponding place in the list of responses.

Output for the program should be written to the file types.txt. It should include a well-formatted report listing, for each test taker, his/her name, the percentage of ‘A’ responses in each scale, and the resulting personality type. A tie within a scale should result in a dash (‘-‘) for that part of the personality type.

View 2 Replies View Related

C++ :: Write Program Where User Will Keep Entering Data Until Pressing Ctrl D

Mar 1, 2013

I'm trying to write a program where the user will keep entering data until pressing control + D. Then the it will display the mean, smallest number, and largest number.

Here are three samples of my program running.

Sample 1
Enter the price for stock 1: $ 10
Enter the price for stock 2: $ 1.555
Enter the price for stock 3: $ 3.648

[Code].....

As you can see in Sample 1, the program runs correctly. The largest number was 20 and the lowest number was 1.555. But in Sample 2, the program shows min as 15.500, where it should be showing 15.000 and Sample 3, the program shows min as 110.000 when it should be showing 55.564.

Here's the code.

#include <iostream>
#include <iomanip>
using namespace std;

[Code].....

View 5 Replies View Related

C++ :: Gather All Input Data And Write To A File

Dec 13, 2014

I'm trying to use a function to gather all inputted data and write that data to a file. I'm having trouble getting it to work.

#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>

using namespace std;

int totalExpenses(double[], double, string, int);
int totalIncome(double);

[Code] ....

View 1 Replies View Related

C :: Program To Calculate Students Grades From Input File And Write To Output File

Aug 29, 2014

One of my class assignments is to create a program that receive a .txt file containing a students name and their grades as follows:

John K. 99, 87, 57, 89, 90, 95
Amanda B. Jones 100, 88, 76, 99, 86, 92
etc..

The number of students is unknown until run time. You have to take those grades and average them weighing the first (4) at 10% a piece and the last (2) at 30% each.

Then return an output file with the students name and their letter grade A,B,C,D,F based on their computed score. In addition, on screen it needs to display the average scores for each Q1, Q2, etc. as well as the minimum and maximum for each test on the screen. I am having a hard time in assigning the scores to a variable so that they can then be computed as an average and then used to determine a letter grade. I have begun to write the code and am a bit stuck..here's what I have so far:

Code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

[Code]....

View 2 Replies View Related

C/C++ :: Program To Compute Students Grades From File And Write Them To File?

Aug 31, 2014

We have to write a program that reads an input file containing data in the form:

Martha J, 80, 90, 90, 100, 89, 99, 85
Anna Smith, 65, 72, 77, 68, 62, 70, 65
Bill Gates, 60, 54, 89, 62, 65, 60, 50
...etc...

and then use that information to determine their letter grade and write that information to a .txt file. I have been able to successfully pass that information to a function to determine their letter grade and have been able to successfully compute their letter grade. However, I can get this information to successfully post within the *computeGrade () function. Yet, I don't know how to pass this information back to the main() on a student by student basis so that I can open a new .txt file and write just their name and letter grade to it.

Another issue I'm having is when it comes to computing the averages of the class. Each score is either a quiz (there are 4), a midterm (there are 2) or a final (there is 1). I'm a little stuck on how to pass say all of the quiz 1 grades as one entity to the function averagesminmax(). Is there a way to compile each of the grades for a specific quiz or midterm as one array and pass that to the function to then do the computation. Also we need the min and max so again from compiling the grades of a particular quiz or exam together as one.

Here's the code that I have so far.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
const char *computeGrade();
int averagesminmax();
int main() {
char fName[20];
char lName[20];

[code]....

Do I need to re-read the input file and assign them to different variables?

Here's a sample of the output so far:

Enter input .txt file name
Graded
Thui Bhu, 91, A
Ariana B. Smith, 96, A
Emily Gonzales, 83, B
Jennifer L, 89, B
Maria Jones, 67, D
Bill Gates, 55, F
Escobar Morris, 78, C
Anne Latner, 88, B
Program ended with exit code: 0

Also in my output file, the only thing that it prints will be the first name of whatever the last student in the input file list is.

View 2 Replies View Related

C :: Binary File Write By User Input Then Printing Binary File Data Out

Dec 6, 2013

Following is the program I wrote it basically takes 9 inputs and then save them into binary file. then print out the data stored in binary data and find inverse of it then print the inverse out. but its stuck in a loop somewhere.

Code:
#include <stdio.h>
int main() {
int a[3][3],i,j;
float determinant=0;
int x;
FILE *fp = fopen ("file.bin", "wb");

[Code] .....

View 6 Replies View Related

C :: Write A Program To Copy One File To Another?

Feb 11, 2013

Here I was trying to write a program to copy one file to another.

Code:
#include <stdio.h>#include <stdlib.h>
int main(int argc, char *argv[])
{
FILE *fp , *ft;

[Code]....

So it should copy test1 to test2. Now I created test1 in gedit. I just put one character "c" in it and closed it. And I ran the program. When I check sizes of test1 and test2 , using

ls -l

command, I see that test2 has 4 bytes and test1 has 2 bytes. So something strange is happening here. I just put a single character in test1, so shouldn't it show 1 byte ? And why test2 is showing 4 bytes ? I have Win XP on my laptop. And I use Ubuntu 12 inside VirtualBox. So this is Linux environment...

View 10 Replies View Related

C++ :: Program That Reads In Ten Whole Numbers And Output Sum

Jan 23, 2014

Write a program that reads in ten whole numbers and that output the sum of all the numbers greater than zero, the sum of all the numbers less than zero (which will be a negative number or zero), and the sum of all the numbers, whether positive, negative, or zero. The user enters the ten numbers just once each and the user can enter them in any order.

Your program should not ask the user to enter the positive numbers and the negative numbers separately. Assume the user will type integer numbers.

this is what i got but it wont run saying there is an error

#include<iostream>;
using namespace std;
int main() {
int count=0;
int num;
int positive=0;
int negative=0;

[Code] ....

View 5 Replies View Related

C/C++ :: A Program That Repeatedly Reads In Values?

Sep 26, 2014

I started to write a program that repeatedly reads in values for a,b and c and find the root of the polynomial

ax^2 + bx + c = 0

The program should print out for example:

two complex roots: root1 = -1.00000 + i*1.41421
root2 = -1.00000 - i*1.41421

My code:

#include <stdio.h>
#include <math.h>
int main(void){
int a,b,c;
printf("Choose the values of a, b and c for the equation ax^2 + bx + c");
scanf("%d%d%d
",a,b,c);

[code].....

View 6 Replies View Related

C++ :: Program That Allow User To Read / Write Onto File

Jan 28, 2013

So I'm trying to create a program that allows one to read/write on to output.txt. I though I had everything set up right, but its only writing one word to the text file. Heres the code.

#include "stdafx.h"
#include <iostream> //Needed for User Input
#include <fstream> //needed for ofstream
#include <string> // needed for strings
#include <windows.h> //needed for Sleep
#include <cstdlib> //Needed for return EXIT_SUCCESS;

using namespace std;
int main() {
ofstream outputfile; //allows to read and write to files

[Code] .....

If I type Puppies Are Cute and go to output.txt, the only thing written in the text file is Puppies.

View 9 Replies View Related

C/C++ :: Write A Program Where It Asks The User For A File Name?

Apr 18, 2014

I'm trying to write a program where it asks the user for a file name.

If that file exists, the it will open the file and then read it and print the information in the file.

However, if the user enters a file name that does not exist, the user will have 2 more tries (for a total of 3 tries) to get the correct name of the file.

I am close to getting it. What I have now just won't go through the loop to validate if the input matches an existing file. It goes straight to the printing of what is in the file. If the file doesn't exist, it prints: "Found your file..Opening..processing...Total keys found = 0."

So, my question, what am I doing wrong that it won't go through the loop properly?

#include<iostream>
#include<iomanip>
#include<fstream>
#include<string>
using namespace std;
int main() {
bool fileFound = false;

[code]....

View 2 Replies View Related

C++ :: Program That Reads In A Sequence Of Binary Digits?

May 11, 2013

c++ program that reads in a sequence of binary digits (values 0 and 1) and stores them into a STL container. The input should terminate on any input that is not a 0 or 1. After finishing the read-process, apply a "bit-stuffing" algorithm to the container. In this case the bit stuffing should occur after four consecutive bits of the same value.i,e. four 0's or four 1's.. Also write the de-stuffing code to process the stuffed data to recreate the original data and verify that the original data is recovered correctly.

View 6 Replies View Related

C/C++ :: Program That Reads 3-by-4 Matrix And Displays Sum Of Columns

Nov 18, 2014

I'm not sure why Im getting a wrong Sum. of the Columns.

Write a method that returns the sum of all the elements in a specific column in a matrix using the following header:

double sumColumn(const double m[] [SIZE], int rowSize, int columnIndex)

Write a test program that reads a 3-by-4 matrix and displays the sum of each column. here is a sample run:

Enter a 3-by-4 matrix row by row:
1.5 2 3 4
5.5 6 7 8
9.5 1 3 1
Sum of the elements at column 0 is 16.5
Sum of the elements at column 1 is 9.0
Sum of the elements at column 2 is 13.0
Sum of the elements at column 3 is 13.0

#include <iostream>
using namespace std;
const int SIZE = 4;
int rowSize=3;

[Code].....

View 1 Replies View Related

C++ :: Write A Program That Will Read Names From Input File

Apr 24, 2014

I have a lab with the following instructions:

Manually create an input text file called Lab22BInput.txt with the following data:

Dove
Doe
Alston
Zebra
Egg

Write a program that will read the names from the input file. Print out each of the names read to the screen. The program should go through the list of names and determine which comes 1st in the alphabet. The program should determine how many letters are in this name. Print out the name that comes first in the alphabet and the length of the name.

I have created the input file, and the data correctly outputs to the screen when I run the program. However, I do not know what kind of logic to use to sort them alphabetically and determine the amounts of characters.

So far I have the following:

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
string str1, str2, str3, str4, str5;

[Code]...

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved