C++ :: Reading From Boolean Matrix Class

Feb 18, 2015

Question for coding transivity in c++

a->b b->c then a->c

It should contain a main code reading from boolean matrix class. for ex)input file is

8
0 1
1 2
2 3
3 4
4 5
5 6
6 7

8 is the number of no.

what program should do.
1. check if 0->7 first(0th element)->last
2. check every 5th(5,10,15...) element is to last 5->7

View 1 Replies


ADVERTISEMENT

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++ :: Create Matrix Of Data That Add Values Based On Reading Get From DVM

Apr 22, 2012

Ok I'm trying to create matrix of data that I can add values to based on a reading that I will get from a DVM. I'm using a 3d vector to do this. I need to keep track of the serial number, the day and within day I need to take two readings at different temps, this will continue for 7 days.

The rows of my 3d vector will be the days, the colums will be the serial numbers the depth will be the reading at the different temps.

What I need to do is compare the first element (days) and when it is greater then or equal to 4 I will perform calculations of the readings. So all I want to do is compare the first element of the vector, How do I do this?

Here is what I got

Code:
#include <vector>
typedef std::vector<double> Double1D;
typedef std::vector<Double1D> Double2D;
typedef std::vector<Double2D> Double3D;
#define HEIGHT 5
#define WIDTH 3

[Code]....

View 7 Replies View Related

C++ :: Add Three Objects Of A Class Matrix

Apr 9, 2014

I have been working on an assignment where I have to add three objects of a class Matrix. The class should have the flexibility to add more than two oprands without changing any operand on Left hand side of the '=' operator.

Matrix obj1, obj2, obj3, obj4
Obj1=obj2+obj3+obj4

I am using the following code for this

Matrix Matrix::operator + (Matrix &obj) {
if((this->Columns == obj.Columns) && (this->Rows == obj.Rows)) {
for(int i=0;i<obj.Rows;i++)

[Code] .....

the problem is that it is just adding only 2 operands. How can I add more?

View 2 Replies View Related

C++ :: Matrix Class Using Vectors

Jul 23, 2012

I have implemented matrix class using vectors. code is

template <class T>
class CBSMatrix : public CBSVector< CBSVector<T> >
CBSMatrix(long r,long c, T t) {
setsize(r, c);
init(t);

[Code] .....

Although i have implemented the cols() but things in it are confusing me specially this line "if(size()) return at(0).size();" and "CBSVector<T> v(cols());" this line in add row function is also troubling me. in main i have done some thing lyk CBSMatrix <int> mat(5,5,0); now how to put values in this matrix. How to put values in this template based and vector based wired matrix because first row is created in this and then cols are added to that row.

View 14 Replies View Related

C++ :: Adding Arrays And Matrix To A Class?

Feb 5, 2014

I'd like to start out by adding an array to a C++ class. I'd like to be able to reference the array using a class object that I create, for example:

Class is Stone.

Stone Bob is an instance of "stone" that I name "Bob".

"Bob.array[1] = "granite";" tells the compiler that the second element in the array (with the first being the zeroth element) is a string containing "granite".

I'll eventually want to extend this to an n x m matrix within the "stone" class that can be referenced as: Bob.matrix[1][3]="lignite";

I tried to make this work using a text again and again last night to no avail. My code is below.

NOTE: Since I am dynamically allocating memory space, I'd like to avoid memory leaks when using this class with dynamically allocated arrays and matrices. Not sure how to do this. Also need some insight into "destructor", and why my simple version reduced to a comment below doesn't seem to please the compiler.

CODE FOLLOWS:

Code:
// AINOW.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
using std:: string;
using std:: cout;
using std:: endl;
using std:: cin;

[code]....

View 11 Replies View Related

C/C++ :: Matrix Class - Addition / Subtraction

Jul 7, 2014

I'm working on a matrix class and I've hit a few snags. Here's what I've got so far:

Matrix.h

#include <iostream>
#include <conio.h>
using namespace std;
class Matrix {
private:
int matrix[50][50];

[Code] ....

Where I have questions is in implementing the addition and subtraction bits into the class itself. I understand that I'm going to have to do a copy operation (this from reading in C++ Primer Plus 5th Edition). Right now I'm just after adding/subtracting as the rest will be variations on the same theme.

So, here it goes:

As I understand the problem, I need to pass my two matrices as arguments to an addition function. This is going to involve having to copy the values of the two existing matrices into temporary matrices within the addition function, then I'll add them, and store them in a new matrix which will be my return value. So...something like this:

int Matrix::matrixAdd(int R, int C, const Matrix & matrix1, const Matrix & matrix2) {
int sum;
Matrix matrix;
for (int i = 0; i < R; i++)

[Code] ....

I do end up with errors there...C2240, and C2662. Again, I'm new to working through this, but that's what I've got. My idea is that I'm passing the maximum size of the array as defined by the user, in this case a 2x2 array, it'll cycle through and add up to that imposed limit...I went 2x2 because it's small enough that testing doesn't drive me up a wall.

View 14 Replies View Related

C++ :: Adding Two Objects Of Class (Matrix)

Feb 13, 2013

I am trying to add matrices a and b. I am getting an error in the "add" function, probably because I have m[i] in it, and m is not an array. What is the correct way of writing the "add" member function here?

Also, although the "read" and "write" member functions of the class are working just fine, do you think there is a better way of writing them?

Code:
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
const int rows=3;
const int columns=3;

[code].....

View 2 Replies View Related

C/C++ :: Resizing Matrix And Zero-parameter Class Member

Sep 19, 2014

I'm attempting to make a matrix class, and so far I've made a member that can make a vector of vectors, but I'm not sure how to go about resizing the vectors if need be.

EX: resizeArray(3,3) should return a 3x3 vector.

Also, for some reason when I call my default member, matrix(), I get an error that says.. "Request for member numrows in myMatrix, which is of type matrix<int>[][]"

#include <iostream>
#include <vector>
using namespace std;

[Code].....

View 1 Replies View Related

C++ :: Matrix Class (strings But No String Header Allowed)

Sep 27, 2013

I am IT student and had a C++/C (oral + paper) exam today. One of the tasks was to write a 2D-Matrix (as the question said) class with following restrictions:

- No <string> header is allowed
- Only Dtor needs to be implemented
- No templates
- Following should be possible:

Code:
std::cout << mat1 + mat2 + "some randome string";
mat1 += mat2; So i did the following:
In Matrix.h i wrote: Code: Class Matrix{
int rows, cols;
char *arr[][];

[Code] .....

Now..this destructor made me loose some points since the Prof. said that it is not correct. The corrected version was:

Code:
Matrix::~Matrix(){
if(arr){
for(int i = 0; i < rows; i++){
for(int j = 0; j < cols; j++){
delete [] arr[i][j];
[Code] ....

Now, i agree on that error i made, but it is only in case we use the "new" keyword to reserve place dynamically for each string(for each char*). So this raised the question in my head about:

Since the following is allowed in C++

Code:
char* str1 = "hello";
char* str2 = "you";
arr[1][3] = str1;//arr[1][3] was initialized to "_" without new keyword
arr[6][0] = str2;//arr[6][0] was initialized to "_" without new keyword why would someone use the new keyword..

I mean like this:

Code:
arr[1][3] = new char*[sizeof("sometext1")+1];
arr[1][3] = "sometext1";
arr[6][0] = new char*[sizeof("sometext2")+1];
arr[6][0] = "sometextw";

What is happening internally in C++ in both the cases(with and without new keyword)?

View 11 Replies View Related

C++ :: Matrix Class - Template Constructor Doesn't Work So Well

Feb 5, 2013

I realized a Matrix class to practice and I have a problem I can not solve! Here my problematic code:

Mtrx.h:

Code:
template <class T>
Mtrx::Mtrx(dim m, dim n, const bool random_constructed = false, const T min = static_cast<T>(0), const T max = static_cast<T> (10))
Mtrx.C

[Code] ...

And here the relative main section:

Code:
Mtrx rand1 ( 5, 5, bool);// ok
cout<<rand1<<endl;

Mtrx rand2 ( 7, 3, bool, -5, 20);// ok
cout<<rand2<<endl;

Mtrx rand3 ( 7, 7, bool, 0., 15.);// compilation error: undefined reference to
// "Mtrx::Mtrx<double>(unsigned long, unsigned, bool, double, double)"
// collect2: error: ld returned 1 exit status

I compiled in a Linux OS with g++ -std=c++11

View 3 Replies View Related

C++ :: Template Class For Matrix Manipulation - Expected Initializer Before Constant

Jan 29, 2013

I wrote a template class for Matrix manipulation. The compiler cannot compile the source and complains

Matrix.h:144:41: error: expected initializer before ‘const’

What is the problem of the code enclosed below?

#ifndef MATRIX_H
#define MATRIX_H
/**
* @file Matrix.h
*The Matrix template class written for simplify the matrix manipulation.
*/

#include <cassert>
using namespace std;
template<typename T>
class Matrix {
int rows,cols;

[Code] .....

View 6 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/C++ :: Assign A Matrix To Submatrix Of A Bigger Matrix?

Feb 27, 2012

I want to assign a matrix to submatrix of a bigger matrix.

ublas::matrix<int> A(8,5);
ublas::matrix<int> B(2,5);
for(size_t i=0;i<A.size1();++i)
for(size_t j=0;j<A.size2();++j)
        A(i,j)=i*A.size2()+j+1;
for(size_t i=0;i<B.size1();++i)
    for(size_t j=0;j<B.size2();++j)
        B(i,j)=i*B.size2()+j+5;
ublas::matrix_range<ublas::matrix<int> > a(A,ublas::range(0,2),ublas::range(0,5));
a=B;  

and it works.

but if the matrix is compressed_matrix type, there's something with it. the error log as below:

Check failed in file boost_1_48_0/boost/numeric/ublas/detail/matrix_assign.hpp at line 1078:
detail::expression_type_check (m, cm)
terminate called after throwing an instance of 'boost::numeric::ublas::external_logic'
what(): external logic
Aborted

I'm not sure this is a bug or not.

View 2 Replies View Related

Visual C++ :: Class / Private - Reading Uml?

Feb 9, 2013

So I'm trying to do a homework assignment, where I read a uml about a bank program, and just create it. Here is the UML. So while working on Bank, the top one, i've come up with this so far.

Code:
#include <iostream>
#include <string>
using namespace std;
class bank
{ string name;
int routingNum;

[Code] ....

I'm assuming that's what the uml wants. However I can't seem to access that private class. Idk why. I declared it as an object in the main.

View 4 Replies View Related

C++ :: Find Matrix P For A Square Matrix A

May 25, 2014

I have to prepare a project. But I don t know how can I do this. Program will find a matrix P for a square matrix A such that P^-1 A P ....

View 15 Replies View Related

C :: Boolean Value Use For If And Else Statements

Apr 20, 2013

Am i using boolean values correctly? our professor wanted boolean value use for the if and else statements.

Code:
#include <stdio.h>
#include <math.h>
#define GRAVITY 9.8
#define LIMIT 500
#define SEC 5

[Code] ....

View 2 Replies View Related

C++ :: Reading File And Storing In Class Objects?

Aug 18, 2013

I've a text file : Random.txt which comprises of
Jade
12MS234
Male
18
Rocky
12MS324
Male
18
Marx
12MS632
Male
18

Now in my program i've a class
class stud
{
char name[10];
char reg[10];
char gender[10];
int age;
};

Now I've to write a code in c++, where i've to read the given data and store this into 3 objects of stud class(array of objects) ...then further i've to manipulate the above stored data. I think i'm getting error while storing...variables are showing random characters... give me the code.for this program..in C++

View 2 Replies View Related

C++ :: Negating Boolean Values

Mar 22, 2013

I made some research on how to negate a boolean value but none seemed to work. Ok, so I have the following code:

Code:

#include <iostream>
using namespace std;
int main() {
bool Turn = true;
for (int i = 1; i < 11; i++)

[Code]....

As of now the code prints "XXXXXXXXXX". And I want it to print "XOXOXOXOXO", so I tried 2 different things, which did not work:

Code:

#include <iostream>
using namespace std;
int main()
{
bool Turn = true;
for (int i = 1; i < 11; i++)
{

[Code]...

Code:

#include <iostream>
using namespace std;
int main()
{
bool Turn = true;
for (int i = 1; i < 11; i++)

[Code]...

Ok so I made those changes so that the boolean 'Turn' would change everytime the loop executed. Guess it doesn't work.

View 2 Replies View Related

C++ :: Casting A Logical Boolean As Int?

Jun 8, 2013

Let's say I have a product that needs service after 500 hours at 100 RPM. I can dsiplay the remaining hours only as an integer and we only have integer math. Management wants it to display 500 for the first hour, not 499 after the first minute is ticked off. But after a few minutes fullHours will be 499 and partialHours will have some value. I have 3 ways to determine displayHours to suit management and I want to know if the first is ligit.

short fullHours = 500;
short partialHours = 0;
short displayedHours = 0;

// Method 1 - Is is Kosher to cast a boolean as an int? Is TRUE always a 1 or is that a bad assumption?

displayedHours = fullHours + (short) (partialHours != 0);

//Method 2 - Works but some have disdain for the ternary conditional

displayHours = fullHours + (partialHours ? 1 : 0);

//Method 3 - seems a bit pedantic

displayHours = fullHours;
if (partialHours != 0) {
displayHours++;
}

View 19 Replies View Related

C++ :: Boolean Function In Turbo?

Jan 9, 2015

Is the boolean function already defined under the default headers? Else, how would I create one? Would this work? :

#define true 1
#define false 0
typedef int bool;
Bool x=true;

View 3 Replies View Related

C++ :: 2D Array In Boolean Function

Apr 24, 2014

i have a Boolean function containing 2D dynamic array, it'll retain either 0 or 1, how can i delete the dynamic array?

bool something (int** a,int b, int c) {
int **arr = new int*[b];
for(int i=0;i<b;i++)
arr[i]= new int[c];
if (...) return 0;
else ...
if (...) return 0;
}

View 3 Replies View Related

C# :: Split String With Boolean

Nov 19, 2014

I have my Arduino send the following string every second:

69.4,69.4,69.4,69.4,69.4,69.4,8.42,100,100,50,50,20,16,10,14

and i currently have my C# code split it and send the values to corresponding text boxes:

// SERIAL READS:
private void myport_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) {
string RxData = myport.ReadLine();
this.BeginInvoke(new LineReceivedEvent(LineReceived), RxData);

[Code] ....

Now if i were to add true/false values to my arduino string, im not sure to read it. I would like the bool values to enable/disable led jpegs to simulate output status.

rly1_led.enable = newData[15];// if true

Ive tried everything and just cant figure it out. This is my first C# project.

View 14 Replies View Related

C++ :: What Is The Type Specifier For Boolean

Dec 11, 2012

In the following example, how 'd I use sprintf when I have a boolean type of variable?

Code:
char s[64];
bool bVar = false;
sprintf(s, "This is a boolean variable bVar = %?", bVar);

What is supposed to replace ? in the sprintf statement ?

View 10 Replies View Related

C :: Writing A Macro That Returns A Boolean Value

Apr 24, 2014

I need writing a macro that would return true/false (1/0) )value. I want to check if a certain element exists in the array. The macro will accept array, its size, and the value to be compared, and must return yes or no. Here is the code that I have written:

Code:
#define EXISTS(T, a, n, val) do {
char ret=0;
T *a_ = (a);
size_t n_ = (n);
for (; n_ > 0; --n_, ++a_){
ret = (*a_ == val);
}
}
while(0)

How can I get the result from this macro.

View 6 Replies View Related

C++ :: Assigning A Function Using Boolean Operator

Nov 18, 2013

I am writing a code where I have to find out the spot a letter is in. I am getting an error with assigning a function using a boolean operator.

bool is_member(const vector<char> & list, char character) {
for(int i=0; i < list.size(); i++) {
if(character==list[i]) {
return(true);

[Code] .....

My constant vector list is { 'a', 'e', 'i', 'o', 'u', 'y'}. My error comes in on line 20. I am not calling the boolean correctly. If I type in the letter "i". Then the function should output 2 since i is in the 2nd index spot of my vector list. How to fix my error? I am not understanding why my line of code is not working.

View 10 Replies View Related







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