C :: Using Arrays - Program That Prompts For And Reads In Test Scores
Feb 11, 2013
Write a program that prompts for and reads in test scores. You may assume that valid test scores will be integer values between 0 and 100. You may also assume that the user will not enter more than 35 test scores. Use a preprocessor directive to define this value. User input will be complete when the user enters a -1 for the test score. When all of the test scores have been entered, the program will print out the scores. Use a while or do-while loop to read in the values. Use a for loop to print out the values.
Sample output:
Enter test score 1: 88
Enter test score 2: 67
Enter test score 3: 74
Enter test score 4: 94
Enter test score 5: 79
Enter test score 6: 56
Enter test score 7: -1
Number of scores entered: 6
Test scores entered : 88 67 74 94 79 56
View 14 Replies
ADVERTISEMENT
Apr 7, 2013
I have created a program that allows for a user-defined number of test scores as input. After the user enters these scores, the program calculates the average test score. Here is my code:
#include <iostream>
#include <iomanip>
using namespace std;
// Function prototypes
double getAverage(double*, int);
[Code] .....
I am having trouble with the final part of my program. How do I pass the array of test scores to a function that calculates how many people got an A (90+) on the test? The final output should look like this:
The average of those scores is:
The number of A grades is:
View 2 Replies
View Related
Jan 12, 2014
I'm trying to basically have a user input the amount of test they want averaged, then have the user input the test scores. Send the test scores to a function and have them ordered in ascending then send it to another function that averages it. When I wrote the function I keep getting the address back instead of the actual values.
#include <iostream>
#include <iomanip>
using namespace std;
void arrSelectSort( int* [], int);
void arrAverage(int);
[Code] .....
View 3 Replies
View Related
Jan 25, 2015
i have so far, and im having trouble finding a way to store 5 test scores for each student that has been entered. for example: enter name: chaotic enter id number: 12312312
Enter test score 1:
Enter test score 2:
Enter test score 3 etc.......
heres me code so far
#include <iostream>
#include <string>
#include <iomanip>
#include <cstdlib>
using namespace std;
[Code]....
View 1 Replies
View Related
Nov 30, 2014
I was doing a side programming challenge in my workbook that asked me to dynamically allocate and array for test scores. So far I have an array that will accept an integer to allocate the amount of test scores and then will accept integers to populate the array, however when I try to cout the contents of the array the numbers are absurdly different than what was put in. Here's my code:
#include "stdafx.h"
#include <iostream>
using namespace std;
void main() {
cout << "How many test scores?" << endl;
int scores(0);
[Code] ....
And this is the output screen:
How many test scores?
4
Enter test score 1:
22
Enter test score 2:
33
Enter test score 3:
44
Enter test score 4:
55
-33686019
18472
55656634
201345063
Press any key to continue . . .
Why am I getting these crazy numbers? I've looked back and forth from examples in my book and it doesn't look like I'm doing anything wrong.
View 5 Replies
View Related
Oct 22, 2014
I was asked to create a C++ program that allows a user to take a test with series of different questions, and also retake the test if they choose to. I have been able to do that. But the other condition is to display the highest and lowest scores (highest and lowest correct answers) the user got, and in which test they got that score. For example, if the user takes the test 3 times, in which test did they get the highest score, and in which did they get the lowest score.
This is how far I went with the program. The code below only let the user take the test as much as they want, and tell them how many times they took it, and the last score they had. My idea is this, if I can make a variable store each test score, then I can compare them. But since there is no definite number of tests to be taken.
#include <iostream>
#include <string>
using namespace std;
void main() {
int correct = 0;
int wrong = 0;
[Code] .....
View 3 Replies
View Related
Apr 22, 2014
I am writing a class that dynamically allocates an array that holds a user-defined number of test scores (test scores go from 0 to 10 both included). Once all the test scores are entered and validated (values only between 0 and 10, both included), the array should be passed to a function that sorts them in ascending order. Another function should be called that calculates theaverage of all the scores.The main program should display the sorted list of scores and the average of the scores with appropriate headings.
View 6 Replies
View Related
Jan 18, 2014
I need to sort these students based on their test scores.
My biggest problem is with my sort function. I am not sure of the syntax to call the items the proper way. I also don't know how to call the function properly as I know that i can't pass a int to a struct. Also not sure about the z malloc. Just threw that one in there.
Code:
struct student{
int id;
int score;
};
void sort(struct student* students, int n){
/*Sort the n students based on their score*/
[Code] ....
View 5 Replies
View Related
Jan 14, 2013
Below is the program I have written yet I can't seem to get it to work right.
// Purpose: generate a class average for entered test scores
// Input: # of tests, test scores
// Output: total number of tests, average score of tests
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
//declare variables
short numberOfTests = 0;
[Code] .....
View 6 Replies
View Related
Oct 28, 2013
so in declaring a display function prototype only that displays a student test scores in the format (student name tab number of scores tab test scores )
is this right?
#ifndef STUDENTTESTSCORES_H
#define STUDENTTESTSCORES_H
#include <string>
using namespace std;
class StudentTestScores{
private:
[Code]...
and also how do we call the display function if it is in a class from the header file onto the main cpp file.
View 2 Replies
View Related
Sep 23, 2013
I'm making a program that prompts a user for an int value. The value input by the user must be a multiple of 16. If it is not, I must return an error message.
View 5 Replies
View Related
Dec 15, 2014
My problem is when I try to show the contents of my text files after I add a contact it wont show me anything.
#include <iostream>
#include <conio.h>
#include <string>
#include <windows.h>
#include <fstream>
#include <cstdlib>
using namespace std;
//prototypes
void printline(char, int);
[code].....
View 3 Replies
View Related
Feb 10, 2014
Implement a class Person with two fields name and age, and a class Car with three fields:
The model
A pointer to the owner (a Person*)
A pointer to the driver (also a Person*)
Write a program that prompts the user to specify people and cars. Store them in a vector<Person*> and a vector<Car*>. Traverse the vector of Person objects and increment their ages by one year. Traverse the vector of cars and print out the car model, owner’s name and age, and driver’s name and age.
#include <iostream>
#include <vector>
#include <conio.h>
#include <string>
using namespace std;
class Person {
[Code] ....
View 7 Replies
View Related
Oct 8, 2014
Here is the whole code:
#include <iostream>
#include <ctime>
#include <cstdlib>
//This program prompts the user to select a number between 2 and 12
//computer throws two dices
//player win if selected number matches the sum of the two dices thrown by computer
[Code] .....
View 6 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
Nov 8, 2013
Write a program that prompts the user to enter an integer and then displays that integer as a product of its primes and if it is a prime then it should say so? Above is the question I have been given
#include <iostream>
#include <vector>
using namespace std;
int main () {
int num, result;
cout << "Enter A Number " << endl;
system ("pause");
return 0;
}
This is what I have so far, do I have to use a for loop, a while loop or a do loop,
View 7 Replies
View Related
Jun 27, 2013
Write a program that prompts the user to enter an item#, the program should determine if the item is in the file and print the price of the corresponding item. If the item is not in the file an error message should be printed.
All I have so far is
string item_no=0;
cout<<"Enter a item#";
getline(cin,item_no);
if stream openData;
I need to finish the rest in pseudo code
View 2 Replies
View Related
Sep 27, 2014
I have an assignment in which i must create a program which prompts for user input of current and birth date, which will compare said dates and output if its your birthday or not. I've completed a large portion of it, but cannot figure out how to get the user input of month as an integer such a 2 into February.
#include <iostream>
using namespace std;
class DayOfYear {
public:
void input();
[code]....
View 1 Replies
View Related
Aug 19, 2014
Okay so suppose that a text file grade.txt contains an unspecified number of scores. How would I program that reads the scores from the file and displays all the scores, their total and average? Scores are stored in the format of one score per line. Im having trouble with the whole #include <fstream> file and how to lay it all out in visual studio.
View 1 Replies
View Related
Jan 21, 2015
I wrote the following program:
#include "stdafx.h"
#include "string.h"
#include "ctype.h"
[Code].....
View 1 Replies
View Related
Jun 5, 2014
Write a program that scores a blackjack hand. In blackjack, a player receives from two to five cards. The cards 2 through 10 are scored as 2 through 10 points each. The face cards - jack, queen, and king are scored as 10 points. The goal is to come as close to a score of 21 as possible without going over 21. Hence, any score over 21 is called "busted". The ace can count as either 1 or 11, whichever is better for the user. For example, and ace and a 10 can be scored as either 11 or 21. Since 21 is a better score, this hand is scored as 21. An ace and two 8s can be scored as either 17 or 27. Since 27 is a "busted" score, this hand is scored as 17.
The user is asked how many cards she or he has, and the user responds with one of the integers 2,3,4, or 5. The user is then asked for the card values. Card values are 2 through 10, jack, queen, king, and ace. A good way to hande input is to use the type char so that the card input 2, for example, is read as the character '2', rather than as the number 2. Input the values 2 through 9 as the characters '2' through '9'. Input the values 10, jack, queen, king, and ace as the characters 't', 'j', 'q', 'k', and 'a'. (Of course, the user does not type in the single quotes.) Be sure to allow upper - as well as lowercase letters as input.
After reading in the values, the program should convert them from character values to numeric card scores, taking special care for aces. The output is either a number between 2 and 21 (inclusive) or the word Busted. Use fucntions, multiway branches, switch statements or nested if-else statements. Your program should include a loop that lets the user repeat the calculation until they are done doing so.
The code runs properly for the first card but then it asks if the user wishes to repest the program. I need to claculate the value of all cards before it asks for that. Here is my code:
#include <iostream>
using namespace std;
int main()
{
[Code].....
View 5 Replies
View Related
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
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
Dec 10, 2014
I'm trying to get the program to read from a file of 15 scores. 10 are quizzes 5 are exams. I want my program to read from the input file the first name "or" last name and if the user puts a different name, the program Gives off an error screen message
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
const int NUM_STUDENTS = 20;
const int NUM_QUIZZES = 10;
const int NUM_EXAMS = 5;
[code]....
View 14 Replies
View Related
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
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
View Related