C/C++ :: How To Create A Table With Variables From Multiple Structs
Aug 1, 2012
I would like to create an array of struct variables inside a table to avoid using many if/else and/or switch/case statements. I have attached a simple example of what I am trying to do, it doesn't work. For the table "sTablePtr" I see different values than what I set, when I dereference it with a "&" it just shows me the addresses of the variables. However at the end, when I do print out the values, by just using the structs themselves, they print out the values correctly.
My structure declarations must remain a pointer. To be clear, what I am trying to do is have sTablePtr[i] show me the correct values I set, in this case I want the for loop to print out 1, 2 and 3. If there is a different way of doing this, I am open to it as long as I can use a table of my struct variables to avoid many if statements.
#define MAX_CNT 3
typedef struct {
int nNum;
int nCnt;
}sDummy1;
I need to create a dynamically allocated, growable, queue of structs. I tried my best to do as much as I could. What's holding me up is the queue aspect of it.
I am having a lot of trouble being able to get data from a file and input it into given structs and arrays of structs and then outputting the file. We are given a file that contains 96 lines and looks like this:
Arzin, Neil 2.3 6.0 5.0 6.7 7.8 5.6 8.9 7.6 Babbage, Charles 2.3 5.6 6.5 7.6 8.7 7.8 5.4 4.5
This file continues for 24 different people and then repeats with different scores (the second line). The first number, in this case is 2.3 for both people is a difficulty rating. The next 6 numbers are scores.
We are given this data in order to set up our structs and arrays and my code:
#include <iostream> #include <fstream> #include <iomanip> #include <string> #include <cmath> using namespace std; int main () { ifstream inFile; inFile.open("C://diveData.txt);
I am trying to make a table class that will be able to have multiple columns of data. I want it to have something to hold data (I was using a 2D vector for only one data type) in it, somewhat like a pair, but for any number of data types. The class is a template to make it generalized.
I have looked a little at variadic templates, but I don't know how to declare the vectors for each data types then.
I want to create a proper visible table with boundaries that contains boxes and each box receives a value .I don't know where to start from.i have an idea of using matrix for entering values in each box of table,but how to create lines and boundaries ?
I am trying to get variables that are global to multiple files. I have mananged to make constant variables that are global but maybe not in the best way. In the header i have the constant variables being defined:
const int variable_Name = 5;
And the cpp file:
#include <iostream> using namespace std; #include "vars.h" int main ( ) { cout << variable_Name<< endl; system ("pause"); return 0; }
Is there a better way to do this and to make the variables able to be changed within the cpp files.
I have this assignment where I have to create a map based hash table for a sparse matrix. The professor has provided some code and I'm supposed to fill in parts of it to make it work.
He has given us a class sparseMatrix which we need to provide a hash function for. This hash function is to be defined in a Class TupleHash which is inside sparseMatrix. I think I got that part down. What is really confusing me is what he has done with some typedefs.
For one of them I had to declare an unorderd_map that maps a struct Tuple on to the class template argument Object. I did that like so:
This is giving me a world of unintelligible error messages. This is how it starts.
In instantiation of 'struct std::__detail::__is_noexcept_hash<int, sparseMatrix<int>::TupleHash>':| recursively required from 'struct std::__and_<std::is_default_constructible<sparseMatrix<int>::TupleHash>, std::is_copy_assignable<sparseMatrix<int>::TupleHash>, std::__detail::__is_noexcept_hash<int, sparseMatrix<int>::TupleHash> >'|
Write a program that creates and displays a table of temperature conversions. Get the starting temperature from the keyboard in degrees Celsius (do not allow input of a value below absolute zero). Also get an integer value to represent the number of degrees to increment for each of a 20 row table (do not allow the increment value to be less than one. The first column will be a row number starting with one, follow by the Celsius value and then the conversions into Fahrenheit, Kelvin, and Rankine. Be sure that all columns are neatly right aligned for a variety of inputs.
Thats what i wrote so far:
#include <iostream> #include <iomanip> using namespace std; int main() { double C,F,K,R,n,a; cout <<"Enter starting temperature in Celsius: "; cin >> C; [Code] ....
Thats what the instructor looking for:
Enter starting temperature in Celsius: -500 ERROR: Temp must be >= -273.15: -273.15 Enter increments in degrees Celsius: 100
I am writing a bit-check function just to make it easier on myself to check status flags in my classes. I use char variables and each bit represents something on or off. Since I have numerous classes that will use this functionality, it makes sense to write and compile the code only one time rather than for each class. I was thinking of writing the function and including it as a "friend" function to each class that needs it. Is that an appropriate way to do it?
It seem to store the entire line in userID including the ":". I want to ignore the ":"'s and store everything in between in respective varibles in the order specified above.
So first string in userID, then ignore the :, then second string in name, and ignore the next :, and so forth.
Write a program to create an output file containing a customized loan amortization table. Your program will prompt the user to enter the amount borrowed (the principal), the annual interest rate, and the number of payments (n). The payment must be rounded to the nearest cent. After the payment has been rounded to the nearest cent, the program will write to the output file n lines showing how the debt is paid off.
Code:
#include <stdio.h> #include <math.h> int main (void) {
I want to put my socket programming example of how it can support multiple ports. I want to make the process more requests from distributing particles to create non-blocking structure
It seem to store the entire line in userID including the ":". I want to ignore the ":"'s and store everything in between in respective varibles in the order specified above.
So first string in userID, then ignore the :, then second string in name, and ignore the next :, and so forth. How I can accomplish this?
#include <cstdlib> #include <iostream> #include <math.h> #include <cstdio> #include <stdio.h> #include "dp_lib.h" int main() { int A =1;
[Code]...
im new to coding but ive written this code for an assignment and it creates 2 sine waves and adds them together but i want to be able to create a range of different sine waves at different frequencies and play them one after the other like in my code,but with the end result being that i would like each sine wave to represent a different note, so when your on the the console screen the user will be able to choose from a select number of notes and input them in any order so that the WAV file produced plays the sine waves in the order the user chooses so they can make a simple tune. but my code only plays it in the order it is in the code
i am trying to create a program for multiple windows. Here is my code
#include<Windows.h> // Store handles to the main window and application instance globally. HWND ghFirstWnd =0; HWND ghSecondWnd=0; HWND ghThirdWnd=0; HINSTANCE ghAppInst=0;
[Code]...
problem is when i try to execute the code it just say create window1- failed!!
I am trying to create a multiple choice quiz so I can learn the menu at my new job, while doing a side project but I am having a warning when outputting. Speaking of side projects, is this a kind of side project people are looking for on a resume?
So im trying to create a quiz using c++ that incorporates three different types of questions. These are the standard one answer question, true false questions and multiple choice questions.
How to create the true false and multiple choice questions?
I am trying to create a simple interface on console to allow to input some values to some variables. For ex:
int main() { double a = 1.5; double b = 2.5; double c = 3.5; string x;
[Code] ....
However, I want these three to display at the same time (now they display one by one), and in the console window I can move the cursor between input place of a, b and c with "arrow key" of keyboard.
I am having an issue with my sort function. This is one part of the Hash table program. The main issue is that I am trying to sort the pointer table after all of the values have been entered. The ptr_sort function is not a class function and so I am therefore unable to use the class variables psize and pTable. Is there another way I should be trying this? it is a Vector should I use the sort() function from the vector class in STL?