Question
engineering computation

4. You were just hired for a summer internship with one of the areas best software compa- nies; however, on your first day o
11. You are playing a game where you roll a die 10 times. If you roll a 5 or 6 seven or more times, you win 2 dollars; four o
7:40+ LTE AA Aereader.chegg.com 8. Write a script named arrayCollide that will combine two arrays, sort them, and then return
7:404 LTE Reader View Available 5. You have a big problem. In one of your CS courses, your professor decides that the only wa
assume that the string will only consist of valid letter grades. For example, CrazyGrade ( BADDAD) should return DFBBFB Cr
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the code for your problem.

function decimal = mybin2real(binarystring)

    % Converts an input string of 1s and 0s to a number.

    Num1 = binarystring;

    LN1 = length(Num1);

    dec1 = 0;

    for ii = 1 : LN1

        dec1 = dec1 + str2double(Num1(LN1-ii+1)) * 2^(ii-1);

    end

    decimal = dec1;

end

while true

% this is the loop that runs forever

    binarystring = input("Enter a binary number: ", 's');

    if isequal((binarystring == '1') + (binarystring == '0'), ones(1, length(binarystring)))

    % display output

        decimalNumber = mybin2real(binarystring)

    else    

    % exit the loop if number include other symbols except 1 and 0

        break;

    end

end

Here is the screenshot of the code if the indentation is not clear.

function decimal = mybin2real(binarystring) % Converts an input string of 1s and Os to a number. Num1 = binarystring; LN1 = l

Here is the output of the code.


Hope this helps.

Please rate the answer if you like it.

Do leave a comment.Any suggestion/query is much appreciated.

Add a comment
Know the answer?
Add Answer to:
engineering computation 4. You were just hired for a summer internship with one of the area's...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PYTHON: Dice Rolling Write a script that takes input for the number of dice to roll...

    PYTHON: Dice Rolling Write a script that takes input for the number of dice to roll and for the number of sides for the dice. Roll that many n-sided dice and store the values an array. Take the number of sides of the dice and the number of dice as typed inputs from the user. Output should be a comma separated list of the die numbers with no spaces like this: 6,4,1,3,1 Write a script that will simulate the roll...

  • CSCI 135 Test 2 Name: 6, (21%) Consider the following definitions: class Student class Section public:...

    CSCI 135 Test 2 Name: 6, (21%) Consider the following definitions: class Student class Section public: string getFirst ) string getLast () int getGrade) void set First (string s) void setLast (string ) void setGrade (nt g): numStudents () Student getNthStudent (int n) string getCourse ) string getInstructor ); private: private: string firstName string lastName Student students [SIZE: string course; string structor; grade; Write a function, honorRoll that returns a dynamic array containing only those students in section sec with...

  • Using the following parallel array and array of vectors: // may be declared outside the main...

    Using the following parallel array and array of vectors: // may be declared outside the main function const int NUM_STUDENTS =3; // may only be declared within the main function string Students[NUM_STUDENTS] = {"Tom","Jane","Jo"}; vector <int> grades[NUM_STUDENTS] {{78,98,88,99,77},{62,99,94,85,93}, {73,82,88,85,78}}; Write a C++ program to run a menu-driven program with the following choices: 1) Display the grades 2) Add grade 3) Remove grade for all students for a selected assignment 4) Display Average for each student 5) Display the name of...

  • using basic c++ please!!! 6. (21%) Consider the following definitions class Student { class Section public:...

    using basic c++ please!!! 6. (21%) Consider the following definitions class Student { class Section public: string getFirst (); string getLast (); intgetGrade () void setFirst (string s); void setLast (string s); void setGrade(int g); numStudents (); in Student getNthStudent (int n); string getCourse (); string getInstructor (); private: private: string firstName; string lastName; int Student students [SIZE]; string course; string instructor; grade ; Write a function, honorRoll that returns a dynamic array containing only those students in section sec...

  • 1.1. Write a function named "areFirstTwoTheSame AsLast TwoChars" that accepts a string. It returns true if...

    1.1. Write a function named "areFirstTwoTheSame AsLast TwoChars" that accepts a string. It returns true if the first two characters and the last two characters of the string are the same. It returns false otherwise. In addition, if the string is empty or has only one character, it also returns false. For example, these are the strings with their expected return values false falsc "AB" true "ABA" false "ABAB" trus "ABBA" false "ABCABC false "ABCCAB" true 1.2 Write a function...

  • In C++ Assignment 8 - Test Scores Be sure to read through Chapter 10 before starting this assignment. Your job is to write a program to process test scores for a class. Input Data You will input a tes...

    In C++ Assignment 8 - Test Scores Be sure to read through Chapter 10 before starting this assignment. Your job is to write a program to process test scores for a class. Input Data You will input a test grade (integer value) for each student in a class. Validation Tests are graded on a 100 point scale with a 5 point bonus question. So a valid grade should be 0 through 105, inclusive. Processing Your program should work for any...

  • Python help! Any help is appreciated, thank you! Fill in the missing function, monthString(), in the...

    Python help! Any help is appreciated, thank you! Fill in the missing function, monthString(), in the program. The function should take number between 1 and 12 as a parameter and returns the corresponding month as a string. For example, if the parameter is 1, your function should return "January". If the parameter is 2, your function should return out "February", etc. def monthString(monthNum): """ Takes as input a number, monthNum, and returns the corresponding month name as a string. Example:...

  • Need help with these array problems. int countAllPunctuation( const string array[ ], int n ); Return...

    Need help with these array problems. int countAllPunctuation( const string array[ ], int n ); Return the total number of punctuation symbols found in all the elements of the passed array argument. For the purpose of this function, the characters '.' , ',', '!', ';', ''', '-', '/', ':', '?', '"' count as punctuation symbols (that is, period, comma, exclamation mark, semicolon, apostrophe, dash, slash, colon, question mark, and double quote). Return -1 if n <= 0. For example, for...

  • Make a public class called ManyExamples and in the class... Write a function named isEven which...

    Make a public class called ManyExamples and in the class... Write a function named isEven which takes in a single int parameter and returns a boolean. This function should return true if the given int parameter is an even number and false if the parameter is odd. Write a function named close10 which takes two int parameters and returns an int. This function should return whichever parameter value is nearest to the value 10. It should return 0 in the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT