answersLogoWhite

0

📱

Computer Programming

A category for questions about computer programming and programming languages.

10,506 Questions

How can you sort an arraylist of strings?

You can sort an ArrayList by using the sort method of the Collecions class (java.util.Collections). Assuming you have an ArrayList called foo: Collections.sort(foo);

In C programming a character variable can at a time store how many characters?

You can store one, however if you make a char array:

char[50];

You can make a string out of your array of characters.

When do you declare a member of a class static?

Static members should be used whenever you have a member that is logically considered part of the class, but is not associated with any instance of the class. They are bit like global variables and functions but there's more control over their visibility outside of the class.

Static member methods can be thought of as being global functions that are scoped to the class (rather than to each instance of the class). As such, they do not inherit an implicit this pointer and can therefore be called without instantiating an instance of the class (access specifier permitting). However, any and all instances of the class have unrestricted access to all the static member methods of the class.

Static member variables can be thought of as being global variables that are scoped to the class (rather than to each instance of the class). That is, all instances of the class share the same set of static member variables amongst them, rather than each having their own (as they would with non-static member variables). Static member variables are also accessible to static member functions. As with all other static variables, they are initialised at compile time (which must be done outside of the class declaration), and will remain in scope for the entire lifetime of the program.

All static members are subject to the public, protected or private access specifiers, so while they can act like global variables and functions if declared public, their visibility outside of the class can be limited to private or protected access.

Possible uses for static members are many and varied. By way of an example, suppose you want to maintain a read-only count of all instances of a class. The following framework demonstrates how this can be done with static members:

class Object

{

public:

Object(){++s_instances;}

~Object(){--s_instances;}

static unsigned int GetInstances(){return(s_instances);}

private:

static unsigned int s_instances;

};

// Static member variable initialiser (evaluated at compile time):

unsigned int Object::s_instances=0;

int main()

{

cout<<"Current instances:\t"<

Object * p1 = new Object();

cout<<"Current instances:\t"<

Object * p2 = new Object();

cout<<"Current instances:\t"<

delete( p1 );

cout<<"Current instances:\t"<

delete( p2 );

cout<<"Current instances:\t"<

}

Output:

Current instances: 0

Current instances: 1

Current instances: 2

Current instances: 1

Current instances: 0

Previous Answer

In the code, if you want to have only one instance of the member variable irrespective of the number of objects created for that class. In these kind of scenarios static members are used

Does a cylinder have 4 sides?

It is the area of the ends of the cylinders which is Pi x r^2 so we have two of those and the total is 2 Pi r2 now add to the the area of the sides. This is 2x Pi x r x h so the total surface area is: 2 Pi r2 +2Pi x r h

Advantage of flowchart in c language?

Pre-test loop in C#

