C/C++ :: Creating And Accessing Info From Arrays

Mar 1, 2014

I'm working on a project where I have the user enter storm data about hurricanes for multiple seasons. I need to make separate arrays for:

1. the month, wind speed, and min. press.
2. the category of the storm

What I'm having trouble understanding is how to make the software take an input, assuming from a scanf, and put it in an array. Then taking that value and output-ing it back out when needed.

So here is piece of my code. Note: Disregard the commented sections of the code, my current project is building off a previous one, where in the last project we were using loops, now we are using arrays.

case 1:
{
if (year > 0) //begins counting
{
/*num_trop_storms = 0*/ num_hurricanes = 0, year = 0, wind_speed = 0,
hcat1 = 0, hcat2 = 0, hcat3 = 0, hcat4 = 0, hcat5 = 0, hrun = 1, totalhurr = 0;
knots = 0, cummwindspeed = 0.0;

[Code] ....

In the code above, how exactly the scanf takes the inputs from the user and then stores them for me to access. So, I want my array to be 3 columns, for months , wind_speed, & minpress. The array has a undetermined amount of rows. I think if I figure out the first array, I can handle the second.

View 7 Replies


ADVERTISEMENT

C/C++ :: Creating And Accessing Index Files?

Oct 27, 2014

I'm supposed to read in a data file with fixed length records and fields, create a sorted index list in memory, and save that list to a file. Then I'm to write a second program that interactively (via the Linux command line) takes a key and the index file name, opens and loads the index file, searches for the given key using the index table, and opens and returns the correct data record.

The original file consists of a list of records with a key (int), a name (string of 8 characters max), a code (int) and a cost (double).

The RRN (relative record number) begins at 1, with the RRN at 0 representing a dummy record with only the size in the first entry.

Here is the data file I will be using.

8 blank 0 0.0
12345 Item06 45 14.2
12434 Item04 21 17.3
12382 Item09 62 41.37

[Code]....

The "File is Open" part will be replaced once I figure out what do do once the file is open, just used this message to verify that it was opening the file.

View 12 Replies View Related

C :: Accessing Arrays Using Pointers

Aug 30, 2013

I came across the below code snippet in a project and was not sure how value of variable "response" is computed. Here as we can see, pic_data holds two one dimensional arrays but "response" access both the single dimensional array as two dimensional array.

Code:

#define MAX 100
#define MAXBUF 100
u32 response;
u32 index;
}

[code]....

View 3 Replies View Related

C/C++ :: Accessing Private Arrays?

Aug 31, 2014

How do i access the private array? I tried this and it's not working. Want i want to do is create class object in main and pass the string to constructor, and set m_make, m_model to that string. Then call the member function to output that.

const int BUFLEN = 256;
// class declaration
class CVehicle
{

[Code].....

View 2 Replies View Related

C/C++ :: Accessing Elements From Arrays

Feb 9, 2014

I'm confused about accessing elements from arrays. Supposed I have an array of pointers to char:

char *names = { "John", "Rose", "Steven" };

To access one of the strings, should I use names[ 0 ][ i ], where i is an index in the set ( 0, 1, 2 ), or should I use names[ i ]? I would think it would be the first option, because this array has 1 dimension that contains others arrays, right?

View 8 Replies View Related

C++ :: Declaring And Accessing Arrays In Classes

Mar 31, 2013

We are learning how to use composition. In this project there is the Main (), resistor .cpp and .h, capacitor .cpp and .h, and filter .cpp and .h. I have 4 arrays built in the resistor.cpp that I want to print through the main(). I put the arrays in the constructor and have watched them initialize with the proper values, but as soon as the program leaves the constructor the values are wiped away and the elements are left with the value " -858993460 " in all of the them.

Here is the code:

Filter Main()
#include "Capacitor.h"
#include <conio.h>
#include "Filter.h"
#include <iostream>
#include "Resistor.h"
#include <windows.h>
#include <iomanip>

[Code] .....

View 9 Replies View Related

C++ :: File Writing - Input Your Login Info And Program Writes That Info To A Text File

Jan 30, 2013

I'm trying to make a program that you input your login info and it writes that info to a text file. Then, later on once I get my problem fixed, the program will read the info to the user. my code is as follows(the input part is a bit lengthy):

// Password Log
#include <iostream.h>
#include <fstream.h>
#include <string>
#include <time.h>
using namespace std;
ofstream login;

[Code] ....

What my problem is when I choose "Input new login info" it automatically inputs I have no clue, and calls next program.

View 3 Replies View Related

C++ :: Creating STL Queue Of Arrays?

Dec 3, 2013

Is there any possible way to create an STL queue of arrays? I tried

queue<int[]>q;

It didn't work?

View 2 Replies View Related

C :: Creating Variable Length Arrays

Oct 24, 2014

How do you prompt the user to enter the number of elements for the array and use that information to creatr a variable length array? And then how do you prompt the user to enter in a number for each element of the array and scan in the appropriate numbers? the numbers are double precision floating point.

for example,
Enter the numbe of elements in the array: 3
Enter element 0: 3
Enter element 1: -1
Enter element 2: 4

I know it starts with

int main() {
double N;
int a[size];

printf("Enter the number of elements in the array:" );
scanf("%f", &size);

//I'm pretty sure this is wrong

View 8 Replies View Related

C++ :: Creating Dynamic Arrays / Structures

Feb 7, 2012

We are supposed to create a menu with an option to add a car (make, model etc) to inventory. I have the structure format set up as far as adding the car, but I am stuck on how to make it a dynamic array of structures or whatnot (I'm not really sure on what I'm trying to do in the first place!) Basically, the user can choose to add a car and its info in. How do you set up the array to add whatever number of cars is needed? Will it be able to add more cars should the user come back to the program later?

This is the instruction of this portion of the project :

Menu Application
Add a car to inventory
Prompted to add
Make, Model and Year, Color, Miles, Price
Finish (adds the car to the file)
Cancel takes you to the main menu

View 1 Replies View Related

C++ :: Creating Table Of Arrays - Find Maximum Value And Sum

Aug 12, 2014

I have an array of "2,3,4,5,6,9,10,11,12,99". I need to create a table of this which i have done using case

1. Find the maximum value of the array
2. Find the sum of the first and last element of the array
3. Swap the adjacent pairs of arrays
4. Display the values in array
5. Quit

Please enter choice:

but when i try running the program i did i keep having the break or continue pop up ....

#include <iostream>
using namespace std;
int main() {
int choice;
int number[10] = {2,3,4,5,6,9,10,11,12,99};

[Code] .....

View 6 Replies View Related

C++ :: Creating Crystal Lattice - 3 Dimensional Arrays

Apr 14, 2013

I receive unexpected outcome in my program. Instead of getting all combinations of 0, 1, 2 (i.e. 000, 001, ..., 222) I get only 000 001 002 010 011 012. The idea of the progarm is to create a crystal lattice. Each atom of the lattice has 3 coordinates (x, y, z). That's why I create class Atom. Then I create 3-dim array of the type derived from class Atom. Now each element of the class will represent an atom.

Code:
#include <iostream>
using namespace std;
class Atom {
public:
float x, y, z;

[Code] .....

View 2 Replies View Related

C :: Creating Match-3 (Candy Crush) Game Using Arrays

Mar 6, 2015

I'm supposed to create a "game" that is similar to Candy Crush or Bejeweled. The assignment takes in a .txt file that contains a matrix of values from 1-5 and then assigns each value to a spot in a [10][10] array. Then an Escape Code function prints out colored pixels in place of the number values for each spot, creating a "game board" looking output. Finally, the program is supposed to look for any matches of 3 same-colored pixels and replace them with a white pixel and "XX". Then the program prints the corrected game board with the matches X'd out.

I have it mostly coded, but I've encountered a couple of issues.

1.) I am supposed to label the columns and rows 0-9, and while I have no problem coding the labels for the columns using printf( ), when I try to print the row labels I get a random string of numbers.

2.) I replaced the matches with white pixels by reassigning the value in the array to 7, for which the ANSI Escape Code is white. However, I'm unsure about how to print the "XX" in the same spot.

Here is the input(.txt) file and the output of the program so far:

And here is what I have coded at this point:

Code:
#include <stdio.h>
void printEscapeCode(int c);
int main(void)
{
/* Declare an image array to be gameboard */
int gameboard[10][10];
/* Declare variables and load in how many rows and columns */
int Nrows;
Nrows = 0;

[code]....

View 2 Replies View Related

C++ ::  2D Arrays - Creating Virtual Creatures By Storing A Letter Into Random Position In Array

Nov 3, 2014

So first I have to display a 2D array with all 0s, which is pretty easy.

#include <iostream>
using namespace std;
int main (){
int array[5][5];
for(int a=0; a<5; a++){
for(int b=0; b<5; b++){
array[a][b] = 0;

[Code] ....

So this displays

0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0

Next, this is where it gets confusing. I have to create a virtual creature by storing a letter into a random position in the array (the array can be up to 20x20 in size). Then make a function that searches the array for creatures, so it would search for that character. When it finds a creature, it should randomly decide to either move the creature to an adjacent position, or have it stay where it is. After, it should ask the user to create a new creature, or quit.

So how would I go about adding & modifying the current code to achieve what is listed above?

View 2 Replies View Related

C++ :: Transfer Info From One File To Another?

Jan 18, 2015

I need to transfer the content from the file text.txt to file sort.txt . The data in the text.txt is "struct" (info about people)but the same data needs to be sorted by the name and sent to sort.txt by using a function .

View 9 Replies View Related

C++ :: Send Info To PHP Webpage?

Jul 3, 2014

I was wondering if there was a way for me to send information, say a username and password, to a webpage via a c++ function. I was unsure how exactly to word it, but I did attempt to google it. Here is an example of what I mean.

App starts -> goes to "Https://www.my-site.com/?user=$username&password=$password" -> username/password is valid -> logs them in on desktop app

I do not know much about php, but I am assuming the ?user=$username is setting a variable, correct? I am familiar with sockets, but it seems using the above method, this could be possible without sockets, would it?

Important part:

That is the method that minecraft uses to login players, the question here is what function could I start to send the desktop app to the webpage.

EDIT:: After looking a little more I find that it is probably not possible without sockets, which is fine; however I don't know how to do it still, I would prefer to not use external libraries, such as Curl.

View 3 Replies View Related

C++ :: File Info Search?

Feb 27, 2013

I am looking for a way that I could check the information of a folder and a drive, to show the data size and storage amount (KB, MB, GB). This is so that I can compare the size of a folder to the storage capacity of a disk drive.

View 2 Replies View Related

C/C++ :: Getting Specific Info From A TXT File?

Oct 10, 2014

I'm trying to open a text file with the name "text.txt", for the purpose of only displaying in the console an specific part of the text file. For example, if I got "This is a test [TEXT] This is the message that should display [/TEXT] this is the end of the file", I want only "This is the message that should display" to be the output, the thing is that I can't imagine anyway of doing that. what I should do?

View 5 Replies View Related

C :: How To Read Info From Text File

Jan 8, 2014

I'm a beginner at programming and I'm not sure how to read in information from a text file. What I want to do is take a text file which contains around 20 rows and 3 columns of numbers, and put these into an array which can then be used for performing calculations. How do I do this? Would I need to declare the size of the array beforehand? When accessing my file, do I include the full address?

The relevant part is lines 29-33:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* this is a simpllified code using BEM equations */
main()

[Code] ....

View 13 Replies View Related

C :: Why Can't Get Info From Text File Correctly

Dec 21, 2013

the info gotten from the text file are all wrong, i can't find any problem with my code,

Code:

#include<stdio.h>
FILE *f;
typedef struct prd {
char name[30];
char code[30];
char idt[30];
float price;

[code]....

View 7 Replies View Related

C++ :: How To Search A Chemical Name Info By Symbol

Aug 28, 2014

I am completely baffled by bin file read/write and positioning. Here I wish to search a chemical name info by symbol. Here is my struct

struct chemicalElement {
int atomicNumber;
char name[118];
char symbol[3];
float mass;
};

I successfully wrote to file.dat as binary but having problem in reading and searching...here is my func...

void searchSymbol(char sym, chemicalElement chemEl[]){
ifstream binFile;
unsigned short int i=0;
binFile.open("chemicalEl.dat", ios::binary);
if(binFile.good())
cout<<"File read for search"<<endl;

[Code]..

View 5 Replies View Related

C++ :: Inheritance Info Lost In Container?

Sep 16, 2013

Code mostly speaks for itself:

#include <list>
#include <iostream>
using namespace std;

[Code]....

I added an object of class myderiv to the container, but when I retrieve it back and try to manipulate it, it's actually of class mybase. Is there any way to keep the inheritance information in the container?

View 8 Replies View Related

C++ :: Change The Version Info Of The File?

Jan 18, 2013

im trying to make a tool that can change the version of the file (.exe)

UpdateResource(hResource, RT_VERSION, MAKEINTRESOURCE(1), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPVOID) lpBytes, dwSize);

i know how to update the rcdata of the resource

my problem is i dont know what to insert to it using (LPVOID) lpBytes is it a .txt ? .rc ? is it a binary ? etc.

View 1 Replies View Related

C/C++ :: How To Add Info To Array Of Nested Structures

Dec 4, 2014

I am making a basic music library that stores information rather than files. I need to read from a .txt file the artist's name, the album name, the song name, and the song length. What I am confused about is storing the information in an array of Artist structures.

struct Song{
string songName;
int songLength;
};
struct Album{

[Code] ...

How to read the information into an array of Artists. Also, how would I be able to figure out if the artist already exists in the array when adding a song and if the artist does, add the album under the existing artist.This is how I am reading in the info:

Artist newArtist;
Album newAlbum;
Song newSong;
ifstream inF("library.txt");
while(!inF.eof()) {

[Code] ....

View 1 Replies View Related

C/C++ :: Getting Info From Binary File Into A Struct

Apr 19, 2015

Your goal is to open this struct of students (the binary file). Once open, the first job is to print out each student. Afterwards, display all students with a gpa of 3.5 and higher. Finally, display all students with the major of Computer Science or Game Programming. Be sure to title each category of items.

He gave us a .cpp file and a .h file that we're suppose to use to run the program. He doesn't want us to change his original code, except we can add the needed code to run his code (i.e. Struct & Main).

My problem is that I get an Abort() crash message in VS2013 when I try to run it. Now, in line 95 of the cpp file if I replace the char* with "", it runs fine showing the GPA with blank entries for the other print parameters. I've read the Binary Files chapter of the Pearson textbook several times and it doesn't have anything to say about working with char pointers.

Header file:

#pragma once //Professor's code
struct StudInfo //Start of my code {
char* fName;
char* lName;
char* major;
double gpa;

[Code] ....

View 7 Replies View Related

C++ :: Saving Info Like Trees And Such In A File?

Aug 13, 2013

I'm intrested in creating programs of games and such which learns while playing and saving the information for further use. For example a tic tac toe game where the program saves evry game it won or lost and creates a tree of some kind that store the information of the game and save it in a file when the program is being quit. The problem i'm having is how to save a tree in a file efficently.

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved