C++ :: Importing 2D Array - Print Out Matrix And Manipulate It

Nov 9, 2014

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.

So it'll look like this:
2 0 0 2
2 1 3 2
0 0 3 0
0 0 3 0

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.

View 1 Replies


ADVERTISEMENT

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.

View 7 Replies View Related

C++ :: Manipulate Array Of Student Record Objects

May 15, 2014

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).

View 1 Replies View Related

C++ :: How To Print Matrix

Jan 27, 2015

I wants to print matrix such that Consider that original matrix look like following

1 2 3
4 5 6
7 8 9

Now I want to print like following

7 8 9
4 5 6
1 2 3

we can use only two for loops.

View 1 Replies View Related

C++ :: Program To Print Upper Half Of Matrix

Jan 3, 2015

This is a program to print upper half of the matrix.

#include <iostream>
using namespace std;
int upperhalf(int n, int apu[n][n]) {
cout<<"The upper half of the matrix is :

[Code] ....

the compiler is giving these errors:-

sh-4.2# g++ -o main *.cpp
main.cpp:4:31: error: use of parameter outside fun
ction body before ']' token
int upperhalf(int n, int apu[n][n])

[Code] ....

I dont know where i am wrong.

View 3 Replies View Related

C++ :: Create Random Matrix And Print It Out In Text File

Feb 11, 2014

I am trying to create a random 3x3 matrix and print it out in a text file using basic functions. My code below will not compile.

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
//nxn Matrix = 3x3
const int ROWS = 3;
const int COLS = 3;

[Code] .....

View 2 Replies View Related

C++ :: MP3 Frame Header Importing

Jun 24, 2013

Code:

/* some useful headers */
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>

//my headers
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <vector>

[XCode] .....

The bit that's giving me issues is the "calculatedetails" function, where an mp3 file is opened in binary and then an array of chars is filled with the binary data.

The problem I'm having is that I want to be able to read the constituent bits of the characters in, so that I can find the mp3 frame headers (12 1's in succession)

I'm aware that the section I've added in to perform this is incorrect.

View 7 Replies View Related

C++ :: Importing Data From A File?

Mar 13, 2013

This code will show the data from the .txt file "file1" the data is (0.0 0.1 0.2 0.5 0.8 0.9 1.0)

What I'm trying to do is take these float values and add them all up and divide them by 7 (finding the average and output that) Convert it into a percent and print it in a field:

Width of 6 with 2 digits after the decimal point...

I tried doing something like cout << "the average is: " << data/7 << endl; but that didn't work. I got an error that said "/" was not an operator.

Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ifstream myfile("file1.txt");
string data;
getline (myfile, data);
cout << data << endl;
myfile.close();
return 0;
}

View 1 Replies View Related

C :: Importing / Exporting Library Functions

Feb 22, 2015

I already have this but I sense I'm missing something so I'd like to be pointed to a proper article/document on this sorta thing.

Code:
#if defined( __GNUC__ ) || defined( __GNUP__ )
#define PP_ATTR( TYPE ) __attribute__( TYPE )
#ifndef _PRAGMA
#define _PRAGMA( COMMAND ) _Pragma( #COMMAND )

[Code] .....

View 12 Replies View Related

C :: Importing Text File To Structure

Nov 21, 2013

I am trying to take a Text File mydata.txt and import it into a structure however when I try to run this code it just closes out.

