C/C++ :: Write Random Grades To File?
Jul 1, 2014
I need to write a program to store a user specified number of grades to a file, with one grade per line. random function to generate grades between a 55 and 100. When you open the file, it should be for writing, and not appending. Again, prompt the user for how many grades to generate, and store them in a file.
View 2 Replies
ADVERTISEMENT
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
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
Jan 21, 2014
Write a program that asks the user to enter a student’s grades on four exams. The program should display the four grades and the average of the four grades,rounded to the nearest tenth. To add the grades, use a variable called total_grade, which you should initialize to zero.As the program prompts for and obtains each grade, add the grade to total_grade using the += operator.
View 3 Replies
View Related
Aug 31, 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 next (2) at 15% each and the final at 30%. 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:
//
// main.c
// Final Exam
//
[Code].....
The problem I'm having now is how to go about passing the grades to the function computeGrade and then compute the average and return that to the function.
View 4 Replies
View Related
Jul 21, 2014
My code has no errors. I'm just having problems with getting the grades of the file sorted. grades is not a struct, but is a int inside struct School. Below is what I;m having problems with(this is just the code I started working with,I made a few changes but it didn't work,I have no clue)
void selectionSortG() {
Students min;
int key;
for (int i = 0; i < size; i++){
min = student[i];
key = i;
for (int k = i; k < size; k++)
[Code] ....
View 2 Replies
View Related
Jan 29, 2014
I have a complex program, around 25.000 code lines. It is quite stable, but I have a bug which only happens from time to time, and when in online-mode, so it is quite difficult for me to reproduce it. I have put lot of efforts to see where the problem is, and I have seen where the code crash, but that line is not the culprit, it only refers to read a memory location where it is supposed to be good data, and it is not. The real bug has happens before in execution. That data is read-only, I mean, I only compute it at program start-up, and then never write into it again, but my bug write to it doring code run, maybe because bad pointers address in any place, and look ramdom (different snapshots execution write at different memory locations).
My question is, is there a way to know when my code 'write' into that 'to me protected memory'? I thinking if there is a method to make a hash of all variables and arrays in that memory section, or any way to 'assert' when that big memory section is written, taking into accound that when I refer to that memory section it could be any of the lots of variables and arrays I precompute at start-up.
View 2 Replies
View Related
Oct 14, 2014
You are to write a C program that grades a true-false quiz. The quiz data will be available in a text file; here is an example:
Quiz #8 (09/22/14) (corrected version)
TTFTTFTFTF
0080 TTFTTFTFTF
0340 TTFTFFTFTF
The first line in the data file is a comment that you may assume can be up to 80 charac- ters long; it cannot be blank. The second line contains the answer key for the 10-question true-false quiz. The following lines in the data file contain a student's id number in column 1 followed by their answers for the quiz in column 2. A 0 (zero) on a line by itself indicates that there are no more students to process.
Write a program that first reads in (from standard input; more on this in a moment) the comment line and answer key as strings followed by each student's data. Store the student's id numbers in an array. You are to "grade" each student's quiz using the key provided fol- lowed by recording their scores (in a second array) in order to be able to print them out later. You do not need to use an array of strings or characters in your program. Write your program allowing for up to 100 students, and you may assume that at least 1 student will have taken the quiz.
You should create test data text files and provide the data to your program using redirection from the command line (see the sample run below). Your program should output the number of students who took the quiz, the average score, the best score, and a table showing each student's id, score, and grade. The formatting, spacing, and labels in your output should 1 match the sample run below exactly.
Your program should determine each student's grade as follows: if the score is equal to the best score b or b−1, give an A. If it is b−2, award a B. Give C's for any score that is equal to b−3 or b−4, a D for b−5 and an F for all others.
Alright So I'm just stuck at comparing the key answer with student answer here is my code comparing one student's answer with the answer key . is that right ?? One more thing for some reason when i try to print answer[0] the result is nothing why is that
Code:
#include<stdio.h>
int main(void) {
char comment[80];
char answer [10];
char studentans [10];
int n=0,i=0,x=0;
int ID[10];
[Code] .....
View 1 Replies
View Related
Mar 15, 2013
The Objective Of This Program Is To Create A File To Write Text And Read Back The File Content. To Do That I Have Made Two Function writeFile() To Write And readFile() To Read.The readFile() function works just fine but writeFile() doesn't.
How writeFile() function Works? when writeFile() function Execute It Takes Characters User Type And When Hit Enter(ASC|| 10) It Ask "More?(Y/N)" That Means What User Want? Want To Go Next Line Or End Input?
If "Y" Than Inputs Are Taken From Next Line Else Input Ends.
But The Problem Is When Program Encounters ch==10 It Shows "More?(Y/N)" And Takes Input In cmd variable.If cmd=='Y' I Mean More From Next Line Than It Should Execute Scanf Again To Take ch I Mean User Input.But Its Not!!! Its Always Showing "More?(Y/N)" Again And Again Like A Loop.
Code:
#include <stdio.h>
void writeFile(void);
void readFile(void);
int main(){
[Code].....
View 5 Replies
View Related
Jul 8, 2013
how do i decompress an input file and write the results into an output file?
also my do while loop is supposed to keep going unless the user selects the option to exit the program, instead it exits after finishing ay of the options.
here's my code so far...
#include <iostream>
#include <iomanip>
#include <fstream>
[Code]....
View 1 Replies
View Related
Jun 11, 2014
I have a .txt file which I want to read from and then write a new text file, this time with sorted lines. It is easy to sort one value, but what about sorting entire lines based on one value?
I want to sort the lines based on the FIRST value.
Example text file contents:
values;data
5.01 100
2.9 342
2.69 43534
10.1 43
6.8 45324
Output: Text file containing
2.69 43534
2.9 342
5.01 100
6.8 45324
10.1 43
It's easy to do this if there was only 1 number on each line, but I do I sort all the lines based on the first number in each line?
View 2 Replies
View Related
Mar 26, 2013
//******************************************************************************
// GradeCalculator.cpp
// Input: Student Grades in Each Category
// Output: Final Grade, Numerical Grade, Witty Comment
// Final Grade Calculator
// This program calculates a final grade using a formula, assigns a
// corresponding letter grade, and outputs a "witty" comment to the user.
//******************************************************************************
#include <iostream>
#include <fstream> // For file I/O
#include <string>
#include <iomanip>
#include <cmath>
using namespace std;
// Declare function prototypes
void OpenFiles(ifstream&, ofstream&);
[Code] .....
View 1 Replies
View Related
Apr 22, 2013
I am trying to get the code to read from the txt file one bite at a time and then write this bite into the binary file but i cant seem to get it working.
FILE *fpcust, *fpcustbin; //<<<<<-----point to both sales and customers text files, and the new .bin files for both
char buffer;
int ch;
int ch1;
fpcust = fopen("c:customers.txt", "r"); //<<<<-----pointing to the file
fpcustbin = fopen("c:customers.bin", "wb"); //<<<<<-----pointing to the new binary file, opening in writing binary
[Code]...
View 3 Replies
View Related
Dec 11, 2013
im supposed to create a program that reads in a list of integers from the terminal and writes the negative numbers to one file and the positive numbers to another file.
i got most of it doen but for some reason its not writting the negative numbers. on what im doing wrong?
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
int pos_num = 0;
int neg_num = 0;
int positive_numbers = pos_num % 5;
[Code]...
View 2 Replies
View Related
Sep 15, 2013
I am trying to make a grade book and using a vector to get the grades. I am getting errors all over and I figured this would happen because this is the first time I ever used vectors.
Code:
#ifndef ___2B__Homework__LetterGrade__
#define ___2B__Homework__LetterGrade__
#include <iostream>
#include <vector>
[Code] .....
View 12 Replies
View Related
Jul 18, 2013
Write a C++ program that can be used to determine grades at the end of the semester. For each student, who is identified by an integer number between 1 and 60, four examination grades must be kept. Additionally, two final grade averages must be computed. The first grade average is simply the average of all four grades. The second grade average is computed by weighting the four grades as follows: the first grade gets a weight of 0.2, the second grade gets a weight of 0.3, the third grade a weight of 0.3, an the fourth grade a weight of 0.2; that is computed as:
0.3*grade1 + 0.2*grade2 + 0.2*grade3 + 0.3*grade4
Using this info, you are to construct a 60X7 two dimensional array, in which the first column used for the student number, the next four columns for the grades, and the last two columns for the computed final grades. The output of the program should be a display of the data in the completed array.
View 8 Replies
View Related
Apr 22, 2014
Writing a program to calculate grades... My algorithm is long, so I only posted the part that gives me trouble. When classes== 1,2,4, or 5, the program runs fine. but it terminates when classes == 3.
if (classes==3) {
do {
cout<<"Enter the Letter grade for 1st class. (USE CAPS)"<<endl;
cin>>grade1;
[Code].....
View 3 Replies
View Related
Feb 6, 2015
The bottom three functions do not work. Nor are the finished to the extent. I do not know how the data members are being accessed and is only giving me the last output. The overall goal of this program is to output the highest grade with student name and age, lowest grade with student name and age, and the average of all grades. The file is given and is commented out for you to see what the file looks like.
// Header Files
#include <iostream>
#include <fstream>
using namespace std;
// Global Constants
const int STD_STR_LEN = 10;
[Code] .....
View 5 Replies
View Related
May 19, 2013
how to use functions in a program to show the names and grades of students, their average, total, highest and lowest grades.
View 1 Replies
View Related
Oct 28, 2014
How do I sort names and grades in C from highest to lowest?
John 91
Joseph 92
Mary 93
Jake 94
Sorted Scores from highest to lowest
Jake 94
Mary 93
Joseph 92
John 91
View 2 Replies
View Related
Jun 7, 2013
I have to make a program that reads two student grades, the average of the two has to be 6, if you can not take an average of 6, will make a third test and calculate a new average.
I'm not getting the new display medium, without repeating the approved and disapproved?
// TRABAV2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[]) {
[code]....
View 1 Replies
View Related
Dec 8, 2013
I'm using
CString text;
CString file_name;
text = "My text.";
file_name = "MyFile.txt";
FILE *fp;
fp = fopen(file_name, "w+");
fprintf(fp, text + "
");
fclose(fp);
There will be MyFile.txt in Windows codepage.
How to write to txt file with DOS codepage?
View 9 Replies
View Related
Nov 10, 2014
#include <fstream>
#include <ostream>
#include <iostream>
#include <iomanip>
using namespace std;
const int NAMESIZE = 15;
const int MAXRECORDS = 50;
[Code] ....
View 2 Replies
View Related
Feb 24, 2015
I need to write a program that prompts the user for 10 grades and then find the average. I have that part but I need to average to not include -1. How can I tell the program to not calculate -1 into the average.
#include <iostream>
using namespace std;
int main() {
//Declare variables
float grade[10]; // 10 array slots
int count;
float total = 0;
double average;
[code].....
View 1 Replies
View Related
Jan 28, 2013
An instructor needs you to write a program that will compute the final average grades in her class. There are 5 students in the class. Each student must take 2 exams and 4 quizzes as part of their final grade. The weight of each toward the final grade is as follows:
Exam 1 – 30%
Exam 2 – 30% Quiz 1 – 10%
Quiz 2 – 10%
Quiz 3 – 10%
Quiz 4 – 10%
You must use arrays to store each students 3 digit ID number, exam scores and quiz scores. A multi-dimensional array is mandatory. Request from the user the information needed then output all of the information as well as the final average grade for each student.
View 1 Replies
View Related
Nov 8, 2014
This is a simple program I am building to find the average of 5 grades where the lowest grade is dropped. I created a function findLowest() which accepts the 5 grades as arguments, finds the lowest grade and returns it as "lowest". I have tried many different way to find the lowest number. Right now, I am working with if...then statements.
#include <iostream>
using namespace std;
void printMessage(); //Prototype for printMessage
void getScore(int&); //Prototype for getScore with reference variable
int findLowest(int,int,int,int,int,int &); //Prototype for findLowest with reference variable
[Code] ....
View 2 Replies
View Related