C++ :: How To Manipulate A Whole Array As A Single Integer
Mar 22, 2014
here i have an assignment, creating a longInt class and using it to calculate large numbers, i dont have a clue how to manipulate a whole array as a single ineteger.
I am supposed to make a histogram. I succeeded in generating the integers for the histogram. But what I want to do is instead of displaying numbers in the console, I want something like "*" displayed for every integer there is in an array. It should look something like this.
As far as I understand, in some way I need to identify the integer in the array and for every single one of them I need to insert the symbol. I don't know how to identify it.
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1{ class Program { static void Main(string[] args) { diceHistogram();
Write a program that reads four integers from a file ‘input.txt’.
The program will then create a single integer number from the four integers. The output of the program will be the single number and single number + 600.
#include <iostream> using namespace std; int main () { int number , a; cout<<"enter en integer number"; cin>>number; cout<<"add 600 to the number" cin>>a=number+600; return 0; }
Essentially what I need to do is take a text file, ("input.txt"):
4 4 1 0 0 1 1 1 1 1 0 0 1 0 0 0 1 0
And take the first two values on line 1 (4, 4) and use them as length and width. Number of rows: 4 Number of columns: 4
Then I need to print out the matrix and further manipulate it. I need to find the sum of the 1's per column and then take that number and replace each 1 with the 1's in each column.
The part that's mostly troubling me is that my instructor will be giving me the input file with random values, so I don't know what the matrix dimensions will be.
I can read the 2D array but can't seem to use it after. I need to find a way to skip the first line, and then read in the matrix and be able to use it mathematically to add up each column.
Create an application to manipulate an array of student record objects. A student record will consist of a name (first, middle, and last), an ID number (9 numeric digits, cannot be more or less), an address (street, city, state, and 5 digit Zip code), and a phone number (3 digit area code and 7 digit number). The application will support an array of students. The user will be allowed to enter records from the keyboard, sort records by either name (last, first, middle) or by ID, save the records to a disk file (name supplied by user), and read the records from a disk file (name again supplied by user).
Create a fixed length string that must check that the length of the string is the required length. The fixed length class should be done as a template with the number of characters as the template argument. From this fixed length string, derive a class to hold digits of a fixed length.
Create component classes as necessary to use together to implement the student record class.
Use either the array template created in an earlier lab to handle the array or you may use the vector class from the STL to handle the array of student record objects.
The maximum number of students will be 25 (it may be less).
I need to sort this and I know how to do it. But I need to sort it again with the highest value in the first row and keep all information in that row paired with the name . So
Lincoln 120 300 400 Parks 100 500 250
Parks 100 500 250 Lincoln 120 300 400
I need so swap this whole rows. I'm using dynamic array. So my question is Do I have to do a bunch of temps to move them? Or is there a way to move the whole int array row as a single unit?
I am trying to assign the integer value to unsigned char array. But it is not storing the integer values. It prints the ascii values. Here the code snippet
The values which are stored in uc[] is ascii values.I need the integer values to be stored in uc[]. I tried to do it with sprintf. but the output is not as expected. if I print the uc[i] it should diplay the value as 0,1,2....99.
I wrote a code which checks if there are any single numbers in an array.e.g.In the next array there is a single number - "3" 4 1 4 3 4 1..Here is an array which doesn't have single numbers in it: 4 1 4 3 3 1
Code: #include <iostream> using namespace std; int single (int arr[], int size) { int couple=0;
[Code]....
First I thought to double the number of couples I'll get from my search and find some connection to the length of the array, but it hasn't worked out (signed red).
I am trying to read in player names (ex: first last) from a text file into the people[].name data struct. I can successfully read in my card file, but I cannot get this to work. I get a seg fault. I believe this is because nothing is actually being read in for my while loops. I can't use std::strings so these must be c-style strings aka char arrays.
// deck of cards // below are initializations #include <iostream> #include <fstream> #include <ctime> #include <stdlib.h> #include <string>
using namespace std; //globals const int maxCards = 52;
My assignment is to write a binary calculator that works with floating point for simple math (+,-,x,/). How to do this. the binary numbers need to be from the user.
I've come to a point where I want to manipulate an image file at run time or with pre-determine sizes and have to be applied when the windows is moved or through in program options.
I know I can do the applying part. However I am a little unsure of how to tackle the image manipulation. I want to make it so that it is not os dependant. So I know I can not rely on any os functions. The only other thought that came to mind was to deal with the video card itself.
So the main question after all of that is said and done. How is c++ able to interact with the video card directly for images? Or if there are existing function I can use. How do they do that? If I can use existing function I would like to be able to manipulate it myself.
How I can manipulate certain strings. This program here is supposed to randomly scramble any word/sentence input. However, I notice that even the empty spaces get moved; is there any way to stop that from happening? I would want the empty spaces to stay in their input positions.
I need a translate (in both directions) all primitive types, into char[] (will be stored in string)
I understand how to manipulate integral types with bits and I cant just cut them down and shift them, but float and double don't work with this manipulation. So, how I can create a perfect bit copy of float and double?
int i = 0xFCED03A4; //Random number char c[4]; c[0] = ((i >> 3) & 0xFF); c[1] = ((i >> 2) & 0xFF); c[2] = ((i >> 1) & 0xFF); c[1] = (i & 0xFF);
[Code]...
This is basic stuff but I need an equivalent for float and double types, and it needs to be a perfect BIT copy, not value copy.
I'm trying to write a program that manipulates a doubly linked list. My professor wants it to have two structs, one called Node (containing the data, and pointers to the next and previous nodes) and one called DLList, which contains the nodes for the head and tail (which is then passed to all of my functions).
I'm a little confused how to access the head and tail, for instance, if I want to initially set them to null in the main function (he emphasized the need for this), or to use them in my functions. I've tried a lot of variations to call the head and tail, but I keep getting told that head and tail are undeclared in the function.
How might I access my head and tail, for instance in a main function, when they're defined like this? (I took out all of the logic in my functions for clarity)
I made a program that can use a function to manipulate data from a list class. The program is very basic and I think the error makers may be obvious to some of you. I just wanted to find it without having to scrap my program. It doesn't generate a compile error but it announces a memory error while it is running. I use visual studio 2012, the program is an exercise from a c++ book.
list.h #ifndef LIST_H_ #define LIST_H_ typedef double Item; const int MAX = 10; class List
Write a program using user-defined function which accepts an integer array and its size as arguments and assign the elements into a two dimensional array of integers in the following format: If the array is 1,2,3,4,5,6, the resultant 2D array is
I am trying to concatenate two words from a file together. ex: "joe" "bob" into "joe bob". I have provided my function(s) below. I am somehow obtaining the terminal readout below. I have initialized my memory (I have to use dynamic, dont suggest fixing that). I have set up my char arrays (I HAVE TO USE CHAR ARRAYS (c-style string) DONT SUGGEST STRINGS) I know this is a weird way to do this, but it is academic. I am currently stuck. My file will read in to my tempfName and templName and will concatenate correctly into my tempName, but I am unable to correctly get into my (*playerPtr).name.
/* this is my terminal readout joe bob <- nothing is put into (*playerPtr).name, why not? joe bob joe bob seg fault*/ /****************************************************************/ //This is here to show my struct/playerInit
I am having problem in writing the code for the problem "To assign the elements of 1-D integer array into 2-D array of integers such as if the array is 1,2,3,4,5,6 The resultant 2-D array should be like :
I have a problem concerning transforming int array into bmp image. I wanted to add a post in this topic: [URL] .... , but unfortunately it is closed. Actually I have a question concerning the code written by Duoas. I have a function which takes values from the file and I want to convert it into bmp with the use of Duoas code. I do it like that(it's Duoas code + my load and main function) Is it something wrong with how I do it or it's rather sth wrong with the file.
It compiles without errors but when I run it: core dumped.
According to gdb debugger problem is here: double hue = (intarray[ row - 1 ][ col ] - min_value) * granularity; programs stops, segmentation fault ...