C/C++ :: Quiz Program Based On Data File Handling
Dec 22, 2014
I'm trying to make a Quiz program based on C++'s Data File Handling capablities. I've attached the code in .txt file and I wonder why I'm getting the error identifier bScience cannot have a type qualifier?
Attached Files QuizPro.txt (9.6 KB)
View 7 Replies
ADVERTISEMENT
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
Apr 15, 2014
My code is not moving past the line below...actually i am making a quiz and this piece of code id checking whether the entered answer is correct, from a file..
getline(anss,saveans);
while(a<1) {
getline(anss,saveans);
if (saveans == ToString(randNum)) {
getline(anss,saveans);
if (saveans == ans)
[Code] ....
View 9 Replies
View Related
Jul 11, 2014
I am making a multiple quiz program. So everything is working fine, except for the part where i'm trying to add a highscore for each user which is being stored in a binary file. I have added a sample of the program containing the error. This isn't the actual program, which is very long.
class user { //The collection of all info pertaining to the users
char user_id[50];
public:
int hscore1;
user() {
strcpy(user_id,"NULL");
hscore=0;
[Code] ....
View 1 Replies
View Related
Jan 10, 2014
I am having a 1file (given file) and in that i have some binary information and i niw i want to convert those binary information into decimal form and save it into new file (output fle). I was written a code but that was not working properly.
Code :
main() {
int i,j,n,ch;
int a[100][100];
FILE *p,*q;
char file1[20],file2[20];
printf("enter the given file name");
[Code] ....
View 2 Replies
View Related
May 16, 2013
Every time I write in file using ofstream it works fine except for one thing that when the file is re-opened after writing something and we try to add more data then previously added data is removed how to get rid of this.
<code>
struct abc {
char name[100];
int a;
};
int main() {
ofstream file;
file.open("text.dat", ios:ut | ios::binary);
[Code] ....
View 1 Replies
View Related
Nov 24, 2013
I have this code for a computer project... (store management) but the character strings are not copied on text file..
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
class Store {
public:
char *item_name[5];
store()
[Code] .....
Now when i run the program, it gives a error :::
ERROR
address 0x0
How can i write these strings to the text file?
View 2 Replies
View Related
Mar 26, 2013
I've written a program to read inputs in a text file. The file named Input.txt contain integers 2 3 and 4. My program is as follows:
#include<iostream>
#include<cstdlib>
#include<fstream>
using namespace std;
int main (){
int x,y,z;
[Code] ....
the program is outputing x=2293616 , y=0 and z=0 instead of x=2, y=3 and z=4.
View 9 Replies
View Related
Apr 24, 2013
I want to create a binary file based on some hex data :
Ex Input Hex :54313032202020303030
Out put like :6
View 2 Replies
View Related
Dec 4, 2013
I have two classes, productListType and buyerListType, that are each basically linked lists. To create the linked list for an object of productListType, I successfully wrote a non-class function createProductList to read the product data from a text file. The class definition for buyerListType has a data member productBoughtRecord that is of type productListType to aggregate the details of the products purchased by a particular buyer during transactions. I decided to make productBoughtRecord a pointer since the contents of this data member would wax and wane over the course of several transactions, depending on the amount and frequency of payments made by the buyer. I have provided a rough sketch of the class below:
class buyerListType
{
public:
setCustomerInfo( ....., productListType* p);
.
.
.
private:
productListType* productBoughtRecord;
.
.
};
I'm similarly trying to write a non-class function createBuyerList to load the record of customers from a text file. How do I determine what the value of the formal parameter p in member function setCustomerInfo is, in order to be able to set the data member productBoughtRecord? take into consideration that an object of class buyerListType would have multiple buyers with varying amounts of products purchased.
View 11 Replies
View Related
Nov 16, 2014
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void correctResponse(void);
void incorrectResponse (void);
void multiplication( void ); // function prototype
[Code] ....
// end function multiplication
// It keeps crashing. How do I compile the responses into a grade?
View 5 Replies
View Related
Apr 7, 2015
I've been taking a C++ class, and for a project we need to do, we have to create a simple quiz show game while putting the high scores and names inside a .txt file. We have lessons we can look at to complete it while learning. But at the end there's always a challenge that we should complete to show that we've actually learned the information. For the challenge, we needed to take the information in the .txt file and reset it to its original information. So say there's 5 people preset that have high scores, then a person plays the game and the program asks if they'd like to reset the list. If the user inputted 'y' or any key that needed to be pressed, the program would reset the .txt to its original information.
This is the code that creates the program.
// Include Libraries
#include <iostream>
#include <string>
#include <fstream>
// Include standard namespace
using namespace std;
// Declare Global Variables
int Guess;
int Winnings;
[Code] ....
It works how I need it to and there aren't any problems, necessarily, but I want to know if there's any, more efficient, ways of completing this task. Like if there's any already made function of resetting a file.
This is the code that resets the file. As you can see, it just uses the information earlier in the code inside the if statement. Is there any pre-made function or method of resetting a file?
cout << "Would you like to reset the high scores list? (y or n): ";
cin >> ask;
if (ask == 'y')
{
High_Score[0] = 25000;
High_Score[1] = 12000;
High_Score[2] = 7500;
High_Score[3] = 4000;
High_Score[4] = 2000;
[Code] .....
View 1 Replies
View Related
Apr 10, 2013
I'm fairly new to C++ programming. I wanted to accept a datatype as an input. I've seen something similar while working with the <queue> library.
When defining a new object of queue
For example:
queue<int> Queue;
How is <int> handled ??
View 1 Replies
View Related
Apr 16, 2014
Data handling for a UAV project I am trying. My background is in Microcontrollers but I have never had exposure to "sound" programming practice...
I have got 2 microcontrollers to drive a UAV craft I've made. One "firmware" micro collects all the sensor data and then passes it to the other "application" micro for control processing. Once decisions have been made this is sent back to the "firmware" micro so that actions are taken.
So in essence I am sharing a raw data chunk periodically between the 2 processors that has outputs and feedback data. For the moment this is captured as one big buffer array on either micro after receiving. For easier structure I thought of bouncing this buffer that contains all sensor information and control variables between the 2 processors (visualize a ping pong game with all the possible variables from both micros - bandwidth between the micros is not a limitation) There are quite a few modules that want to access information from this buffer and write control actions back to it.
I was thinking of constructing a struct on both micros to access this "raw data" from the buffer and set it up with variable names so that it is easier for functions to read info and write controls back.
But this would mean that the data is accessible to every function, and there is the fear that some functions will write to the input data or write to control variables that they should not have access to. I also need to reduce memory copies and the like due to limited memory on each micro.
View 4 Replies
View Related
Jan 24, 2014
I have to implemente the to_string method. Whats the fastest way? Stringstreams. But I have to use C++ without any headers, so I need to implement the stringstream class. How can an stringstream hold one float? An double? Hoq cqn I implement an strigstream myself?
View 8 Replies
View Related
Feb 17, 2015
write a program as described below: program that reads in two integers (age, social security number). You should write functions that throw an out-of-range exception forage (no negative numbers)SSN (must be a 9-digit integer) My code is written below:
#include "std_lib_facilities_4.h"
int main(){
int age = 0;
int ssn = 0;
[Code].....
View 8 Replies
View Related
Jul 14, 2012
I have a folder "pics" in g: drive. There I want to create some text.txt file. Thus, the final path is "g:pics ext.txt".
How can I do that?
View 3 Replies
View Related
Dec 23, 2014
I have a area in my Project where i need to display a title and content in two text boxes. The Data base tables are:
ID | Title | Content
This is what I have so far, I know I am on the right track, I just cant figure out how to get each box to display based on the ID.
private void frmMain_Load(object sender, EventArgs e){
try {
string connStr = ConfigurationManager.ConnectionStrings["sdcAssistDB"].ConnectionString;
OleDbConnection dbConn = new OleDbConnection(connStr);
dbConn.Open();
[Code] ....
View 3 Replies
View Related
Nov 24, 2013
writing a program that requires exception handling. if an error occurs, i what the program to go back to the begging of the loop. i tried using break but that just makes the program crash when it receives a bad input. how do i do this? this is what i have so far (this part of the program any ways)
while (! quit)
{
// Output phone book menu
cout << endl
[Code].....
View 1 Replies
View Related
Apr 23, 2013
Generate a binary ascii characters(weird character ) based on Hex:54313032202020303030 data in C++
View 3 Replies
View Related
Feb 7, 2014
Player is given choice of x number of Races This choice changes the player's base stats. Then player is given a choice of x number of Classes (archer, warrior, etc.) This choice determines how the player's stats will change upon leveling up.
#include <cmath>
#include <iostream>
#include <ctime>
[Code]....
View 7 Replies
View Related
Feb 3, 2014
I am trying to create a program that would execute a foreground process. I have this code for the foreground process
Code:
#include <stdio.h>
#include <signal.h>
int main() {
int temp;
printf("We are in the current program
[Code] ....
And this is my main program
Code:
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
int main() {
signal(SIGINT, SIG_IGN);
[Code] ....
My main program stops executing after the process "./scanf" executes and there fore does not print the line "How are You"...
I want to main program to continue executing after "./scanf" finishes. How to achieve that?
View 2 Replies
View Related
Mar 27, 2014
I need to insert my thesaurus words .txt to my c program applying BST. But I am not sure how.
Here are my file: awwwwwwww.txtthes.c
View 1 Replies
View Related
Sep 27, 2013
how to stop outputting data based on a user input. The text file is as follows:
1. a
2. b
3. c
and the code I'm using is as follows:
int main (){
string line;
int search;
cout << "Enter a number from 1-3" << endl;
cin >> search;
search++;
ifstream myfile ("example.txt");
[Code]...
What I want to do is to just output number 1 (the whole line) if the user enters number 1. However, I get an error on the second condition w/c is the "&& line!= search"
View 1 Replies
View Related
Apr 1, 2014
I have a problem I am working on where I need to sort some data based on the values of a string of bits. The strings look like this,
010000001110000000
there are 18 bits, 1 means a feature is present, 0 means the feature is absent.
Each of these string has 4 on bits. I need to sort them such that I have the longest possible runs with 3 of the same on bits. It doesn't matter which 3 bits are on, I am just looking to order them in blocks with the longest possible runs. As a second step, the ordered blocks will be sorted by size large>small.
The following data is ordered like I need it to be.
Code:
// block 1, run of 12, keys 1,2,11 are identical (key 12 is also identical)
011000000001100000
011000000001100000
011000000001100000
011000000001100000
[Code] .....
This is the sort order that I am looking for. I need to be able to take a list of the bit strings in any particular order and sort them into the order above. The algorithm would need to recognize that there are 4 on keys and then look for groupings of three common on keys.
This is more of an algorithm question than one about specific implementation in code. I generally assume that most programming problems have been solved one way or another, so I don't know much about analyzing and manipulating strings of bits.
Is there a standard method for this kind of pattern recognition?
View 14 Replies
View Related
Apr 22, 2012
Ok I'm trying to create matrix of data that I can add values to based on a reading that I will get from a DVM. I'm using a 3d vector to do this. I need to keep track of the serial number, the day and within day I need to take two readings at different temps, this will continue for 7 days.
The rows of my 3d vector will be the days, the colums will be the serial numbers the depth will be the reading at the different temps.
What I need to do is compare the first element (days) and when it is greater then or equal to 4 I will perform calculations of the readings. So all I want to do is compare the first element of the vector, How do I do this?
Here is what I got
Code:
#include <vector>
typedef std::vector<double> Double1D;
typedef std::vector<Double1D> Double2D;
typedef std::vector<Double2D> Double3D;
#define HEIGHT 5
#define WIDTH 3
[Code]....
View 7 Replies
View Related