Question

In: Computer Science

I get the following errors when I type the code #include <iostream> #include <string.h> #include <bitset>...

I get the following errors when I type the code

#include <iostream>
#include <string.h>
#include <bitset>
#include <math.h>
#define IS_INTEGRAL(T) typename std::enable_if< std::is_integral<T>::value >::type* = 0
using namespace std;
 
 
template<class T>
std::string inttobits1(T byte, IS_INTEGRAL(T))
{
        std::bitset<sizeof(T)* CHAR_BIT> bs(byte);
        return bs.to_string();
}
 
int bitstoint1(string bits)
{
        int value;
        for (int x = 0, y = bits.length() - 1;x < 8 && x < bits.length();x++)
        {
                int val = atoi(bits.substr(y, 1).c_str());
                value += (int)val * pow(2, x);
        }
        return value;
}
void getlikeyvoltages1(int pinvalue)
{
        //voltages used by OUSB range 0 to 5
        int probability = (int)pinvalue / 255;//this is the likely voltage that can be generated when it's value is pinvalue
        cout << "Votage produced by OUSB when the voltage is " << pinvalue << " = " << probability << endl;
}
void readpotentiometer1()
{
        unsigned char byte = 0x08;//mybyte
        string bits = inttobits1(byte);
        cout << "bits: " << bits << endl;//the bits read
 
        getlikeyvoltages1(bitstoint1(bits));
}
 
void readousb1()
{
        FILE* fpipe;   char command[] = "ousb io PINC";  // Read the switch state.   
        char line[256];
        if (!(fpipe = (FILE*)popen(command, "r"))) {
                // error if fpipe returns NULL       
                perror("Problems with pipe");
                exit(1);
        }
        while (fgets(line, sizeof line, fpipe)) {
                //divide by 4
                int val = atoi(line);
                val = val >> 2;//divide by 4
                printf("%d\n", val);    //the current value
        }
        pclose(fpipe);
 
 
}
int main(int argc, char** argv) {
 
        while (1)
        {
                readousb1();
                string s;
                cin >> s; //pause the program
        }
 
 
        return 0;
}


Error (active)   E0020   identifier "pclose" is undefined   LabPrac2020   
Error (active)   E0020   identifier "popen" is undefined   LabPrac2020   
Warning   C6001   Using uninitialized memory 'value'.   LabPrac2020   
Warning   C4018   '<': signed/unsigned mismatch   LabPrac2020
Warning   C4244   '+=': conversion from 'double' to 'int', possible loss of data      
Error   C3861   'popen': identifier not found
Error   C3861   'pclose': identifier not found   

Solutions

Expert Solution

it seem the eroor is because you have not included the apropriate header files .

Just include this header file and the code will run.

#include<bits/stdc++.h>

#include <iostream>
#include <string.h>
#include <bitset>
#include <math.h>

//include this header file
#include<bits/stdc++.h> 


#define IS_INTEGRAL(T) typename std::enable_if< std::is_integral<T>::value >::type* = 0
using namespace std;
 
 
template<class T>
std::string inttobits1(T byte, IS_INTEGRAL(T))
{
        std::bitset<sizeof(T)* CHAR_BIT> bs(byte);
        return bs.to_string();
}
 
int bitstoint1(string bits)
{
        int value;
        for (int x = 0, y = bits.length() - 1;x < 8 && x < bits.length();x++)
        {
                int val = atoi(bits.substr(y, 1).c_str());
                value += (int)val * pow(2, x);
        }
        return value;
}
void getlikeyvoltages1(int pinvalue)
{
        //voltages used by OUSB range 0 to 5
        int probability = (int)pinvalue / 255;//this is the likely voltage that can be generated when it's value is pinvalue
        cout << "Votage produced by OUSB when the voltage is " << pinvalue << " = " << probability << endl;
}
void readpotentiometer1()
{
        unsigned char byte = 0x08;//mybyte
        string bits = inttobits1(byte);
        cout << "bits: " << bits << endl;//the bits read
 
        getlikeyvoltages1(bitstoint1(bits));
}
 
void readousb1()
{
        FILE* fpipe;   char command[] = "ousb io PINC";  // Read the switch state.   
        char line[256];
        if (!(fpipe = (FILE*)popen(command, "r"))) {
                // error if fpipe returns NULL       
                perror("Problems with pipe");
                exit(1);
        }
        while (fgets(line, sizeof line, fpipe)) {
                //divide by 4
                int val = atoi(line);
                val = val >> 2;//divide by 4
                printf("%d\n", val);    //the current value
        }
        pclose(fpipe);
 
 
}
int main(int argc, char** argv) {
 
        while (1)
        {
                readousb1();
                string s;
                cin >> s; //pause the program
        }
 
 
        return 0;
}

Related Solutions

