answersLogoWhite

0

📱

Computer Programming

A category for questions about computer programming and programming languages.

10,506 Questions

How would you write a program that counts the number of vowels in a string in assembly language?

int countVowels(const char* str) {

int i = 0;

int numVowels = 0;

while(str[i] != '\0') {

switch(str[i]) {

case 'a':

case 'e':

case 'i':

case 'o':

case 'u':

++numVowels;

}

++i;

}

return numVowels;

}

static int countVowels(String str) {

int numVowels = 0;

foreach(char ch in str) {

switch (ch) {

case 'a':

case 'e':

case 'i':

case 'o':

case 'u':

++numVowels;

break;

}

}

return numVowels;

}

What is Variable Scope?

The scope of a variable is the range, or area, in which a variable exists.

// this c is global and can be referenced from anywhere

int c = 1;

void foo() {

// this c is local to function foo and can't be referenced from the outside

int c = 2;

}

void bar() {

// if we try to reference c here, we get the value 1 from the global variable

}

What is high-level language compiled?

Compiling a high-level language means that the high-level source code (what is typed by the programmer) is being converted to machine code (binary, i.e. 0's and 1's) that the local computer can execute. In interpreter languages, the source code is first converted to byte code, which is either run directly (slower, but very portable), or interpreted by a virtual machine (see JVM) into machine code, and then executed (faster, but somewhat less portable). If an error is found the compilation stops and the errors are displayed.

What optional statement can be used in a case structure to execute statements when all other conditions are false?

default : <statement>;

i.e.

switch (value) {

case 1 : do_this(); break;

case 2 : do_that(); break;

default : do_whatever();

}

What is called if an assembler that runs on one machine but produce machine code for another machine?

It's still an assembler, just because the machine it is assembled in isn't running doesn't mean the name changes.

What function enables the user to input information while the program is being executed in c?

The scanf() function is a commonly used function to input information during the execution of a program. scanf() function has its prototype in the stdio.h header file.

To accept and display a number:

int num;

printf("Enter a number: ");

scanf("%d",&num);

printf("You entered %d",num);

To accept and display a character, replace %d with %c and make num a character variable [char].

Plus: gets, fgets, read, fread, getchar, getc, fgetc, getch...

What are the advantages of HashSet over Array?

Array list and linked list are very effective Data Structures. However, ArrayLists are not effective for adding and removing elements in between and Linked Lists take a lot of time when iterating through the elements. A HashSet is effective in both aspects. However, the selection of HashSet is better if the data we enter needs to be traversed while addition and removing is frequent. Further, HashSet cannot have duplicates. So in places where we need to avoid duplicating data, HashSet would be the key.

What is the technical name for a number with a decimal point?

A number.

37. is a number with a decimal point and it is an integer.

37.2 is a rational number.

37.23459... which continues for ever, without coming to a recurring pattern is an irrational number.

Multiprogramming with variable partition?

Multiprogramming - variable partitions

  • Variable partitions - allowing jobs to use as much space as they needed (limit being the complete memory space)
  • No need to divide jobs intotypes- reduce waste if jobs could not fill partition

However, complete wastage is still not reduced

  • Consider what happens when multiple jobs in memory, and jobs start completing activity- this leads to the creation ofholesin main storage that must be filled.

How do you convert a pdf file into a doc file using VB code?

You will need a PDF server running somewhere that can be accessed by your VB code. It will need to be called from the code through the server and get the PDF file in return.

I did that with Tweak PDF Converter, an pdf editor for converting pdf file to word form.

Write a program using method plainto check whether a string is a palindrome or not A palindrome is a string that reads the same from left to right and vice-versa?

Palindrome number is a number like 121 which remains the same when its digits are reversed. To find this number in a simple java program, just follow the below way. sum = 0; while(n>0) {

r=n % 10; sum=concat(r); n=n / 10; } print r;

What is the Real Address System 038413807?

you probably mean the mac address that's the address your device wireless or network card has embeded into it.

How do you figure out alphanumerics?

if you are talking about the more general CS term of alphanumerics, then you are talking about all printable characters such as all letters, numbers, symbols, punctuation marks, etc. So, if your question is what are alphanumerics, there you go.

