C :: Declare Two 1-dimensional Parallel Arrays Of Integers That Will Hold The Information Of Up To 10 People
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?
For the past couple of weeks I have been working on a template to hold two-dimensional arrays. Right now I am puzzling over an indexing question.
There are many places in the template where I would like to use initializer_lists to refer to user-specified row and column ranges, particularly in member function arguments. A typical example would be a member function whose declaration would be along the lines of:
Code: Array<Type>::some_function(std::initializer_list<int> columns, std::initializer_list<int> rows); which could get called via
Code: arrayInstance.some_function({3:4}, {5:8});
It would be really nice to be able to use Matlab-style indexing to specify the last column, or the last row, in the Array object -- along the lines of
Code: arrayInstance.some_function({3:4}, {5:END}); where END takes the value -1, and can be defined in Array, or somewhere else.
The way I have tackled this so far was to write myself an Indices PODS class with two elements to hold start and finish values, and a constructor-from-initializer_list that looks something like this:
Code: Indices::Indices(std::initializer_list<int> range, int replace_value) { int const *it = range.begin();
So the elements of "range" give the values of Indices::start and Indices::finish -- but if either of them are entered as END by the user, they will be replaced by replace_value. (The default value of replace_value is END, so Indices::start and Indices::finish will never change if it is omitted.)
I also defined an Indices::endset(int) function to do the same thing for existing Indices objects:
Code: Indices::endset(int replace_value) { if (start == END) start = replace_value; if (finish == END) finish = replace_value; } Using Indices::endset, you can code up Array::some_function by modifying the above signature to something like
Code: Array<Type>::some_function(Indices columns, Indices rows) { columns.endset(this->M); rows.endset(this->N); ... }
This does work, and I've been able to use it in practice. However, it is klutzy. What I would really like to be able to do is have the Indices constructor handle value-replacements in "columns" and "rows", instead of needing to put calls to Indices::endset in every single Array<Type> member function that uses this approach.
The basic problem is that, when Array<Type>::some_function is called, there is no easy way of inserting Array<Type>::M and Array<Type>::N into the optional argument of the Indices constructor when "columns" and "rows" are being built.
The Indices class needs somehow to get access to these, and know which one is being used, M or N. So it needs to have some sort of deeper connection to Array<Type>, but I don't know what that connection should be.
I need to be able to make matches from the data i input, and also classifying between male and female. matches for person with specific traits (not one in the program) i really tried for the first part and now the rest is mentally disturbing me. and also to generate a report of partners found.
#include<string.h> #include <iostream> using namespace std; char username[20]; char storedusername[20]; char password[20]; char storedpassword[20]; int loginresult; char name[20];
Basically the question is to develop an application that allows: Create an application which stores information about people, along with a task list.
The user should be able to Store people's information
Name, Age, Telephone number, Address
-Retrieve information by entering name - Remove a person's record by entering their name -Return records for all people, sorted according to an information type other than age -Enter a task which needs doing, a priority entered for its urgency -View highest priority task on the list -User should be able to remove highest priority item on the list
How to develop this application on a console command line interface style or any other style.
I am working on a number of utility functions for two dimensional arrays of integers, or matrices. However I am having a problem with segmentation faults, most likely due to errors in using malloc in functions like copyMatrix.
Code: matrix_utils.h~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //This function checks if two matrices are equal int isEqual(int **A, int **B, int n);
//This function returns one row of a matrix int * getRow(int **A, int i, int n);
//This function returns one column of a matrix int * getCol(int **A, int j, int n);
Consider a new data type, the mikesint, which can hold 9 bits.
(a) What is the largest integer that an unsigned mikesint can hold? (b) What is the largest positive integer that a signed mikesint can hold? (c) What is the largest negative integer that a signed mikesint can hold?
How can I concatenate two 2-dimensional int arrays into one larger 3-dimensional array. This question is also valid for the 3-dimensional vectors. I know the command for the one dimensional vector as:
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.
#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
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
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]
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};
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
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() {
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.
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.
I'm building a box to take in several arrays of different lengths. one group happens every 10 seconds. one of them happens every 5 seconds. this is from a weather station.
I plan to retransmit them, substantially unchanged at a lesser rate to save radio power over a serial data link. buried in groupD, I want to change a few chars before retransmit.
I don't want to go to the trouble of doing a structure for each of them since most will be resent unchanged. some entries are chars, some are decimal, some are a mix. I guess it might be convenient to further define groupD, maybe not.
what is the best way to declare the group? I want them to be contiguous since that's how they will end up in the tx buffer. Each subgroup has its own checksum, so I planned it this way to make checksum more convenient.
display the 3rd element of a two dimensional array of integers named T of size 2x5?? i don't know how to start because i'm just advance studying with array
How will you code a program that displays the maximum value in a two dimensional array of integers. the program will ask the user to input the 4x5 array?
i know how to code it. but i dont know what to do to find the maximum value. :( how to find the maximum?
I am new to programming all together but i have been writing a program in c++ and im coming up against an issue with my array.
#include<iostream> #include<iomanip> #include<string> using namespace int main () { int a ; int b ; char answer ('Y') ;
[Code] ....
I am trying to get the program to increase say year one by 1 when the condition is met i have tried
if ( a >= 70 && a <= 100 && b == 1) {grade [0][0] = 0 + 1;}
and
for (grade[0][0] = 0 ; a >= 70 && a <= 100 && b == 1 ; grade [0][0]++) {grade [0][0]= 0 + 1 ;}
Now all that i want is that the array will take the information from int a and int b and then add 1 to the appropriate part of the array . I have tried putting it in deferent places but its not working for ether. the program will run but it will not add to the array.