Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 24-03-2010, 05:00 PM   #1 (permalink)
Alpha Geek
 
CA50's Avatar
 
Join Date: May 2007
Location: GraveYard
Posts: 918
Default C++ coding


I am currently working on a c++ program to do all the martix operations like addition, subtraction, multiplication and transpose.

But i am little weak in that "Function call / declaration etc." , so i am feeling difficulties in coding the program.

I am sending my partially completed code:
Please tell me how to initialize a function to add and display, and also the function itself.
Code:
#include<iostream.h>
#include<conio.h>
#define max_row 10
#define max_col 10 
int main()
{
      //theis program will add two matrix of 3x4
      int mat1[max_row][max_col],mat2[max_row][max_col],mat3[max_row][max_col],row,col,i,j,value,n;
      cout<<"\n\t\t\t  OPERATIONS ON MATRICES\n\t\t    Coded by CA50 on 22/03/10 08:40\n\n";
      cout<<"Enter the number of rows for MATRIX 1 (max is 10):\a ";
      cin>>row;
      cout<<"Enter the number of columns for MATRIX 1 (max is 10):\a ";
      cin>>col;
      if((row<=max_row)&&(col<=max_col))
      {                                
          cout<<"\nYou have sucessfully created MATRIX 1 of ("<<row<<"x"<<col<<").\n";
          for(i=0;i<row;i++)
          {
              for(j=0;j<col;j++)
              {
                  cout<<"Enter value for row-"<<i<<" col-"<<j<<" ";
                  cin>>value;
                  mat1[i][j]=value;
              }
              
          }
      }
      else
      {
          cout<<"\n\n\aMatrix generation failed. You have exceeded the maximum size limitation.\n";
          getch();
          exit(0);
      }
      cout<<"\n";
      cout<<"Enter the number of rows for MATRIX 2 (max is 10):\a ";
      cin>>row;
      cout<<"Enter the number of columns for MATRIX 2 (max is 10):\a ";
      cin>>col;
      if((row<=max_row)&&(col<=max_col))
      {
          cout<<"\nYou have sucessfully created MATRIX 2 of ("<<row<<"x"<<col<<").\n";
          for(i=0;i<row;i++)
          {
              for(j=0;j<col;j++)
              {
                  cout<<"Enter value for row-"<<i<<" col-"<<j<<" ";
                  cin>>value;
                  mat2[i][j]=value;
              }
          }
      }
      else
      {
          cout<<"\n\n\aMatrix generation failed. You have exceeded the maximum size limitation.\n";
          getch();
          exit(0);
      }
      //menu creation
      system("cls");
      cout<<"\n\t\t\t  OPERATIONS ON MATRICES\n\t\t    Coded by CA50 on 22/03/10 08:40\n\n";
      cout<<"----- MATRIX MENU -----\n1. Matrix addtion.\n2. Matrix Subtraction.\n3. Matrix multiplication.\n4. Transpose of a matrix.\nEnter your choice ";
      cin>>n;
      switch(n)
      {
               case 1:
                    cout<<"\nThe result of matrix addition is:\n";
                    //call matrix addition function here                
               case 2:
                    //call matrix subtraction function
               case 3:
                    //call matrix multiplication function
               case 4:
                    //call transpose function
               default :
                       cout<<"\n\nINVALID CHOICE\n\nPress any key to exit...";
                       getch();
                       exit (0);
      }
      return 0;
}
__________________
| A Bit IP35-Pro | E8400 | GTS250 | Gskill 2x2GB | 1.9 TB | CM EP+ 460W | 2x DVD-RW|
| Win XP x86 | Win 7 Ult x86 | LinuxMint |
| Nokia 2700c |
CA50 is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 27-03-2010, 02:07 AM   #2 (permalink)
XLr8
 
arpanmukherjee1's Avatar
 
Join Date: Sep 2008
Posts: 637
Default Re: C++ coding

first i suggest reading Let us C by yashvant Kanetkar

#includes ....

void display(int mat[],int row,int col)
{
i<row
j<col
cout<<*mat+i+j;
cout<<endl;
}

int *add(int mat1[],int mat2[],int r1,int r2,int c1, int c2)
{
adding & storing in sum[][];
return *sum;
}

main()
{
case 1:
add(.......);
case 2:
......
__________________
Quote:
There are more things in heaven and earth, Horatio,
Than are dreamt of in your philosophy.
arpanmukherjee1 is offline  
Old 27-03-2010, 12:33 PM   #3 (permalink)
Sami Hyypiä, LFC legend
 
Liverpool_fan's Avatar
 
Join Date: Jun 2007
Location: Нью-Дели
Posts: 2,138
Default Re: C++ coding

Quote:
Originally Posted by arpanmukherjee1 View Post
first i suggest reading Let us C by yashvant Kanetkar
What? Let us C is a C book. WTF will he do with a C book eh?
And it's a crap C book too. :/

The problem with people is that they think C and C++ have similarites which is absolutely NOT the case. Most people end up with C practices in C++ and vice versa which is FAIL.

Anyway for a Beginner, Robert Lafore's book (the latest one, not the older Turbo C++ one is pretty okay), though thinking in C++ is one of the best (and eBook is free) in spite of the fact it's a bit advanced.

Anyway you CAN begin with C if you wish, with a book like C Programming Language by Kernighan and Ritchie; but be prepared to UNLEARN C concepts A LOT while moving to C++.
__________________
Experience true education in Computer Science - http://www.udacity.com | http://www.coursera.org

Spoiler:
Read before asking / messaging any moderator for any query: FAQ + answers for new members

Read all the sticky threads before asking any type of query. Most basic questions are answered in those.
Don't use forum for chatting. Visit http://webchat.freenode.net/?channels=krow, enter nick and connect.
Liverpool_fan is offline  
Old 28-03-2010, 12:53 AM   #4 (permalink)
XLr8
 
arpanmukherjee1's Avatar
 
Join Date: Sep 2008
Posts: 637
Default Re: C++ coding

^^ true ... but for a person with little knowledge of functions, i think basic C concepts should be learnt first...

without this C or C++ cannot be understood properly
__________________
Quote:
There are more things in heaven and earth, Horatio,
Than are dreamt of in your philosophy.
arpanmukherjee1 is offline  
Old 04-04-2010, 10:26 PM   #5 (permalink)
Alpha Geek
 
CA50's Avatar
 
Join Date: May 2007
Location: GraveYard
Posts: 918
Default Re: C++ coding

thanks friends for your wise advices, actually i did some C and now just trying to code those previous c programs in C++. Anyway i coded the whole matrix problem and it is really great. I am contented
__________________
| A Bit IP35-Pro | E8400 | GTS250 | Gskill 2x2GB | 1.9 TB | CM EP+ 460W | 2x DVD-RW|
| Win XP x86 | Win 7 Ult x86 | LinuxMint |
| Nokia 2700c |
CA50 is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Batch File Coding: the beginnig Abhishek Dwivedi Tutorials 7 28-11-2007 01:34 PM
Building website without coding madmoody QnA (read only) 10 18-03-2007 01:40 PM
DVD region coding digit_rajesh QnA (read only) 4 14-02-2007 07:12 PM
5 Ways to Contribute to Open Source Projects Without Coding shankar_ganesh Open Source 13 31-01-2007 11:42 AM
Do normal DVD players have Region Coding ?? thrash_metal Software Q&A 10 21-09-2005 01:33 PM

 
Latest Threads
- by Charan
- by Charan
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 03:15 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2