Now, if you want to know about hexadecimal, then look at it this way. What we use for our numbering system is base 10 and, thus, the reason that it is called Decimal. Deci- is a prefix meaning ten, after all. Hexadecimal is a combination of the two prefixes Hex- and Deci-. In this case, they are to represent six plus ten or, in other words, base 16. Now since there are only ten numerals in our numbering system, we had to borrow some letters to stand in for the additional numbers, specifically A through F.


So, how does hexadecimal work? It works just like decimal: you can have up to the base number minus one as the maximum value for each place. So, for the ones place, you can have values 0 through 9. The same with the next place, which is called the tens. So, the number 63 means 6 in the tens place and 3 in the ones place. In hexadecimal, the same pattern holds true but the maximum value increases. The minimum of course is still zero but the top value is F. So, if you want to see how it works, let's use the hexadecimal value of 3F. This means that there is a 3 in the sixteens place (it is sixteens because this is hexadecimal, so a base 16 numbering system) and F in the ones place.


Now, you might want to try to figure out how to convert from hexadecimal to decimal. Well, it's very simple. Since we know that 3F is 3 sixteens and F ones, we can do a bit of easy multiplying. 3 x 16 is 48 and F is the maximum value that can be in a place in base 16, so as the rule said, that must mean that it is the base value minus 1, which is 15. So, 3F is 48 plus 15, or 63. (Hmmm, interesting how that worked out, huh? ;-) )


Now, what about larger values? The same pattern continues. In decimal, the places are singles, tens, hundreds, thousands, etc. Each time we move a place to the left, the value increases by a factor of ten. Basic, right? Well, the same pattern holds true for hexadecimal but it instead increases by a factor of sixteen. Thus, you have singles, sixteens, 256s, 4096s, etc. So, to show how it works, let's try 3F0. This means that we have 3 in the 256s place, F in the 16s place, and 0 in the singles. Once again, we do a bit of multiplication. 3 x 256 is 768, and F x 16 equals 240, so 3F0 is 768 plus 240, or 1008.


If you want to convert from decimal to hexadecimal, it is a bit more complex since most people don't think that way but it still isn't difficult. Let's convert 1008 back to hexadecimal. So we know that we have 1 in the thousands, 0 in both the hundreds and tens, and 8 in the singles. Well, we know that the maximum place with which we will be working is the 256s since the next step up is the 4096s. So, we are certain this will be a three-digit number. So, to start, how close to 1008 can we come with multiples of 256 without going over? That would be 3 256s, leaving a remainder value of 240 (in decimal, of course). So, we move to the next place: the 16s. How many multiples of 16 can we get out of 240 without going over? That is fifteen but we cannot write it as 15 of course, because that is decimal notation. In hexidecimal, that value is written as F. Since there is no remainder from that solution, we know that the singles value has a 0 in its place. Thus, the conversion of 1008 in decimal is 3F0 in hexadecimal.


Does this help you with either interpretation of your question? If you have any other questions or if this is about as clear as mud at midnight, let me know and I will be glad to assist you further.

Where we can use dijkstra's algorithm?

A practical application is in certain routing protocols, like OSPF. The problem it solves is to search for the "shortest" path to each destination - "shortest" meaning the one that has the lowest "distance" or "metric" according to the criteria used.

Dijkstra's algorithm is easy to use and is a good graph search algorithm to use when it is hard to calculate the heuristics.

Design a While loop that lets a user enter a number?

The only reason to use a "while" loop is to reject invalid data. In pseudocode, it is something like this:

do {

(ask for number - store to variable "x")

} while ("x" is invalid)

The details within parentheses will depend on the programming language. The condition for the "while" also depends on the condition you want to fulfill; for example, you might reject a number that is negative or zero. Note that this uses a "while" that is evaluated at the end; in this case, the loop is executed at least once. If the condition is more complicated to evaluate - for example, the data is input as text and you need to reject non-numeric input - you can do additional processing within the loop, and set a variable "valid" that will be true if the input is valid. In that case, the last line will simply change to:

... while (!valid)

How many steps are involved in writing a computer program?

It depends on the type of computer program you desire. At the bare minimum you need 3 steps in order to make a simple program. The first that is learning you compiler's language (example: JavaScript, C++, C# ect.) and next is to learn how to avoid syntax errors and then create the program that you want. For example, to make a simple execution program using command prompt you will have to learn the commands of a .bat file and then order the commands correctly in order for command prompt to execute and then let it run. Most of programming is trial and error thought the more you get acquainted with your compiler the easier and better you'll become a making your program.