bool condition = false; [NOTE: this line is not part of the loop it is the condition which must be met for the loop to occur. If it is not satisfied the loop does not happen.

while (condition == false)
{
Do stuff
condition = checkCondition();
}

To draw this as a flowchart you just have to show that your flowchart can repeat a step/steps indefinitely depending on a condition

What is 0.65 as a fraction?

0.065 is a fraction. It is a fraction in decimal form rather than in the form of a ratio. However, that does not stop it being a fraction. Its rational equivalent is 65/1000 which can be simplified. But simplification will mean that you lose information about the precision of the fraction.

Name two languages which are used for client side scripting?

Two different client side scripting languages are JavaScript and VBScript.

Scripting languages are not compiled and run on the client machine (in most cases, the web browser.)

There are several currently in use. The most popular is JavaScript. It's a prototype-based, object oriented language, with a Java or C-like syntax.

Microsoft has also produced a competing language called VBScript. VBScript has a syntax based off of Microsoft's Visual Basic programming language. It's used in Active Server Pages, and as the Windows Script Host language, used by sys-admins.

What is the purpose of intermediate code generation incompiler?

The intermediate code generation phase transforms parse tree into an intermediate-language representation of the source program.

Intermediate codes are machine independent codes, but they are close to machine instructions.

The given program in a source language is converted to an equivalent program in an intermediate language by the intermediate code generator.

Intermediate language can be many different languages, and the designer of the compiler decides this intermediate language.

  • syntax trees can be used as an intermediate language.
  • postfix notation can be used as an intermediate language.
  • three-address code (Quadraples) can be used as an intermediate language
  1. we will use quadraples to discuss intermediate code generation
  2. quadraples are close to machine instructions, but they are not actual machine instructions.
  • some programming languages have well defined intermediate languages.
  1. java - java virtual machine
  2. prolog - warren abstract machine
  3. In fact, there are byte-code emulators to execute instructions in these intermediate languages.

What is the circumference of a CD?

12 cm approx I'm a little surprised that you haven't got a CD and some sort of ruler or measuring tape near you. The idea of a homework question like that is to help you get some idea of common sizes.

What Is bool data type?

There are a number of data types that we use in computer science. Bool data type stands for boolean data type. In boolean data type the data is stored in form of 0 ans 1s. On boolean data type logical functions like AND, OR ,NOT ,XOR etc functions can be performed.

Write a C program for Sum of factors of a number?

#include<stdio.h>

#include<conio.h>

void factor(int num)

{

int i,sum=0;

for(i=1;i<num;i++)

{

if(num%i==0)

{

sum=sum+i;

}

}

printf("Sum of the factor of %d is %d",num,sum);

}

void main()

{ int num;

printf("Enter the number=");

scanf("%d",&num);

factor(num);

getch();

}

What is need and characteristics of oop?

OOP stands for Object oriented programming.

The main characteristics of OOP are

1. Class

2. Objects

3. Instance

4. Methods

5. Message Passing

6. Inheritance

7. Abstraction

8. Encapsulation

9. Polymorphism &

10. Decoupling

OOP is a concept that allows us to have a program that is

1. "robust and secure".

2. "architecture neutral and portable".

3. "high performance".

What is meant by syntax rules of programming language and a natural language?

Syntax is defined as a set of rules governing how a language is structured, and the relationships between words, Just as in English * we don't put an adjective after a noun - "I have a car blue new" is wrong and "I have a new blue car" is correct... * and the placement of the verb affects the meaning of the sentence. "I have a new blue car" is very different from "Have I a new blue car".

So too do programming languages have rules which say how pieces of code must relate to one another, and in what sequence they must be phrased.

What is the memory's addressibility?

HI I am Ahtarva,

The addressibility is how many bits does that particular processor or micro-controller's architecture use to specify the address of a memory location in the memory. For example if someone say that addressibility is 8 bit then your memory address contains 8 bits and at maximum you have 2^8 different memory locations (or say memory addresses in your device). Here 2^8 is called Address space.

Which rate is the number of signal transitions per period of time?

The number of cycles per second - if that's what you mean - is called the frequency. The unit is the hertz (Hz).

Is python is easy to learn?

Yes, Python is easy to learn. It's very easy to experiment with because it provides you with a interactive environment in the form of a Python interpreter (written for many platforms including those supported by C, Python, Java, and .NET). Enhanced wrappers and tools around the interpreter, for example ipython, really make learning Python easy. Reducing the compile, link, and load time to zero has the effect of saving you tons of time while learning and not having to deal with the complexities of building software. You can leave that part for Python to figure out all by itself at a preliminary stage.

Now, you may begin learning Python and there are several ways to approach it. If you are already a programmer and would just like to see what features Python has to offer to you, you can start with the Python tutorial located here: http://docs.python.org/tut/tut.html. A tool for the Firefox browser, called the Python Sidebar (found at http://www.edgewall.org/python-sidebar/ ), can aid you to quickly look up Python documentation (including the tutorial) within Firefox.

Instead if you are already an accomplished programmer and prefer learning by breaking down examples of real and useful programs, Dive Into Python (http://www.diveintopython.org) written by Mark Pilgrim is an excellent read.

How to Think Like a Computer Scientist is a good book for beginning programmers starting with Python as their first language. While, a second edition of this book is available for free online (at http://www.openbookproject.net/thinkCSpy/ ) as well, I have only read the first edition (at http://www.greenteapress.com/thinkpython/thinkCSpy/ ) of this book online.

While the above-mentioned books are free for reading online, there are some gems that are commercially available for small prices. Beginning Python from Novice to Professional (Magnus Lie Hetland; Apress) is an excellent book for beginning programmers as well. Text Processing in Python (excellent book by David Mertz; Addison-Wesley), Learning Python (Mark Lutz and David Ascher; O'Reilly), Programming Python (Mark Lutz; O'Reilly), and Python Cookbook (ASPN; O'Reilly) are excellent books on the subject as well.

I hope all this information proves helpful to you.

How do you write a program to compute and print the factorial of given number using a while loop in c plus plus?

// returns n!

int fact(final int n) {

// keep track of factorial calculation in f

// f starts at n, and we will multiply it by all integers less than n

int f = n;

// loop from n-1 down to 2

for(int i = (n - 1); i > 1; --i) {

// increase our total product

f *= i;

}

return f;

}

What is a group of programs that coordinate and control the resources of a computer system called?

A group of programs that coordinate and control the resources of a computer system is called a system software. In other publications, it also includes software development tools like a debugger, linker or compiler.

What is a benchmark?

Benchmarking programs are used to compare computer performance. Here is a list:

3DMark2001se

Most people don't use this program anymore because it's quite outdated, but if you really want the most benchmark utilities you can get then it would be a good program to get. Gamers benchmark. Mediumly recommended.

3DMark03

A program that a lot of people still use. Gamers benchmark. Highly recommended.

3DMark05

A program that only gives good scores if you have very up to date components. Still useful. Gamers benchmark. Mediumly recommended.

PCMark04

Fairly useful benchmarking utility. Mediumly recommended.

PCMark05

An updated PCMark. Mediumly recommended.

SiSoftware Sandra

Very useful benchmarking utility. Able to bench nearly all of you components separately. Highly recommended.

Super Pi

In case the name didn't give it away, this is a program that calculates 4,294,960,000 digits of pi. The benchmark comes in the form of a number (in seconds, perhaps minutes) that shows how long it took your computer to calculate those digits of pi. The simple score readout makes it very easy to compare scores. Highly recommended.

Aquamark3

An excellent gamers benchmark. Fun to watch (at least the first couple times) and very fun UI. Highly recommended.

How do you convert pdf file into word file?

One way is to put the file in a folder, then open that folder, then go to tools at the top and click it, then click folder options, then click the "View" tab at the top, then scroll down about halfway, and uncheck "Hide extensions for know file types", go back to where you can see your pdf or jpeg file in your folder, and rename or put .(some file type) instead of .pdf or.jpg. You should get a pop-up saying "If you change a file name extension, the file may become unusable. Are you sure you want to change it?", go ahead and click yes and it should work.

Structure in c?

Structures are a way of storing many different values in variables of potentially different types under the same name. This makes it a more modular program, which is easier to modify because its design makes things more compact. Structs are generally useful whenever a lot of data needs to be grouped together--for instance, they can be used to hold records from a database or to store information about contacts in an address book. In the contacts example, a struct could be used that would hold all of the information about a single contact--name, address, phone number, and so forth.
->A structure is a collection of related elements , possibly of different types , having a single name.

->"each element in a structure is called field".

->A FIELD is a smallest element of named data that has meaning. It has many characteristics of the variable .

->It exits in memory . it can be assigned values, which in turn can be accessed for selection or manipulation.

-> A field differs form variable primarily in that it is a part of structure.

ITS SYNTAX IS:

struct tag name

{

field list;

};

What is difference between structural language and object oriented language?

I think there is no any difference between object oriented programming language. Because somebody have written that vb is object based language because there is no inheritance, but javascript has no classes and no inheritance but javascript is also object oriented scripting language and java is also object oriented language vb has no inheritance but classes is.So vb is object based language This is not clear that difference between object oriented and object based. if i am wrong than what should be your answer and if i am wright than no problem But first i am requesting to the developer of any programming language that please define the difference between object oriented and object based languages. Amit Sinha Dist-Gaya State-Bihar

Write a program in c language to subtract two numbers?

#include<stdio.h>

#include<conio.h>

int main(void)

{

int sum=0,n,i;

clrscr();

printf("\n Enter two no.");

scanf("%d%d",&n,&i);

sum=n+i;

printf("\n%d+%d=%d,n,i,sum);

getch();

return 0;

}

What is data structute?

A data structure is defined as a way of organizing all the data items that consider not only elements stored but also stores the relationship between those elements.

this is of two types

1.Primitive

2.Non Primitive