answersLogoWhite

0

📱

Computer Programming

A category for questions about computer programming and programming languages.

10,506 Questions

What are the advantages and disadvantages of employing the using directive?

The using-directive is often confused with a using-declaration. A using-declaration adds a given name to a local scope whereas a using-directive does not; it simply makes names accessible in the scope in which they were declared. For example:

namespace X { int i=0, j=0, k=0; }

int k=42; // global scope

// using-directive example:

void f1 (void) {

int i=0; // local scope

using namespace X; // make names from X accessible

i++; // local i

j++; // X::j

k++; // error: X::k or global k?

::k++; // global k

X::k++; // X::k

}

// using-declaration example:

void f2 (void) {

int i=0; // local scope

using X::i; // error: i declared twice!

using X::j; // ok

using X::k; // hides global k

i++;

j++; // X::j

k++; // X::k

}

Polluting the global namespace should always be avoided in non-trivial applications, however we often encounter tutorial code with an implied using namespace std; directive in the global scope to help the student focus on the actual code. We would never do this in production code. Ideally, the only name that should ever be visible in the global scope is the global main function. Everything else should ideally be put in their own namespaces and only imported into a local scope as and when they are actually needed. If we should require additional names to be accessible in the global scope, then these should be limited to just those names which represent truly global concepts.

Large programs tend to use a lot of namespaces and it can be tedious typing them out in full, particularly when they are nested or long and descriptive names. A using-declaration (at local scope) helps us to isolate just those names we are actually interested in, but if we need to use a lot of names from the same namespace, a using-directive helps cut down on the verbosity.

Namespace aliases are also useful for reducing long, descriptive names to a less verbose form in order to aid readability:

namespace American_Telephone_and_Telegraph { /* ... */ } // too long

// ...

namespace ATT = American_Telephone_and_Telegraph; // alias

You might ask why the programmer didn't simply use ATT in the first place, but short names greatly increase the risk of a name-clash. Thus it is better for the programmer to introduce shorthand aliases as and when they are actually required.

Naturally, we should avoid using-directives, using-declarations and namespace aliases in headers, because we cannot predict exactly where those names might be included, resulting in namespace pollution that can lead to some very obscure or subtle errors that would be difficult to track down.

What is the old Warcraft directory?

The old Warcraft directory was C:\games\Warcraft. This changes depending on which version (WC, WC2, WC3 and so on) as well as your operating system.

How do find the circumference of a circle?

The formula;

2 * Pi * Radius = circumference

Will calculate the circumference of a circle.

How do you integrate with opera pms database?

I would like to make a small software tool with specific features, one of them requires me to retrieve information for the Hotel's Opera Management Software.

Is that possible?

What is stack segment?

I will start with a small explanation. An object code genearated by a compiler or assembler by processing a source code file, is structured as blocks of data called segments, each contain a certain type of data. The types supported are the following. BSS or Block started by symbol, Text/code , data, heap and stack.

Data Segment - global and static data which are initialized to non-zero

BSS - global and static data which are initialized to zero

Heap - dynamically allocated variables

The above three are often referred together as data-segment

Text/Code - contains machine instructions / executable computer instructions

Stack - contains local/auto variables,which will be pushed in and popped out during the call to the function.

ang tinda ni cha bating na okuy ay masiramon..bakal na kamo!! tapos si chu ruben ay pasmado na kakakayo...nag niriwang na! tenk you..eyo man lang tabi.

Example of sort program in easytrieve?

You can sort the output using the keyword 'SEQUENCE'.

PRINT PAY-RPT

REPORT PAY-RPT LINESIZE 80

SEQUENCE DEPT

CONTROL DEPT

SUM GROSS

TITLE 01 'PERSONNEL REPORT EXAMPLE-1'

HEADING NAME ('EMPLOYEE' 'NAME')

LINE DEPT NAME EMP# GROSS NET-PAY DEDUCTIONS

Is it true that the only way to transfer control from one place in the program to another in OOP is by using goto statement?

No. That is only true in procedural languages. Although it is permitted to use goto statements in structured and object oriented languages, its usage is limited to local scope only, which reduces the "spaghetti code" that was prevalent in all procedural languages, and still is in low-level assembler and machine code.

What facility static gives in class?

Static variables or function provides global view to the application that is u can access a static variable with one or more than one objects of a single class without loosing i.e. reinitializing its value.

Write a routine to implement the t e x t function?

There are many ways you could write a routine to implement text functions. You could, for example, come up with codes.

How do you think that hackers may be able to blackmail companies?

well maybe by hacking into their entire database, splicing encrypted files, finding bad information the company has payed millions to keep hidden. then, the hacker uses the information and says 'pay me a million or else

What is the decimal equivalent of 1111 in binary?

1111 converted from binary (base 2) to decimal (base 10) is 15

When you expand the steps...

1111 binary

= (1 X 2^3) + (1 X 2^2) + (1 X 2^1) + (1 X 2^0)

= 8 + 4 + 2 + 1

= 15

When a object is passed to a function as argument why it is not generating an error if the parameterized constructor is defined and not the default constructor?

default constructor is used only when the programmer does not use a constructor to initialize objects. Once the programmer defines a constructor then the default constructor is no longer used

What is a program that produces an onscreen or printed document from all or part of a datbase?

report generator

************************************

A database on a spreadsheet that could be used in a mail merge to produce a document. There are other database programs that would save, sort, and produce a document - LibreOffice Base is one I often use (but then, I use Ubuntu, and don't use MS Windows!).

How do you attach parity bit in c language?

for example:

unsigned char attach (unsigned char byte, unsigned char bit)

{

unsigned char mybyte;

mybyte = byte&0x7f;

if (bit) mybyte |= 0x80;

return mybyte;

}

Write a shell program to find given no is even or odd?

The pseudo code would be as follows (you figure out the syntax)

1) Prompt the user to enter a number

2) If entered number is alpha, quit program after displaying message that the user ended the program.

3) Otherwise, find Modulo 2 of the entered number. This is a fancy way of saying "find the remainder when the number is divided by 2)

4) If Modulo 2 is zero, the number is even, otherwise odd

5) Display message showing if the entered number was Even or Odd

6) Branch back to step 1

What is the difference between a string and an array?

Nothing whatsoever. A string is simply an array of type char.

In some programming languages, such as C, a string is an array of char (or short), terminated with a null \0.

An array is just a fixed size of collection, a container to hold things/objects. If all the elements in the container are characters (of char), then we may call it a string, sometimes a byte array (because each character can be represented as a byte).

An array of 7 different days, it maybe a WEEK, or just the birthdays of 7 dwarfs. Then they are nothing to do with strings.

A data item (or variable) is described as a "string" type when it contains some number of characters. Those characters can usually be anything in the system's accepted list of codes. Most systems use ASCII, so a string can include the letters a-z, A-Z, numbers 0-9, and special characters like ~!@#$%^&*()_+-=[]\{}|:";'<>?,/. A string is treated as a single object, although most programming languages have methods to break strings apart (called sub-stringing). In the Perl language, strings are named $something.

An array is a collection of individual data items, sort of like a list. Each element in an array can be referred to in a program by its position in the list. In the Perl language, an array would be named @SOMETHING. The first element in the array would be named $SOMETHING[0], the second $SOMETHING[1], and so on. Each element can be a string, or some other data type.

Other data types would be integers (positive or negative whole numbers), floating point (decimal numbers like 3.14159 or 2398.41; it can be more complicated than this, but that's another story), and a few more exotic types.

In the C programming language a string is actually the same as an array of characters. The last character in a C string is a zero byte which indicates the end of the string.