Code:
#include<stdio.h>#include<stdlib.h>
#include<string.h>
#include<ctype.h>
struct hard_disk{
char name[18];
double size;

[Code] .....

View 4 Replies View Related

C/C++ :: Importing Data From TXT File And Working With It

Mar 13, 2013

This code will show the data from the .txt file "file1" the data is (0.0 0.1 0.2 0.5 0.8 0.9 1.0)

What I'm trying to do is take these float values and add them all up and divide them by 7 (finding the average and output that)

Convert it into a percent and print it in a field:

Width of 6 with 2 digits after the decimal point...

I tried doing something like cout << "the average is: " << data/7 << endl; but that didn't work. I got an error that said "/" was not an operator.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;  
int main() {    
    ifstream myfile("file1.txt");
    string data;  
    getline (myfile, data);
    cout << data << endl;      
    myfile.close();    
    return 0;  
}

View 1 Replies View Related

Visual C++ :: Importing Bare Names

Oct 2, 2012

how do I import the stripped export names (no mangling) from C code

A functions int Func()

is exported by def file to MyDll.dll

LIBRARY
EXPORTS
Func

Now if I import from another source Func by providing

exyern "C" int Func()
/lib:MyDll.lib

I get error error LNK2019: unresolved external symbol Func referenced in function main

View 1 Replies View Related

C :: How To Manipulate Binary

Oct 5, 2013

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.

View 2 Replies View Related

C++ :: Manipulate A String Into Name Of A Variable?

Feb 1, 2013

The while loop is increased by i++ each time. In the commented line I want to express.When:

i = 1 , player1.cards[j] = random;
i = 2 , player2.cards[j] = random;
void cardScramble()
{
int random;
int i = 1;
while (i <= 4)

[code]....

I tried to define it or manipulate it as a string but didn't work.

View 2 Replies View Related

C++ :: Manipulate Image File At Runtime

Oct 20, 2013

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.

View 4 Replies View Related

C++ :: How To Manipulate Certain Strings - Ignoring Spaces

Aug 11, 2013

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.

#include <iostream>
#include <string.h>
#include <ctime>
#include <cstdlib>
#include <fstream>
#include <string>
using namespace std;

[Code] ....

View 4 Replies View Related

C++ :: How To Manipulate Bits Of All Types For Storing

Aug 10, 2013

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.

View 7 Replies View Related

C Sharp :: Opening And Importing Multiple Files Into DataGridView / Database

Mar 29, 2013

I'm trying to add a function now that lets the user open 1 or more files and import them to the database and dataGridView. Now the way it is now (should) work. But when it has finished with FILE1, it won't add FILE2 as it then gives me an error that the Column Date Already exists.

My code is below

private void btnOpenLog_Click(object sender, EventArgs e)   {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.Filter = "Log Files (*.log)|*.log";
            openFileDialog1.Multiselect = true;

[Code] .....

View 12 Replies View Related

C :: Program To Manipulate Doubly Linked List

Nov 17, 2013

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)

View 1 Replies View Related

C++ :: Function To Manipulate Data From A List Class

Feb 3, 2013

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

[Code] .....

View 4 Replies View Related

C# :: Creating X Number Of Textboxes At Runtime And Manipulate

May 6, 2014

i need to creat a program in la user give me "X" number and creat the textbox and y need sum all textbox

int t = Int32.Parse(txtbano.Text);
for (int i = 0; i < t; i++)
{

[Code]....

View 8 Replies View Related

C++ :: Using OOP To Implement Matrix Class That Provide Basic Matrix Operations

Mar 27, 2013

i want to know how i can solve this question? do i need to create a class or write the program codes.

View 12 Replies View Related

C :: Array And Matrix Check

Sep 24, 2013

1. Input an dimension and elements of an array from the keyboard. Count the odd elements of an array and that number join to variable K, then sort the last K elements in decreasing order.

Code:
#include <stdio.h>
main ()
{
int A[100], i, n, j, K = 0;
printf ("Type in the dimension of an array:
");
scanf ("%d", &n);

[Code]....

View 7 Replies View Related

C++ :: Converting 1D Array To 2D Matrix?

Jan 12, 2015

Q.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

1 2 3 4 5 6
1 2 3 4 5 0
1 2 3 4 0 0
1 2 3 0 0 0
1 2 0 0 0 0
1 0 0 0 0 0

Ans.

#include<iostream>
using namespace std;
int two_print(int x, int one[999]) {
int two[999][999], q=x, z=x;
for(int k=0; k<x; k++) {
q--;

[code].....

View 2 Replies View Related

C++ :: Accept Matrix As Argument And Display Its Multiplication Matrix

Jun 1, 2014

I just want to know the code of the program: Write code to accept matrix as aurgument and display its multiplication matrix which return its multiplication matrix.

View 1 Replies View Related

C++ :: Copy To Make 1D Array A 3D Matrix

Jun 3, 2013

I'm trying to copy my array 'block' to a 'dummy' 3D matrix so I can take out some arbitrary smaller matrix. Shouldn't this be possible with std::copy, where I'm certain the number of elements in the 1D array are equivalent to those in the dummy?

int dummy[210][210][1000];
std::copy(&block[0], &block[block.size()], &dummy);

View 2 Replies View Related







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