C/C++ :: Modifying Row Of Matrix Based On Zero Entry?

Nov 19, 2014

Here is the problem:

Write an algorithm such that if an element in an M * M matrix is 0, its entire row and column is set to 0.

Your function prototype may look like the following:

void setZeros ( int size, int arr[][size] );

Heres what I have:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SIZE 3
void scan_matrix(int arr[][SIZE]);
void print_matrix(int arr[][SIZE]);
void initiailize_matrix(int arr[][SIZE]);
void set_zeros(int matrix[][SIZE]);

[code]....

I'm not sure on how to scan zero for this code and I have bolded some comments that I am having trouble with as well.

View 1 Replies


ADVERTISEMENT

C# :: Modifying User Controls While Modifying Main Form?

Jul 10, 2014

I am trying to modify a user control while modifying the main form. For example i have my main form open in one visual c# window and my user controls in another. However it seems that in order for my code changes in my user control to have any effect on the main form i need to close all my c# windows and then re-open them and even then that sometimes doesn't work am i doing anything wrong or is this supposed to happen??

Also yes i am saving and clicking build solution on my user controls.

View 14 Replies View Related

C++ :: Create A Map Based Hash Table For A Sparse Matrix?

Jul 24, 2014

I have this assignment where I have to create a map based hash table for a sparse matrix. The professor has provided some code and I'm supposed to fill in parts of it to make it work.

He has given us a class sparseMatrix which we need to provide a hash function for. This hash function is to be defined in a Class TupleHash which is inside sparseMatrix. I think I got that part down. What is really confusing me is what he has done with some typedefs.

For one of them I had to declare an unorderd_map that maps a struct Tuple on to the class template argument Object. I did that like so:

typedef unordered_map<Object,Tuple,TupleHash> HashTable;

The next typedef was given to me like so:

typedef typename HashTable::value_type valueType;

This is giving me a world of unintelligible error messages. This is how it starts.

In instantiation of 'struct std::__detail::__is_noexcept_hash<int, sparseMatrix<int>::TupleHash>':|
recursively required from 'struct std::__and_<std::is_default_constructible<sparseMatrix<int>::TupleHash>, std::is_copy_assignable<sparseMatrix<int>::TupleHash>, std::__detail::__is_noexcept_hash<int, sparseMatrix<int>::TupleHash> >'|

View 1 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++ ::  modifying Several Variables Via Header File

Feb 18, 2014

I'm trying to split up my game (about 1300 lines) into header files, but I'm coming up with a problem whenever I try and put a function in a header file, when that function was modifying some variables that were defined before int main in the .cpp. For example:

int variable1 (0);
int variable2 (0);
void increasevariables() {
variable 1 = variable1 + 1;
variable2 = variable2 + 1;

[code].....

If it only modified one variable then I could just pass that variable and the return it:(return variable1 + 1;)But I don't know how to make a function in a header file modify several pre-existing variables. In the actual program, the variables are dependant on each other and the modifying is a lot more complicated, so I'd rather not split it into several functions and run one at a time if there's another way.

View 4 Replies View Related

C/C++ :: Modifying Array Inside Of Function

Mar 7, 2014

I am new to C++ and am trying to modify an array inside of a function.

It is of my understanding that you cannot return an array from a function?

Would writing it to a data file and then retrieving it be a solution to this problem?

View 2 Replies View Related

C# :: Foreach And Modifying Objects In Collection

May 8, 2014

I have a class that loads the contents of a XML file into their respective object types and stores those objects in a list. Each object has its own list of objects with properties the program will later modify.

The problem I am currently having is that after looping through the objects and modifying the necessary properties the modifications do not persist. This leads me to believe I am modifying a copy of the object rather than the object I think I am modifying. I am not sure why this is happening as I believe I should be modifying the object that is referenced in the collection.

What I have tried, I started using LINQ to get the object I am looking to modify. After a little more research I don't think this can work properly due to the LINQ query returning a new object(copy of the object). Currently I am using nested foreach loops which still are not behaving the way I expect as the properties I am setting are not making their way back to the original object.

The PopulateLogSheet() in the following class is where the problem loop is.

class ChillerCheckCollection {
public List<Chiller> chillers = new List<Chiller>();
public void LoadChillers(string filePath) {
var availableChillers = (from chiller in Xdocument.Load(filePath).Descendants("chiller")
select new Chiller

[Code] ....

And here are the other classes referenced in the above class.

class Chiller {
public IEnumerable<LogSheet> chillerLogSheet = new List<LogSheet>();
public int chillerID;

[Code] ....

View 2 Replies View Related

C++ :: Modifying Existing Array With A Function

Mar 26, 2013

I have an array of char representing pixels in a bitmap, which I want to modify. I don't think I can just iterate over the array and pass chars into a function individually, because the function needs to take into account the neighboring pixels, too.

I thought of two ways to do this. The first would be to pass the array to the function as an argument, then have the function change it and return it. The trouble is I'm not exactly sure what happens internally when you pass an array to a function and return it. Is it the same array, modified? Or is it a copy of the array, so now you're using twice as much memory?

Alternatively I guess I could have a function with a void return type and pass a pointer to the array. I'm somewhat new to this, but the way I understand it is that a pointer is like the address of a house, while the array is the actual house. So if I give the function the address, it can go to that address and rearrange the furniture inside the house. Then, after the function returns, I can go to that address myself and see all the rearranged furniture, even though the function has already returned.

Is there a problem with the second way? It seems a bit neater, but maybe I'm understanding pointers wrong.

View 14 Replies View Related

C++ :: How To Read Data Of Particular Student And Save It After Modifying

Jun 21, 2014

I have to read a particular student data from file using his Roll no and modify it and then save it to file again

This is the File
24 salman 98 97 96 95 94 A ;
21 faizan 88 87 86 83 85 B ;
35 Gohar 99 98 97 96 90 B ;
45 sibghat 91 92 78 85 88 C ;
009 john 89 87 91 78 95 C ;

how can i read data of roll no 35 and modify it and save it again to the file

this is my program

int r = 0 ;
while ( ar[j]!="0" ) {
//cout << "Salman majid is
" ;
if ( ar[j]==k ) {
r = j ;
getdata() ;

[Code] .....

View 2 Replies View Related

C++ :: How To Rotate Single 3D Object By Modifying Its Coordinates

Jun 20, 2014

I would like to understand how to rotate a 3D Object around it's Center, by modifying it's Vertex Coordinates. N

The reason is that I need to keep track of the new coordinates because of my collision system, which is based on Vertex Coords.

Here is the Code for an Object

void DrawHouse(GLfloat x1, GLfloat x2, GLfloat y1, GLfloat y2,
GLfloat z1,GLfloat z2, GLfloat u1, GLfloat u2, GLfloat v1, GLfloat v2, GLuint textid) {
glBindTexture(GL_TEXTURE_2D, textid);
glBegin(GL_TRIANGLES);
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(u1,v1); glVertex3f(x1,y1,z2);

[code]....

View 7 Replies View Related

Visual C++ :: Modifying 3Ds Max App Wizard / Error C1083

Nov 22, 2012

I've got

[tranlated]

Code:

error C1083: cannot open: '[!output PROJECT_NAME].h': No such file or directoryd:program files (x86)autodesk3ds max
2012maxsdkhowto3dsmaxpluginwizard emplates1033atmospheric_type_atmospheric.cpp1513dsmaxPluginWizard

I opened the project

Changed it to vc100

Changed it to x64

Disabled optimization

And compiled

And the results are shown above

View 1 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 :: Modifying Code To Handle Uppercase And Special Symbols

May 23, 2013

My code is currently reads in a string of lower case letters, identifying the occurrence of each letter.

Code:
#include <stdio.h>
#include <string.h>
int main()
{

[Code]....

My issue is that I want my code to read uppercase and special symbols. showing the occurrence of both.

Code:
else if(str[x] >= 'a' && str[x] <= 'z');
else if(str[x] >= '0' && str[x] <= '9');

However I struggle to implement it

View 3 Replies View Related

C :: Modifying Linked List - Passing Pointer As Argument

Feb 27, 2015

I am having trouble modifying a linked list. I am writing a function to delete the last node from the linked list, but it gave me incompatible types error.Here is my struct:

Code:
typedef struct PCB{
int id;
struct PCB *next;
struct PCB *prev;
}PCB_rec, *PCB_p;

Here is my function to delete the last node (given the pointer is pointing at the last node of the list):

Code:
void del_last_node(PCB_p *process_list){
PCB_p temp = process_list;
if (temp->prev != NULL){
temp = temp->prev;

[Code] ....

And here is how I called the function:

Code: del_last_node(&process_list);

It gives me the following errors:
initialization from incompatible pointer type at line:
PCB_p temp = process_list
assignment from incompatible pointer type at line:
process_list = temp

View 14 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++ :: Analysis Of Discrete Wavelet Transform - Modifying For Loop To Make It Faster

Aug 25, 2014

I have this code which performs the analysis part of discrete wavelet transform. It works pretty well. However, I wish to reduce the time that it consumes even further. I did use reserve() and it worked upto few msec.

int rows = signal.size();
int cols = signal[0].size();
int cols_lp1 =(int) ceil( (double) cols / 2);
vector<vector<double> > lp_dn1(rows, vector<double>(cols_lp1));
vector<double> temp_row;
temp_row.reserve(512);

[Code] ....

View 5 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

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++ :: Adding Entry To Map?

Feb 5, 2013

I have the following code in sourceFile.cpp. functionA() is first called and inserted entires for key1, key2 and key3. Then functionB() gets called to use the vectors for the 3 keys. I want to free all memory after exiting functionC(). Among the three ways to put an entry into the map for the 3 keys, which is correct / better?

Class ClassA { ... }
ClassA *key1 = new ClassA();
ClassA *key2 = new ClassA();
ClassA *key3 = new ClassA();

[Code]....

View 2 Replies View Related

C/C++ :: How To Create Entry Verification

Nov 21, 2014

I have an assignment to create a program that will display the duplicate numbers that were entered by a user. I have the code finished and I have covered the basic requirements of the assignment. However, during my testing I found that if I enter anything other than a whole number (i.e. char or float) the program will run out and exit. I would like to add a little code to verify that the user has entered a whole number. I cannot seem to get this to work though. I have written other codes that verify if a number is above and below a certain value, I just do not know how to look for a certain type of entry.Here is my code:

int main() {
int number[20];
int duplicateNumber[20];
int i, j, k, counter = 0;
// Get number input from the user
for (i = 0; i < 20; i++) {
printf("Please enter a whole number %d: ", (i + 1));

[Code]...

View 3 Replies View Related

C++ :: Displaying Average For Each Entry

May 3, 2013

I have to display an average for each student that is entered ....

void StudentData::displayAverageScore() {
double totalScore = 0;
double totalEx1 = 0, totalEx2 = 0, totalEx3 = 0, averageScore = 0;
for(int i = 0; i < entries.size(); i++) {
totalEx1 += entries[i].getEx1();// accumulate totals
totalEx2 += entries[i].getEx2();
totalEx3 += entries[i].getEx3();
if(totalScore != 0) averageScore = (totalEx1 + totalEx2 + totalEx3) / 3; // don't divide by 0
cout << "Average Score For Exams: " << setprecision(1) << fixed << averageScore << endl << endl;
}
}

View 7 Replies View Related

C++ :: Adding Entry Into Array?

Aug 6, 2014

My program is suppose to be as a virtual phone book that allows you to add,search, display names and numbers.

At the beginning you are able to add up to 10 entries and then from there the program goes to a menu where you can add more entries, search etc.

My problem is that I am unable to add an entry into the existing list of names/phone numbers.

Example: At the beginning I add Joe,Albert,Barry. It sorts them into Albert, Barry, Joe (good so far!)

However, if I choose to add another entry (Carl) it becomes Barry,Carl,Joe.

The functions I am using to add entries are: GetEntries (for initial entries) and Addentries for more entries during the main program.

*******************************COPY OF CODE**********************************

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

[Code].....

View 5 Replies View Related

C++ :: Makefile Only Executing First Entry

Mar 15, 2013

Why this makefile only executes the first entry, compiling only the first program listed?

###########################################################
#
# Simple Makefile for Operating Systems Project 2
#
###########################################################
vowcon:
g++ -o vowcon vowcon.cpp -pthread
osproj2c:
g++ -o osproj2c osproj2c.cpp -pthread
osproj2b:
g++ -o osproj2b osproj2b.cpp -pthread
osproj2a:
gcc -o osproj2a osproj2a.c -pthread
clean:
rm osproj2a osproj2b osproj2c osproj2d vowcon

View 7 Replies View Related

C/C++ :: While Loop To Stop After Third Entry

Jul 6, 2014

Having multiple issue trying to get a while loop to stop after the third entry.

#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
using namespace std;
int mySequentialSearch() {
int value;
string line;

[Code] .....

I am just working on the while loop right now. Then the function after I get the loop working.

View 10 Replies View Related

C :: Secure Entry Keypad Simulator

Feb 15, 2015

We've been tasked write a code which would mimic a secure entry keypad.. Only recognising the digits 0-9 for the passcode, and non-numerics S (start again) C (clear last digit) and E (enter) for the control. All other key strokes are to be ignored.

The passcode has to be <10 digits and represented on the screen by "****", with any keystrokes >10 ignored.
The valid passcode being 4 digits (1234).

With 3 attempts to get the correct pass code, after each fail attempt as please try again message show, where after the 3rd attempt a specific message is displayed and an alarm sounds..

View 13 Replies View Related

C :: The Last User Entry In Loop Fprintfed Twice?

Apr 13, 2014

Still working on my first homegrown C program design . The function basically allows the user to enter a list of classes and grades and saves the list to a file to be used later in the file. The function compiles and runs through without error except for the fact that it always prints the last user entry to the *profilep file twice. Just as a note, the scanchar function is one I made to scan in one character and an end of line character to throw away the end of line char before I learned about %*c about 30 minutes ago...

Also I haven't much bothered to strengthen the function against crazy user input but I have heard using fgets and sscanf in conjunction can replace scanf and protect against weird user input. How to apply this within the program.

Code:
// creates a new profile and prints it to the profile file.
void newprof(FILE* profilep, const char *allclasses[ABBR_SIZE]){
int c, checker, counter;
int i, a;
char prof[MAX_PROF][ABBR_SIZE];
char grades[MAX_PROF][3];

[Code] .....

View 1 Replies View Related







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