C/C++ :: Iterate 2D Matrix In Order To Exchange Columns And Rows Using Pointers

Jan 19, 2014

I am trying to iterate a matrix in order to exchange rows and columns element by element. Although the function that exchanges the rows has come out well, i don't seem to figure out how to do the same on columns.The columns switch for a matrix like

1 2 3
1 2 3
1 2 3

if i try to switch column 3 and 2,is:

1 3 2
1 3 2
1 2 3

Here are both of the functions:

void interchange_rows(int *p,int n,int r1,int r2){
    int temp;
    for(int i=0;i<n;i++){
            temp=*(p+r1*n+i);
            *(p+r1*n+i)=*(p+r2*n+i);
            *(p+r2*n+i)=temp;
   
[Code] ......

View 1 Replies


ADVERTISEMENT

C/C++ :: Program To Sum Rows And Columns Of A Matrix?

Apr 23, 2014

Im using apmatrix and im inputting values into a 4 by 4 matrix and im getting all these errors that have nothing to do with my cpp file so im guessing its apmatrixies fault. Also I put in the cpp and header file of both apmatrix and apvector into my project folder. Heres my code:

// Libraries
#include "apmatrix.h"
#include <iostream>
//cout, standard output
// <<, stream insertion operator

[code]....

My errors are:

error C1189: #error : The C++ Standard Library forbids macroizing keywords. Enable warning C4005 to find the forbidden macro.c:program filesmicrosoft visual studio 11.0vcincludexkeycheck.h2421TheMatrix

4IntelliSense: identifier "EMIT" is undefinedc:Program FilesMicrosoft Visual Studio 11.0VCincludeyvals.h4911TheMatrix

and a bunch are repeated

View 1 Replies View Related

C :: Creating Rows And Columns

Mar 6, 2015

how to make the it all work later...but in the mean time how can i get this to display this? Note it has to be made using as a console program. The "Description" and "Cost/ib" collums will be referenced through use of a header file. all else is done by user input and calculations.

View 2 Replies View Related

C/C++ :: Columns And Rows For Loops?

Feb 26, 2015

I'm having trouble trying to get my loop program to display multiples of 4 in rows and columns. My objective is to print multiples of 4 that are less than 100 in a 4 by 4 format.

So far when I write the code I get 4 8 12 16 20 .... 96 all on the same line.

This is what I expect the code to look like if done correctly.

4 8 12 16
20 24 28 32
36 40 44 48
52 56 60 64
68 72 76 80
84 88 92 96

This is code that I have so far.

#include <iostream>
using namespace std;
int main(){

[Code]....

View 4 Replies View Related

C++ ::  how To Count Rows And Columns From File

Sep 2, 2014

So I made a text file which goes like this

word word word word
word word word word word word word
word word word word word
word word word word

(word is actually word I just didnt type them)

Now i figured out how to get the rows to work

#include <iostream>
#include <fstream>
#include <istream>
#include <stdio.h>
int main()
{
FILE* fp;
int countLines = 1;
int i;

[Code]...

I cant figure out column to work... Is it the same method cause im getting confused a lot!

View 12 Replies View Related

C++ ::  Columns And Rows In Text File

Dec 21, 2014

How i draw such a thing in .TXT file using file handling. This output must be in columns and rows and in well arranged form.

No. Name Roll No. Physic Math Compuer Science Islamiyat Pak Studies Average Grade
1 Student Name 12345 50 60 70 76 90 81 A
2 Student Name 12345 55 52 50 80 58 55 C
3 Student Name 12345 85 66 90 88 77 75 B
4 Student Name 12345 40 70 91 45 56 85 A
5 Student Name 12345 30 80 80 55 93 45 D

View 3 Replies View Related

C++ :: How To Get Sum Of Rows And Columns In 2 Dimensional Array

Aug 2, 2014

Here's my code for adding the rows and columns. My problem is that my program displays an incorrect output.

main() {
int a[20][20],r,c,y,x,sum=0,rn,cn,cs=0,rs=0;
cout<<"Enter number of columns : ";
cin>>cn;

[Code] .....

This should be the output
Enter number of columns: 4
Enter number of rows: 3
Enter twelve numbers: 9 2 3 4 2 3 1 2 5 6 7 8

The numbers are:
9234
2312
5678
Sum of number 1 column is: 16
Sum of number 2 column is: 11
Sum of number 3 column is: 11
Sum of number 4 column is: 14
Sum of number 1 row is: 18
Sum of number 2 row is: 8
Sum of number 3 row is: 26

View 6 Replies View Related

C/C++ :: How To Sort A Table By Rows / Columns

Oct 5, 2014

I am trying to sort a Report Table by which the user can enter any column or row number and output the results. And also sort by names as well. And from my code

#include "stdafx.h"
#include<iostream>
#include <string>
#include<iomanip>
using namespace std;
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time */

[Code] .....

I know I need to start somewhere with a void function and put in a selection sort.

View 1 Replies View Related

C++ :: How To Set Pointer And Iterate Through A Matrix

Aug 8, 2012

How can a set a pointer , to a matrix example matrix[20][20] and iterate ( loop ) in each row first sort of X first and then Y through it using the pointer , how to setup dynamic allocation

through pointer = new matrix[20][20]

and finally call delete on pointer when done with the matrix.

View 4 Replies View Related

C++ :: How To Modify A Program So That It Accepts Columns Instead Of Rows

Feb 4, 2015

I have a N queens (actually 8 queens to be specific) program that accepts the numbers in order by row. I need to get it so it accepts the numbers in order by column. At first glance I thought it was just one space different, but it turned out not to be and how to get the one space difference in there. My current code (which I'm aware isn't doing the column accepting right) is:

Code:

#include <iostream>
using namespace std;
int main() {
int board[8];
cout << "Enter the columns containing queens, in order by column: ";
for(int i = 0; i < 8; ++i) {
cin >> board[i];

[Code]...

What the output should be:

Code:

Enter the rows containing queens, in order by column:

7
6
5
3
4
2
1
0

.......Q
......Q.
.....Q..
...Q....
....Q...
..Q.....
.Q......
Q.......

What it is:

Code:

Enter the columns containing queens, in order by column:

7
6
5
3
4
2
1
0
........Q
.......Q.
......Q..
....Q....
.....Q...
...Q.....
..Q......
.Q.......

View 5 Replies View Related

C++ :: Print Square Roots Of Numbers With Rows And Columns

Mar 12, 2013

this is what i have so far

#include <iostream>
#include <cmath>
using namespace std;
int main () {
int v;

[Code] ....

im trying to get the program to print this as an example if the user enters 5 (the rounding of the decimal is optional).

1 1.41 1.73 2 2.24
1 1.41 1.73 2
1 1.41 1.73
1 1.41
1

why its not reading my for loop for rows its only doing columns ...

View 4 Replies View Related

C++ :: Program Inputs The Number Of Rows And Columns And Asks For The Entries

Feb 7, 2015

I am writing a program that deals with 2d arrays. The program inputs the number of rows and columns and asks for the entries. When the program run and compiles it works perfectly until it outputs then it gives me a warning.

Here is my code:

#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int row1=0,col1=0,i,j;
//int a[row1][col1];
int** a= new int*[row1];

[Code]...

I am learning how to do this before I can move on so it can read a text file of numbers.

Also I am having problems with ////delete [] a[];///// I took it out because it made my code compile and run but when I add it in, it gives me an error:

matrixtesting.cpp|56|error: expected primary-expression before ']' token|

I know this expression is suppose to deallocate the array.

View 7 Replies View Related

C Sharp :: How To Select Specific Rows And Columns From A Text File

May 29, 2014

I want to select three columns from my text file i.e. Empl No, Start Date and Created Date. After selecting this, I want to insert the data into a database.

I have attached a copy of the text file.

I have the following code so far:
 
 if (File.Exists(filename))
                {  
                    string[] lines = File.ReadAllLines(filename);
                    for (int y = 0; y < lines.Length; y++) {    
                        Console.WriteLine(lines[y].ToString());  
                    }    

How do i select specific details for each employee

View 1 Replies View Related

Visual C++ :: Multidimensional Array Having 3 Rows And 8 Columns - Bubble And Selection Sort

Feb 19, 2014

You will write a program that uses a multidimensional array having 3 rows and 8 columns and sorts each of the rows using both a bubble sort and a selection sort.

You must declare the array inside of main. You will have a for loop containing the calls to bubbleSort and selectionSort. You need to pass into function bubbleSort and selectionSort the following: 1) each column of the multidimensional array, 2) the size of the column, and 3) a particular row number of the multidimensional array to be used for printing out the "pass" shown on the following pages.

I keep getting an error that the identifier for bubbleSort and selectionSort is not found. (Error C3861)

Also, I feel like I'm missing something in int main() to get it to sort properly.

Code:
# include <iostream>
using namespace std;
int main() {
const int SIZE1 = 3;
const int SIZE2 = 8;
int arr [SIZE1][SIZE2] = { { 105, 102, 107, 103, 106, 100, 104, 101 },

[Code] ....

View 1 Replies View Related

C++ :: How To Use Dynamic Memory Allocation And Pointers To Iterate Through The Arrays

Dec 21, 2014

I need to use dynamic memory allocation and use pointers to iterate through the arrays that I have already in this program. I am lost, nothing I do works and where to use the pointers. I am just looking for a push in the right direction so I can finish this project and how I can implement pointers in my program.

#include <iostream>
#include <string>
#include <cstdlib>
#include <iomanip>
#include <stdio.h>
using namespace std;

[Code]...

View 1 Replies View Related

C/C++ :: Swap Value Of Two Rows In A Matrix Among Themselves

Mar 21, 2015

I want to swap the value of two rows in matrix among themselves, the index of rows are user defined.

void swapRows(int matrix[M][N], int m, int n, unsigned short R1, unsigned short R2) {
for (int i=0; i<m; i++) {
for (int j=0; j<n; j++) {
//dunno what to put in here

[Code] .....

View 6 Replies View Related

C/C++ :: Program That Reads 3-by-4 Matrix And Displays Sum Of Columns

Nov 18, 2014

I'm not sure why Im getting a wrong Sum. of the Columns.

Write a method that returns the sum of all the elements in a specific column in a matrix using the following header:

double sumColumn(const double m[] [SIZE], int rowSize, int columnIndex)

Write a test program that reads a 3-by-4 matrix and displays the sum of each column. here is a sample run:

Enter a 3-by-4 matrix row by row:
1.5 2 3 4
5.5 6 7 8
9.5 1 3 1
Sum of the elements at column 0 is 16.5
Sum of the elements at column 1 is 9.0
Sum of the elements at column 2 is 13.0
Sum of the elements at column 3 is 13.0

#include <iostream>
using namespace std;
const int SIZE = 4;
int rowSize=3;

[Code].....

View 1 Replies View Related

C/C++ :: Array Implementation Of Stack To Reverse Columns In Matrix

Dec 1, 2014

I had the following question in my exam paper and only got 1.5 out of a possible 6 marks. This is the question:

Given the Matrix class:

class Matrix {
public:
Matrix(unsigned r, unsigned c);
Matrix(const Matrix<T>& rhs);
~Matrix();
const Matrix<T>&operator=(const Matrix<T>& rhs);
[Code] ....

Use the linkedStackType class (Array implementation of stack) and write a function reverseCols to reverse the order of columns in the matrix. Note that reverseCols is not a member function of the Matrix class therefore only the public interface of matrix can be used.

//Implementation of Stacks as Array
template<class Type>
class stackType: public stackADT<Type> {
public:
const stackType<Type>& operator=(const stackType<Type>&);

[Code] ....

What is the correct solution must be to reverse the columns of the matrix?

View 1 Replies View Related

C :: Array Add Total Rows And Total Columns

Apr 16, 2013

Code: i am trying to display the information in the array as a table and add the total rows and the total colums separately

#include<stdio.h>
int main(void)
{
int row, col;

[Code].....

View 1 Replies View Related

C :: Sort Matrix Such That It Has Value In Ascending Order

Sep 29, 2013

Trying to sort matrix such that it has value in ascending order.

But outcome is coming :

Code:
Matrix after sorting :
2,2,2,2,
2,2,2,2,
2,2,2,2,
2,2,2,2,
Can't find whats wrong.

[Code]....

View 2 Replies View Related

C++ :: Matrix Multiplication Using Pointers

Feb 15, 2014

Code:
#include<stdio.h>
#include<conio.h>
void main()

[Code] .....

This program on running returns an error of "ILLEGAL USE OF POINTER".

View 4 Replies View Related

C :: Matrix Multiplication Using Pointers

Feb 17, 2014

Code:
#include<stdio.h> Code: #include<conio.h>
void main() {
int *a[2][2],*b[2][2],*c[2][2],i,j,k;
Printf("
ENTER a MATRIX ELEMENTS

[Code] .....

View 4 Replies View Related

C/C++ :: How To Assign Pointers For Boost Matrix

Aug 4, 2014

I am using boost matrix for generating matrices used for filters. I wan to assign a pointer to these matrices so i can call them out of the function. but i am not able to understand where i am failing. the example code is here.

int main(int argc, char *argv[]) {
QApplication a(argc, argv);
identity_matrix<double> M(3);
std::cout<<M<<std::endl;

[Code] ....

View 9 Replies View Related

C++ :: MergeSort With Sentinels And Order Pointers Not Values

Apr 20, 2014

I'd like to do a MergeSort with sentinels and order the pointers, not the values!

#include <iostream>
#include <limits>
using namespace std;
void
stampa (int *n) {
int i;
for (i = 0; i < 10; i++) {

[Code] .....

View 9 Replies View Related

C++ :: How To Exchange Big Structures Across Libraries

Nov 6, 2014

I have written library in c++ for c++ application. Here, data exchange between library and client through structure. This structure has 20 members ( strings, integers, reals, pointers).

In some flows, library needs few members should get filled in the structure. for ex, application filled 3 integers information and passed to structure. But, in memory, whole structure is occupied.

I think, If library provides functions for every combination, then it would end up with lot of functions. I want to avoid that.

How to optimize data exchange between client and library? ( number of members may be filled sometimes 1, 2, 3, .. 20)

View 7 Replies View Related

C++ :: How To Exchange Strings In Field

Sep 29, 2013

I need exchange strings in field, but how to do that. For example:

{"Hi", "Hello", "Goodbye", "Morning"};
to
{"Hello", "Hi", "Goodbye", "Morning"};

I tried this, but it isn't working:

Code:
for(unsigned int k=0; k<slova[i].size();k++){
t = slova[i][k];
slova[i][k] = slova[i+1][k];
slova[i+1][k] = t;
}

View 7 Replies View Related







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