C++ I took 7/20 =( code: #include <iostream> #include<string.h> using namespace std; // function to calculate...
C++ I took 7/20 =( code: #include <iostream> #include<string.h> using namespace std; // function to calculate number non white space characters int GetNumOfNonWSCharacters(string str) { int i = 0; int count = 0; while(str[i] != '\0') { if(str[i] != ' ') { count += 1; } i++; } return count; } // function to calculate numbers of words int GetNumOfWords(string str) { int i = 0; int count = 1; while(str[i] != '\0') { if(str[i] == ' ' && str[i-1]...
write the algorithm for this the code?!. #include<iostream> using namespace std; #include<string.h> int main() { char...
write the algorithm for this the code?!. #include<iostream> using namespace std; #include<string.h> int main() { char plain[50], cipher[50]="", decrypt[50]=""; int subkeys[50], len;       cout<<"Enter the plain text:"<<endl; cin>>plain;    cout<<"Enter the first subkey:"<<endl; cin>>subkeys[0];    _strupr(plain);    len = strlen(plain);    /**********Find the subkeys**************/    for(int i=1; i<len; i++) { if ((plain[i-1]>='A') && (plain[i-1]<='Z')) { subkeys[i] = plain[i-1]-65; } }    /****************ENCRYPTION***************/       for(int i=0; i<len; i++) { if ((plain[i]>='A') && (plain[i]<='Z')) {    cipher[i] = (((plain[i]-65)+subkeys[i])%26)+65; }...
*****MUST ONLY USE****** #include <iostream> #include <fstream> #include <string.h> #include <stdio.h> Description The word bank system...
*****MUST ONLY USE****** #include <iostream> #include <fstream> #include <string.h> #include <stdio.h> Description The word bank system maintains all words in a text file named words.txt. Each line in the text file stores a word while all words are kept in an ascending order. You may assume that the word length is less than 20. The system should support the following three functions: Word lookup: to check whether a given word exists in the word bank. Word insertion: to insert a...
C++ CODE ONLY Using the following code. #include <iostream> #include <string> #include <climits> #include <algorithm> using...
C++ CODE ONLY Using the following code. #include <iostream> #include <string> #include <climits> #include <algorithm> using namespace std; // M x N matrix #define M 5 #define N 5 // Naive recursive function to find the minimum cost to reach // cell (m, n) from cell (0, 0) int findMinCost(int cost[M][N], int m, int n) {    // base case    if (n == 0 || m == 0)        return INT_MAX;    // if we're at first cell...
8) Errors: Type I and Type II are errors that are possible even when a hypothesis...
8) Errors: Type I and Type II are errors that are possible even when a hypothesis test is done correctly. A hypothesis test is based on probabilities (p-values) This means there is always a probability of drawing the wrong conclusion even when done correctly. Please review the following: a.) What are type I and type II errors? b.) Be able to discuss what a type I or type II error is in a given scenario c.) What is the relationship...
Hi, i need flowchart for this code (C++) please, THANX #include <iostream> #include <thread> #include <unistd.h>...
Hi, i need flowchart for this code (C++) please, THANX #include <iostream> #include <thread> #include <unistd.h> #include <semaphore.h> #include <pthread.h> using namespace std; #define NRO 6 // Número de coches //Puente declarado con matriz y valor entero void Puente(string array, int value); // Variable global int Norte = 1; int Sur = 1; sem_t mutex1; //Coche al norte void* NorteC(void* arg){ sem_wait(&mutex1); string array = "En el lado Norte "; // Norte cout<<array<<"del puente, el coche #"<<Norte<<" puede cruzar el...
Complete the following TODO: parts of the code in C++ #include <iostream> #include <string> #include <limits>...
Complete the following TODO: parts of the code in C++ #include <iostream> #include <string> #include <limits> #include <vector> using namespace std; // // CLASS: NODE // class Node{ public: int value = 0; // our node holds an integer Node *next = nullptr; // our node has a pointer to the next Node Node(int i){ // contructor for our Node class value = i; // store a copy of argument "i" in "value" next = nullptr; // be sure next...
A C++ question: I want to indent the code of this C++ program: #include<iostream> #include<cstring> using...
A C++ question: I want to indent the code of this C++ program: #include<iostream> #include<cstring> using namespace std; int lastIndexOf(char *s, char target) { int n=strlen(s); for(int i=n-1;i>=0;i--) { if(s[i]==target) { return i; } } return -1; } void reverse(char *s) { int n=strlen(s); int i=0,j=n-1; while(i<=j) { char temp=s[i]; s[i]=s[j]; s[j]=temp; i++; j--; } return; } int replace(char *s, char target, char replacementChar) { int len=strlen(s); int total=0; for(int i=0;i<len;i++) { if(s[i]==target) { s[i]=replacementChar; total+=1; } } return total;...
C++ code Why my code is not compiling? :( #include <iostream> #include <iomanip> #include <string> using...
C++ code Why my code is not compiling? :( #include <iostream> #include <iomanip> #include <string> using namespace std; const int CWIDTH = 26; int main() {    int choice;    double convertFoC, converCtoF;    double starting, endvalue, incrementvalue;    const int CWIDTH = 13;    do {       cin >> choice;    switch (choice)    {        cin >> starting;    if (starting == 28){       cout << "Invalid range. Try again.";    }    while (!(cin >> starting)){       string  garbage;       cin.clear();       getline(cin, garbage);       cout << "Invalid data Type, must be a number....
I have the following python code. I get the following message when running it using a...
I have the following python code. I get the following message when running it using a test script which I cannot send here: while textstring[iterator].isspace(): # loop until we get other than space character IndexError: string index out of range. Please find out why and correct the code. def createWords(textstrings): createdWords = [] # empty list for textstring in textstrings: # iterate through each string in trxtstrings iterator = 0 begin = iterator # new begin variable while (iterator <...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT