GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 05-Mar-2005, 23:55
arikeri arikeri is offline
New Member
 
Join Date: Mar 2005
Posts: 10
arikeri is on a distinguished road
Question

problem with code


The following code is compiling properly but not giving the result I want

CPP / C++ / C Code:
     #include<iostream>
#include<string>
#include<string.h>
#include<stdlib.h>
using namespace std;
// all variables used are global
int n;//number of variables
int m;//number of minterms
int d;//number of don't cares
int k;// just a dummy 
struct num {
    int dec;//decimal representation of the number
    int bin[15];//binary representation of the number
};                //for eg; if xyz.dec=32 then xyz.bin=00000000100000 

int dtob(int integer,int BIN[14]);
int main(){
    int n;//number of vairables.
    int i;//used for indexing again and again
    cout<<"enter the number of variables\n";
    cin>>n;
    cout<<"\nnumber of minterms\n";
    cin>>m;
num minterms[m];
    cout<<"\nenter them\n";
    for (i=0;i<m;i++){cin>>minterms[i].dec;}
    cout<<"\nnumber of don't cares\n";
    cin>>d;
num doncares[d];
    cout<<"\nenter them\n";
    for (i=0;i<d;i++){cin>>doncares[i].dec;}


for (i=0;i<m;i++){k=dtob(minterms[i].dec,minterms[i].bin);}
for (i=0;i<d;i++){k=dtob(doncares[i].dec,doncares[i].bin);}







return 0;

}


   




int dtob(int integer,int BIN[14]){
        int saved_integer;// just save the input
        int index,temp,bin,n;
        int array[15]={1,2,4,8,16,32,64,128,256,512,1024,2048,5096,10192,20384};
        int i;

        cout<<"\n\n";

                 while(index>0){
                        saved_integer=integer;

                        if(integer<0 || integer>40000){
                                cout<<"The number must be between 0-40000.\n";
                        }
                        else{
                        index=14;
                                while(index>=0){
                                        temp=0;
                                        if(integer>=array[index]){
                                                temp=array[index];
                                                integer=integer-temp;
                                                bin=1;
                                                index--;
                                        }
                                        else{
                                                bin=0;
                                                index--;
                                        }
                                        BIN[index+1]=bin;


                                        cout<<"\n\n\n";
                                }
                         }
                 }
        cout<<"The binary number is\t";
        i=14;
        while(i>=0){cout<<BIN[i];i--;}
        cout<<"\n";

return 0;

}

--------------------------------------------------------------------------

suppose the input is :
number of variables=3
number of minterms=1
enter the minterms 3
number if doncares=2
enter them 1
7



I want the output to be:

the binary of the number is 000000000000011
the binary of the number is 000000000000001
the binary of the number is 000000000000111



Hope I've made it clear.
Thanks in advance.

Arjun Arikeri :-( (I've been breaking my head for hours)
Last edited by JdS : 06-Mar-2005 at 08:22. Reason: please insert your example C codes between [c] and [/c] bbcode tags
  #2  
Old 06-Mar-2005, 00:29
arikeri arikeri is offline
New Member
 
Join Date: Mar 2005
Posts: 10
arikeri is on a distinguished road
problem solved


:-)
  #3  
Old 06-Mar-2005, 01:19
arikeri arikeri is offline
New Member
 
Join Date: Mar 2005
Posts: 10
arikeri is on a distinguished road
Angry

the entire problem


The entire problem Iam trying to solve is to minimize a cannonical SOP expr to a minimal expression.The number of variables is input to the function.Assume the input to be correct.
I need to use K-maps and hypercubes and not the Quine-McClusky algorithm explicitely.


Plz reply if you have any suggestions.


Thanks in advance .
  #4  
Old 06-Mar-2005, 01:22
arikeri arikeri is offline
New Member
 
Join Date: Mar 2005
Posts: 10
arikeri is on a distinguished road
what I thought was to find all the hypercubes and then later remove rudundancy
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Formatting C / C++ code WaltP C Programming Language 1 07-Jan-2008 00:59
Problem with int mixed with char,... leitz C++ Forum 17 07-Dec-2004 21:56
Insert problem in linked list with two function code Kay Chan C++ Forum 1 03-Sep-2004 10:52
problem with C code belludandy C Programming Language 1 26-Jan-2004 22:28

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 21:15.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.