C/C++ :: Grade Converter Using Parallel Arrays
Apr 8, 2015
I am attempting to reconfigure a working code that before used while loops and if statements to convert a numeric score to a letter grade. I now wish to take this same code however I want to change the char convertGrade(int numScore) to simply use a parallel array as a replacement to the if statements.
The array needs to consist of 3 arrays of fixed size 5:
int minScores[SIZE]
int maxScores[SIZE]
char letterGrade[SIZE]
I know the declarations need to go in the function convertGrade but this is the first time I have worked with arrays and I am having trouble trying to figure out how this array will replace my previous if statement.
In order to access the array elements I need to write specifications such as
minScores[i]
maxScores[i]
letterGrade[i]
(where i = 0, 1, 2, 3, or 4)
#include <stdio.h>
#include <stdlib.h>
#define SIZE 5
int getScore(void);
char convertGrade(int numScore);
[Code] .....
View 5 Replies
ADVERTISEMENT
Mar 10, 2014
I am trying to learn about parallel arrays and files. I believe that I wrote a program that properly writes the data of the arrays into a file, but I am not quite sure how to take the next step and make a second program by bringing in the file I created and reading the information of the file back into two arrays to display them.
Code:
#include<iostream>
#include<fstream>
#include<string>
usingnamespace std;
[Code] ....
View 5 Replies
View Related
Mar 31, 2015
#include <stdio.h> /* fopen, fclose */
#include <stdlib.h> /* exit function */
#include <string.h> /* string library */
#define STRSIZENAME1 41 /* length of name */
#define STRSIZENAME2 100 /* amount of names */
#define STRSIZEAGE 100 /* amount of ages */
/* Name: main */
int main(int argc, char* argv[]) {
[Xode] ....
This is the code I have so far. The goal of the assignment is to sort two parallel arrays, one with names and another with their ages, at the same time to alphabetize them. I am stuck with trying to pull the data from the file itself and concatinating it. I have searched ways to do so and this is the best I understood. So the error is it will get me the first person's name, but it won't get the age and move to the next line in the file. It just keeps repeating the same thing and I can't figure out why.
I attached the sample file with names and ages to view the format of the text file itself.
PS the other defined variables are used later for sorting the data. right now I am just trying to get the data itself and put it in an array but between my book and the internet I can't seem to store the data properly. That is also why I am printing it in the while loop as well so I can see what my arrays look like but I will take that out too once I know the data is good
Attached File(s)
peoplefile.txt (157bytes)
View 2 Replies
View Related
Nov 3, 2014
I have trouble reading data from a text file to parallel arrays. the text file (album.txt) has this format:
Code:
(song1 title)
(song1 artist)
(time1)
(song2 title)
(song2 artist)
(time2)
.
.
etc
I want to store these data into three arrays:
title [], artist[], time[] this is what I have so far:
Code:
#include <stdio.h>
#include <string.h>
#define SIZE 9999
int main ()
{
FILE *tFile;
char title[SIZE];
[Code]...
the problem is that each array reads the whole text? I want to store artists name in char artist[] .. titles in char title[] and so on
View 5 Replies
View Related
Oct 23, 2013
i'm facing some problems with the array, as I have my .h and .cpp files so do i declare them as per norm of how we usually declare a function?
pointtwod.h
class PointTwoD {
private:
int xcord,ycord;
float civIndex;
LocationData locationdata;
[Code] ....
when i compile the error message i get was even when i i put in int xord[]; in my PointTwoD.h file:
PointTwoDImp.cpp:99:6: error: prototype for 'void PointTwoD::storedata(int*,int*,float*) does not match any in class 'PointTwoD'
PointTwoD.h:48:8: error: candidate is: void PointTwoD::storedata(int, int, float)
PointTwoDImp.cpp: 135:22: error: 'xord' was not declared in this scope
PointTwoDImp.cpp: 135:27: expected primary-expression before ']' token
PointTwoDImp.cpp: 135:30: error: 'yord' was not declared in this scope
PointTwoDImp.cpp: 135:35: expected primary-expression before ']' token
PointTwoDImp.cpp: 135:38: error: 'civ' was not declared in this scope
PointTwoDImp.cpp: 135:42: expected primary-expression before ']' token
View 1 Replies
View Related
Apr 14, 2014
So the point in this code is to promt the user to enter a product ID. It then should search the ids array and display the corresponding price and quantity from the prices and quantities arrays. I'm sure this is quite simple but I am new to programming and having trouble understanding arrays. All it is doing is giving me the first subscript when I input a -1.
//Advanced34.cpp - displays the price and quantity
//associated with a product ID
//Created by Scott Knight on April 12, 2014
#include <iostream>
using namespace std;
int main() {
//declare arrays and variables
int ids[5] = {10, 14, 34, 45, 78};
[code]......
View 5 Replies
View Related
Aug 17, 2013
I am having a problem with my program to calculate the GPA of a student. The problem that I am having is that I am not able to get my Total Point Value to display the sum of the two arrays. The multiplication for the array is correct and will display correctly, but instead of putting the total into the accumulator it will display the totals in a column. I have tried moving the coding for the calculation out of the loop that converts the letter grade into a point value,and placing it in it's own loop, but I still get the same display output. Below is the code that I have so far. I still have a few elements to add to the code, but they will be easy once I get this display to work right.
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
// Global const
// prototype
int main () {
// Varialbes, Arrays
[Code] ....
View 1 Replies
View Related
Apr 4, 2014
Class programming project where we declare two arrays, a sting array containing the names of the boroughs and an int array which which holds accident number for each borough. The main function calls getNumAccidents() function to fill the array. it then calls findLowest() to learn which borough had the fewest accidents. It should print out the accident numbers for each borough and then out the borough and accident number with the fewest accidents.
I'm able to get the program to kind of work. When I run it everything works fine but I am not able to get the arrays to sort and match up correctly..
#include<iostream>
#include<iomanip>
#include<string>
#include<cstring>
using namespace std;
class combineSort {
public:
combineSort() {
[code]...
View 14 Replies
View Related
Dec 8, 2013
I have an external file that I would like to read from this file and place the values into parallel arrays. The file has these values:
Rams
Titans
23
Patriots
Rams
20
Steelers
Seahawks
21
View 1 Replies
View Related
Nov 10, 2014
I have a .txt file that I need to input into two parallel arrays. The first array needs to be on dimension and the second needs to be two dimensions.
This is a sample from the .txt file:
Australia62.762.163.359.7
Austria052.853.154.6
Belgium30.430.327.525.3
Canada61.356.257.754.5
Chile026.425.431.1
CzechRepublic038.327.325.2
Denmark65.067.162.355.0
Estonia51.732.929.834.3
Finland55.242.942.143.3
France35.728.330.228.8
Germany56.447.242.646.6
Greece30.326.925.013.1
Hungary032.521.818.6
Iceland068.271.666.0
this is what I have for code so far:
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
const int SIZE = 40;
const int COLUMN = 5;
void getData(ifstream& inf, string n[], double tstData[][COLUMN], int count);
[Code] .....
when I compile and run the code and have it display it does not read the first item into the 1-d array, instead it appears to read the 4th number from the left into the 1-d array and then into the second spot in the 2-d array, then again in its proper place and finally it has this number repeating through the rest of the arrays:
-92559631349317830000000000000000000000000000000000000000000.00 followed by the number 59.7 from the .txt and the long number again.
View 10 Replies
View Related
Apr 19, 2013
I have a txt file that looks like this:
Student ID:97707; Grades: 87.73, 90.41, 91.74, 95.04, 99.13; Name:Davis, Artur
Student ID:23628; Grades: 58.09, 65.18, 68.62, 68.62, 98.05; Name:Davis, Susan
Student ID:49024; Grades: 18.37, 66.06, 68.07, 80.91, 96.47; Name:DeGette, Diana
-I need to read the id, grades and names;
-The id to a separate array
-The grades to a 2-d array
-And the names to a c style string.
Where do I start, im having trouble read the dummy to start
int main() {
char filename[15] = "ex.txt";
string names[MAX_NAMES];
double grades[MAX_ROWS][MAX_COLS];
int id[MAX_IDS];
int index = 0;
ifstream fin;
[Code] .....
View 3 Replies
View Related
Oct 30, 2014
I've been working on an assignment that deals with newspaper advertisements. I have two arrays:
categoryCode (the code for the advertisement's category such as pets, cars, etc) and
numWords (number of words in the ad).
The arrays are dynamic.
My assignment has the category listed each time there is an ad associated with it and then its number of words for that ad. If this were a real-world issue I would want my output to list each category only once despite how many ads were in it, list how many individual ads are in the category, and its total number of words for the ads in that category. When using parallel arrays, is there a way to do this?
Let's say I have categoryCode with three elements {5, 5, 7} and numWords {10, 12, 15}.
How would I make the numWords add together only when the categoryCode values are the same?
I would want the output to print:
Category 5 Ads 2 Words 22
Category 7 Ads 1 Words 15
rather than how my instructor is having us do it like this:
Category 5 Words 10
Category 5 Words 12
Category 7 Words 15
I think I'm getting hung up because my mind is confusing the element's location in the array with the element's actual value and I'm probably making this harder than it should be. How would I compare the categoryCode values in a dynamic array? If it were a fixed size I think I could just compare categoryCode[0] to categoryCode[1] and so on, right? But in this case I'm not sure how I would go about that.
View 6 Replies
View Related
Jul 30, 2014
In pseudocode and in C code, declare two 1-dimensional parallel arrays of Integers to store the age and weight of a group of people that will hold the information of up to 10 people. Use a For loop to iterate through the array and input the values. This is the code i have, but my array is showing up as 11 and not 10?
Code:
#include <stdio.h>
int main() {
//Define Variables
float Age_Data[10],Weight_Data[10];
float Age_Input,Weight_Input;
[Code] .....
View 3 Replies
View Related
Apr 7, 2013
I'm writing a program to calculate a final grade by adding 4 numbers minus the lowest grade and dividing by 3. My knowledge in c is not extensive I thought that a simple assigment operator would do the job but I'm getting a strange large numbers in the execution.
Code:
#include <stdio.h>
#include <stdlib.h>
main(){
int eg, g1, g2, g3, g4, fg, s1, s2, sg;
[Code] ....
View 4 Replies
View Related
Apr 23, 2014
I have to accept the numerical grade and determine the letter grade that the user will receive. I have to use a grading table to determine the letter grade based on the numerical grade. The Letter Grade table is
A 90-100
B 80-89
C 70-79
D 60-69
F 59 and below
Here is the code
//preprocessor directives
#include <iostream>
#include <string>
//namespace statement
using namespace std;
//function prototypes
void getData (string& course, string& first, string& last, int& grade);
[Code] ......
As you can see, I am currently stuck on the determineGrade one
View 1 Replies
View Related
Jun 26, 2013
I get so close, and then it seems my brain shuts down ... I need to write a program that outputs a histogram of student grades for an assignment. The program should input each student's grade as an integer and store the grade in a vector. Grades should be entered until the user enters -1 for a grade. The program should then scan through the vector and compute the histogram. In computing the histogram, the minimum value for a grade is 0, but your program should determine the maximum value entered by the user. Use a dynamic array to store the histogram. Output the histogram to the console. For example, if the input is:
20
30
4
20
30
30
-1
Then the output should be:
Number of 4’s: 1
Number of 20’s: 2
Number of 30’s: 3
I can't quite get my output to look like that:
/* This program will display the histogram of student grades for an assignment */
#include <iostream>
#include <vector>
#include <stdlib.h>
#include <conio.h>
[code]......
View 3 Replies
View Related
Feb 24, 2013
i'm having trouble with my c programming assignment. i'm trying to convert a number grade to a letter grade. I'm trying to Write a function (called: numToLetter) that takes as input a number from 0 to 100 and returns a character ( a single character ), based on the following: if the number is between 60 and 70 return Dif the number is greater than 90 return Aif the number is between 70 and 80 return Cif the number is between 0 and 60 return Fif the number is between 80 and 90, return B and i need to use the return statements to call the function like for example:
if (a > 90) return ('A');
elseif (a > 80)
return ('B');
elseif (a > 70)
return ('C'); else
return ('F');
how do if write my code with this function?
View 1 Replies
View Related
Feb 5, 2013
I know my current program will not compile. How can I store the the start temperature so it can be used again in the final printf statement "start degrees Fahrenheit is converted Celsius."?
Note - I want to use the float data type for precision.
Code:
//THIS PROGRAM WILL CONVERT TEMPERATURES BETWEEN DEGREES FAHRENHEIT AND DEGREES CELSIUS
#include <stdio.h>
int main(void)
[Code].....
View 4 Replies
View Related
Feb 26, 2013
I'm trying to make a program that takes up to a seven digit binary number and converts it to its decimal equivalent. I'm still a beginner, so this might be a simple question but how do I stop the user from entering anything but 1s and 0s? This means no decimals or numbers other than 1 or 0.I already made it so it won't accept anything below 0 or above 1111111.
View 1 Replies
View Related
Mar 15, 2013
#include <iostream>
#include <math.h>
using namespace std;
int main() {
int N=0, counter=0, counter1=0,counter2=0, temp=0, temp1=0,dec=0,result=0, moder=0;
[Code] .....
This is Binary to Decimal Converter. It's not working. Although Dry Run of this program works fine.
View 4 Replies
View Related
Dec 23, 2013
I am writing a program that converts arabic numbers into roman numerals.
Quote Write a program that asks the user to enter a number within the range of 1 through 10. Use a switch statement to display the Roman numeral version of that number.
Input Validation: Do not accept a number less than 1 or greater than 10.
Prompts And Output Labels. Use the following prompt for input: "Enter a number (1 - 10): ". The output of the program should be of the form "The Roman numeral version of A is R" where A is the Arabic numeral entered (1,2,3,...) and R is the all-capitals form of a Roman numeral, such as VII.
View 14 Replies
View Related
May 23, 2013
I wrote this code purely for educational purposes. It also learn more about how exactly things look in memory. code I have right now ( I will likely add more and change it in the future) .....
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
[Code].....
View 7 Replies
View Related
Sep 9, 2014
I was trying to program an decimal to binary converter (8-bits) in C. I am a complete beginner so I tried to put the 1's and 0's of the binary number as they come without reversing the order for beginning. I have seen example on the internet but didn't understand them so I decided to write it as I understood it. So, I typed the code as shown below:
Code:
#include <stdio.h>
#include <stdlib.h>
int main() {
int number;
int BitNum[8], x;
[Code] ....
The problem with the code is that if binary form has 0s in it then program displays a random number instead of a 0. For example if decimal is 7, it should print out 11100000 but it displays only 111(and some stupid numbers instead of 0). I have tried to solve it but failed.
View 7 Replies
View Related
May 28, 2014
One of the questions requires writing up a code, that converts Fahrenheit scale to Celsius scale.
The relation between temperature in ◦ C and ◦F is given by the formula:
◦C = 5/9 . ( ◦F - 32 )
Write a program that prints a table (just two columns without any borders) with temperature in ◦F and ◦C for temperatures between 0 and 300 ◦F in steps of 20◦. Compile and run your program. I wanted to approach this problem via arrays and for loops, and I wrote up this
Code:
#include<stdlib.h>
#include<stdio.h>
int main() {
// begin main()
// units
double[] celsius = new double[ 16 ];
double[] fahrenheit = new double[ 16 ];
[Code] ....
Now when I'm trying to compile that, the compailer throws an error which makes absolutely no sense to me.
Code:
fahrenheitCelsius.c: In function ‘main’:
fahrenheitCelsius.c:18:9: error: expected identifier or ‘(’ before ‘[’ token
double[] celsius = new double[ 16 ];
[Code] ....
View 7 Replies
View Related
Jun 12, 2014
I wrote a program that converts Binary code to Grey code. It works, but I feel like it's highly inefficient. I've also been trying out Project Euler, but I seem to always turn to using vectors whenever solving a problem.
/* Binary to Grey Code Converter */
#include <iostream>
#include <vector>
using namespace std;
// Global Variables (I'd like to not use them because I've been told it's bad practice)
static int numDigits;
int digit;
vector<int> bin;
[Code] .....
View 1 Replies
View Related
Sep 1, 2014
I need to convert a string into a Font object. I'm trying to use the Font Converter but I don't see support for the font Style. I need to save a font to a string and back again using the font name, size and style.
Font font1 = (Font) converter.ConvertFromString("Arial, 12pt");
View 1 Replies
View Related