Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 08-19-2013, 12:56 PM   #16
LQ Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 21,944

Rep: Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810

Originally Posted by samasara View Post
My c++ code is a code that assess risk based on fuzzy logic. I used a fuzzylogic library and then write such a code. my code is like this:
#include <iostream>
#include <stdlib.h>
#include "../FuzzyRule.h"
#include "../FuzzyComposition.h"
#include "../Fuzzy.h"
#include "../FuzzyRuleConsequent.h"
#include "../FuzzyOutput.h"
#include "../FuzzyInput.h"
#include "../FuzzyIO.h"
#include "../FuzzySet.h"
#include "../FuzzyRuleAntecedent.h"

 using namespace std;
  int main(){

       int Acc, Get, Third;
       Fuzzy* fuzzy = new Fuzzy();

        // Step 2 - Creating FuzzyInputs
        FuzzyInput* Threat = new FuzzyInput(1);
        FuzzySet* lowThreat = new FuzzySet(0, 1.875, 1.875, 3.75);
        Threat->addFuzzySet(lowThreat); //add fuzzy set low to threat level
        FuzzySet* mediumThreat = new FuzzySet( 3.125, 5,  5, 6.875);
       // other fuzzyset will be made like this i do not write them here just for making the code shorten.
 FuzzyOutput* Risk = new FuzzyOutput(1);

        FuzzySet* lowRisk = new FuzzySet(0, 1.875, 1.875, 3.75);

        //Step 3:Creating fuzzy rules
        //for example: 1. If (Threatlevel is Low) and (vulnerability is Low) and (Asset_value is High) then (Risk is Low)

        FuzzyRuleAntecedent* ThreatlowThreatAndVulnerabilitylowVulnerability = new FuzzyRuleAntecedent();
        ThreatlowThreatAndVulnerabilitylowVulnerability->joinWithAND(lowThreat, lowVulnerability);

        FuzzyRuleAntecedent* AssethighAsset = new FuzzyRuleAntecedent();

        FuzzyRuleAntecedent* ifThreatlowThreatAndVulnerabilitylowVulnerabilityAndAssethighAsset = new FuzzyRuleAntecedent();
        ifThreatlowThreatAndVulnerabilitylowVulnerabilityAndAssethighAsset->joinWithAND(ThreatlowThreatAndVulnerabilitylowVulnerability, AssethighAsset);

        FuzzyRuleConsequent* thenRisklowRisk = new FuzzyRuleConsequent();

        FuzzyRule* fuzzyRule1 = new FuzzyRule(1, ifThreatlowThreatAndVulnerabilitylowVulnerabilityAndAssethighAsset, thenRisklowRisk);

        cout << "Threat:" << lowThreat->getPertinence() << ", " << mediumThreat->getPertinence() << ", " << highThreat->getPertinence() << endl;
        cout << "Vulnerability:" << lowVulnerability->getPertinence() << ", " << highVulnerability->getPertinence() << ", " << endl;
        cout << "Asset:" << lowAsset->getPertinence() << ", " << highAsset->getPertinence() << endl;

 float output1 = fuzzy->defuzzify(1);

        cout << "Risk:" << output1 << endl;

        return 0;
As you can see 3 variables Acc, Get ,Third should be feed from a shell script that is like this:
Go back and read the tutorial on C++ and how to get command-line parameters that was looked up and GIVEN to you. Apply that to your C++ code. Again, we are not going to write your code for you a second time. Firerat pointed out what needed to be done, and you're obviously using some sort of library system that's referred to in your C++ code as "../". Is that a valid path?
Old 08-19-2013, 01:03 PM   #17
Registered: Aug 2013
Posts: 34

Original Poster
Rep: Reputation: Disabled
Pass the output of a shell script to c++ program Reply to Thread

Originally Posted by Firerat View Post

your c++ code does not have a single cin, your Acc, Get and Third are all null..
You need to learn c/c++ , I'm not going to do it for you

and regards the 'errors'

It looks to me like you are running your fuzzycode2.cpp source file as if it were a shell script!

look, the code you posted..
sh FuzzyLogic.cpp 
FuzzyLogic.cpp: line 13: using: command not found
FuzzyLogic.cpp: line 14: syntax error near unexpected token `('
FuzzyLogic.cpp: line 14: `  int main(){'
obviously the numbers 'changed' it must be a different version...

How did you ever get this far?

my errors have been solved. Excuse me i think it was a fault i do not run my cpp program with sh i think it is a text mistake. i compile it with makefile and gcc
and then run the code just by ./fuzzycode2.bin . i want just trying with these sample code that you sent me to learn more and i do not like you to do it for me.
Now i just use your sample and should change it for doing something that i want.
Regarsds the thing that you said me that my cpp code has 3 values that all are null, i just put them as a symbol in my code. for the first step of the code i put instead of them some values. for example:


after that i want to pass these values from shell script i put these 3 (Acc, Get ,Asset) as symbols in it for sending these values later to it.
thanks for your kind and help

Last edited by samasara; 08-20-2013 at 09:12 AM.
Old 08-19-2013, 02:22 PM   #18
LQ Newbie
Registered: Nov 2004
Distribution: Debian GNU/Linux
Posts: 12

Rep: Reputation: 2
Old 08-20-2013, 02:04 AM   #19
Registered: Aug 2013
Posts: 34

Original Poster
Rep: Reputation: Disabled
Pass the output of a shell script to c++ program Reply to Thread

Hi dear users,
I edit my code and i get what i wanted. Really thanks for your kind and help.
Old 08-20-2013, 02:12 AM   #20
Senior Member
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,320

Rep: Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635
Originally Posted by samasara View Post
Hi dear users,
I edit my code and i get what i wanted. Really thanks for your kind and help.
what climaxnix said


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how to pass input from c program to shell script? kalyanilinux Programming 13 02-01-2012 10:06 AM
How to pass command line arguments from one shell script to another shell script VijayaRaghavanLakshman Linux - Newbie 5 01-20-2012 09:12 PM
how to pass MySQL user/pass securely in shell script? digity Linux - Newbie 5 01-07-2010 05:48 AM
How to pass the output of one program to another program without backticks? BrianK Linux - General 4 11-11-2008 06:27 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:22 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration