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
ADVERTISEMENT
Nov 29, 2014
I had the following question in my exam paper and only got 2.5 out of a possible 7 marks.
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 (Linked list implementation of stack) and write a function reverseRows to reverse the order of rows in the matrix. Note that reverseRows is not a member function of the Matrix class therefore only the public interface of matrix can be used.
template<class Type>
struct nodeType {
Type info;
nodeType<Type> *link;
[code]....
View 2 Replies
View Related
Nov 27, 2014
Basically what are the advantages and disadvantages of having an array implementation vs linked list implementation for a stack?
View 1 Replies
View Related
Apr 26, 2014
Write a program that evaluates postfix expression using array implementation of stack.
The expression [the input] is evaluated from left to right using a stack. When the element read from the expression is an operand, push it into the stack.When the element read from the expression is an operator: Pop two operands from the stack.Evaluate the two operandsPush the result of the evaluation into the stack.
The final result lies on the top of the stack at the end of the calculation. Make sure to display the result before terminating the program.Write a program that evaluates postfix expression using array implementation of stack.
Code:
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#define M 20
typedef struct{
[Code] ....
View 1 Replies
View Related
May 31, 2014
Code:
#include <stdio.h>#include <unistd.h>
#include <stdlib.h>
#define STACKSIZE 100
struct stackk
{
int top;
int items[STACKSIZE];
};
typedef struct stackk *s;
[Code]...
View 1 Replies
View Related
Apr 7, 2014
I am trying to implement a stack class which has struct data type as its private member. I am getiing the following error ,
bash-3.2$ g++ stack_str_arr.cpp
stack_str_arr.cpp: In member function ‘void stack::push(int)’:
stack_str_arr.cpp:39: error: ‘top’ was not declared in this scope
stack_str_arr.cpp: At global scope:
stack_str_arr.cpp:43: error: no ‘void stack::display()’ member function declared in class ‘stack’
Code:
#include<iostream>
using namespace std;
#define MAX 5
class stack {
public :
stack();
[Code] ....
View 2 Replies
View Related
Jun 7, 2014
I have this code that I need to memorize for my final. Memorizing code is easy for me, but I'm trying pretty hard to fundamentally understand the functions, and what they are doing (even using pen and paper, to draw and trace).For example, in the push function below, I understand everything, except why I'm setting ptr = p. I feel like p should be equal to NULL, then the next node I push should be equal to p, etc.
Stack & Stack::push(double x)
{
Node * p = NULL;
try
{
p = new Node;
}
[code].....
Also, are LL Queues that hard to implement once you can do them w/stacks - That will probably be something I have to code for my final, as well. Below is the full code for my Stack class.
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
class Stack
}
[code]....
View 1 Replies
View Related
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
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
Sep 19, 2013
I'm implementing a 4x4 matrix class and all is going well until the inverse function turned up. I'm trying to implement the inverse function, but I can't seem to get my head around it.
I've tried the internet, but found nothing useful. Also, I've looked into source code of other programs/libraries that implement a matrix class, but the code is unreadable.
How I can implement this damn 4x4 inverse function? I know the process of inversion, but putting that process into code is proving quite a challenge.
In addition, I do have some code, but it's unmanageable and inefficient at the moment. If you want to see it, just ask.
Additional question(s): What applications does the inverse matrix have in 3-D?
View 3 Replies
View Related
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
View Related
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
Jun 14, 2013
The program should store a character array in reverse order then display the reversed array. I have also included in the code that will display the actual characters into the array as it loops through. So I know the characters are being stored, but why doesn't it display the entire string when I call it?
Code:
#include<stdio.h>
int main(){
char str[50];
char rev[50];
printf("Enter Desired Text: ");
scanf ("%[^
[Code] ....
Is it just my compiler?
View 5 Replies
View Related
Aug 29, 2013
I am writing code for a program that will take user input selection of columns and determine an array based on that.The number of columns will be user selected.The number of rows equals 3^(columns) <--exponent not XOR
- This is because each column has the possibility of having the numbers 0,1,or 2
For example, if the user were to select "4" columns, then the array would have 4 columns and 3^4=81 rows. Then I would like to populate this with all of the possible combinations of 0,1,2
i.e.
0000
0001
0002
0010
0011
0012
0020
0021
0022
0100
....
2220
2221
2222
how I would create the "For" Loop for this?
View 19 Replies
View Related
Apr 4, 2014
I am attempting to read values from a file into a 2d array temp[31][2] (31 rows, 3 columns).I only want the values from the file to be read into the first two columns.I believe I am accomplishing that but when I go to print the array, I expect the first two columns to have the file data and the third column to have all zeros. The third column, however is printing such that the value is the next row/first column.
I'm not sure for instance why on the bottom loop for line 1 it doesn't print:
temp[0][0] temp[0][1] temp[0][2] 20 49 0 It instead prints: 20 49 1
Code:
#include <stdio.h> Code: #include <math.h>
FILE *inptr;
int main() {
int temp[31][2] = {0}, tempavg[31][2] = {0};
int i, j, k, sum;
inptr = fopen("ProgrammingProject14.txt", "r");
[code]....
View 8 Replies
View Related
Dec 4, 2014
Basically for homework, we gotta make an array of payroll objects, using the general format I've made below...
I'm having trouble. The .dat file we are given to test looks like this:
40.0 10.00
38.5 9.50
16.0 7.50
42.5 8.25
22.5 9.50
40.0 8.00
38.0 8.00
40.0 9.00
44.0 11.75
When I execute the program, it shows the first column of objects, but will always replace the 2nd column values with a 0.
It's definitely NOT reading that column, and using the constructor to set it to zero. I don't know why it's not reading that column though...
(TL;DR.... Currently it reads "Employee #1: 40, 0" rather than "Employee #1: 40, 10.00"... etc)
Here's my code.... (not 100% done yet just testing datafile output atm)
#include <iostream>
#include <fstream>
using namespace std;
class Payroll {
private:
double payRate; // holds an employee hourly pay rate
[code]....
I want it to read the other column without giving me zero />
View 2 Replies
View Related
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
Apr 11, 2014
I am trying to write a program that reverses the elements of an array by using an function 'myreverse'. The function should reverse original array and return nothing.
In my program, the function 'myreverse' is not getting invoked and the original array is being displayed as it is.
#include <iostream>
using namespace std;
void myreverse(int arr[],int n) {
int *p=&arr[n-1];
int temp;
for(int i=0;i<n;++i)
[Code] .....
View 5 Replies
View Related
Jan 9, 2013
I have been trying this for so long. I need to make a separate function named reverseDiagonal where I have to reverse the diagonals in a 2D array.. I have tried swapping it but i don't know where to place the "cout" and print the diagonal.
View 4 Replies
View Related
Jun 28, 2013
/* Implementation of a circular queue of Array containg names.. */
# include <stdio.h>
# include <conio.h>
# include <stdlib.h>
# include <string.h>
# define QSIZE 5
typedef struct{
[Code] ....
I changed my code. but whenever i typed in the ILoveBacolod it takes it as a whole, and if i deleted it deletes the string not the letter. for example:
Enter String: ILoveBacolod
Enter a command: Delete (D)
Output: LoveBacolod
Enter a command: Delete (D)
Output: oveBacolod
Enter a command: Add (A)
Enter a character: z
Output: oveBacolodz
View 2 Replies
View Related
Jul 19, 2014
I first want to say that i am trying to solve my code without Pointers.
My goal is to..
1. Construct an empty 2D array with a capacity of 25. (list[25][2];)
2. Empty(): test if the stack is empty
3. Push(): add a value to the stack in the (list[i][0] = value;) position and (list[i][1] = previous list[i][0] position)
4. Top(); read the value(list[i][0]) at the top(count) of the stack
5. Pop(); remove the value at the top of the stack (list[i]= 0;)
6. Display(); displays all the elements in the stack going from the top to bottom order. (shows array index, data value, and next array index)
I have hit a road block and don't know what to fix or where to go from here.
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
char name[5];
srand(time(0));
//Protoypes
void construction(int table[25][2]);
[Code]...
View 1 Replies
View Related
Mar 4, 2014
Code:
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <math.h>
void reverseAr(char ar[], int n);
int main() {
int choice;
char *abc= ar[];
[Code]...
My codes keep couldn't get the reverse array of characters.
View 4 Replies
View Related
Jun 20, 2013
i use dev c++...i write this code to reverse an array and save the result in the same one
if n=3 i expect
a[0]=0 a[1]=1 a[2]=2 (before rev is OK but after calling rev)
a[0]=2 a[1]=1 a[2]=0 (expected result )
but i get
n=3
[code].....
View 4 Replies
View Related
Jan 7, 2014
I need an implementation for the array index operator overloading of my Fraction class . The Fraction.h looks like :
#include <iostream>
using namespace std;
class Fraction {
public:
Fraction(int = 1, int = 1);
[Code] .....
I am not able write the Array index operator overloading functions.
View 3 Replies
View Related
Mar 15, 2014
Eg. User input : abcde
Program Output : edcba
I keep on getting weird ASCI symbol in return, I couldn't achieve what I need, and tried debugging for days,
Code: char ar[20];
int len,n=0;
printf("enter the string to be reversed :
");
[Code].....
View 5 Replies
View Related
Jan 23, 2014
Here's my program: - Program which inputs a string from user, reverses it and displays it.
#include <iostream>
using namespace std;
void string_reverse (char [], const int);
int main() {
const int arraysize = 10;
char string[arraysize];
[Code] ....
In the string_reverse function, I have declared temp character type array but on line 38, the
compiler is throwing 3 errors: -
error C2057: expected constant expression
error C2466: cannot allocate an array of constant size 0
error C2133: 'temp' : unknown size
I have declared a constant integer arraysize in line 35. Now I have no clue why is this happening because I think as I have declared it as a constant integer variable, this should not happen.
View 5 Replies
View Related