Is it possible to use a for loop in place of a while loop?
Yes.
while loop consist of only condition statement to make for loop look as while loop we can use syntax shown below:
for(;condition;)
eg:
for(;i<=n;)
#include<iostream>
#include<iomanip>
#include<time.h>
template<typename T>
size_t find(T& data, T a[], size_t size)
{
size_t index=0;
do {
if(a[index]==data)
break;
} while(++index<size);
return(index);
}
template<typename T>
void print(T a[], size_t size)
{
using std::cout;
using std::endl;
using std::setw;
size_t index=0;
do{
if(index&&index%20==0)
cout<<endl;
cout<<setw(3)<<a[index];
}while(++index<size);
cout<<endl;
}
int main()
{
srand((unsigned)time(NULL));
const size_t size=100;
unsigned int a[size];
size_t index=0;
do{
unsigned int data=rand()%100;
do{
data=rand()%100;
} while(find(data,a,index)<index);
a[index]=data;
} while(++index<size);
print(a,size);
}
How long does it take to write an application with a programming language?
It can be one minute for one person, and can be ten year for thousand people.
What is the difference between the structure tag and structure variable?
The structure tag is a type. The structure variable is an instance of that type.
How to Write a c plus plus program to insert a value n after the node in the linked list?
To insert a value after a node in a linked list, first allocate and initialize the node, then add it to the current node...
newnode* = new node (n);
newnode->next = current.next;
if (current != head) current->next = newnode; else head = newnode;
What are the benefits of byte as a datatype?
A byte is the smallest unit of addressable storage. Although a bit is smaller than a byte, a single bit cannot be addressed directly; we always deal with groups of bits and a byte is the smallest group of bits that can be physically addressed. However, once we have addressed a byte, we can then examine the individual bits within it using the bitwise logic operators (AND, OR, NOT and XOR).
On most systems a byte is exactly 8 bits in length. The reason for this is simply that we can represent any 8-bit value using a convenient two-digit hexadecimal notation, where each hex digit represents exactly 4-bits (often called a nybble because it is half-a-byte). Thus an 8-bit byte can be represented by any hexadecimal value in the range 0x00 to 0xff (or 0 to 255 decimal).
(Some systems use odd-size bytes, such as a 9-bit byte. For this we typically use 3-digit octal notation because an octal digit represents exactly 3 bits. Such systems are rare, but we sometimes come across other odd-sized bytes, especially in older data transfer systems such as dot-matrix printers which utilised a 7-bit byte. However, in modern architecture, we can safely say that a byte is always at least 8 bits long.)
Not all programming languages utilise a byte data type as such. C, for instance, doesn't have a built in byte data type but it does have a char data type which is always 1 byte in length. There's no real reason why there isn't a byte data type in C, but when all data types are measured in terms of bytes it was probably deemed unnecessary to say that a byte is 1 byte in length. Although a char is typically used to encode a single character from a character set (and has built in overloads specific to that purpose), the encoding is no less numeric than a byte would be, so there was no real need for a separate byte data type.
Although a single byte can represent any decimal value in the range 0 to 255, it is more correct to say that a single byte can represent any one of 256 unique abstractions. Whether it is a single character from a character set, an unsigned value in the range 0 to 256, or a signed value in the range -128 to +127, these are merely abstractions. How abstractions are interpreted is entirely down to the programmer and/or the programming language.
What is the structure of nylon 66?
Nylon is a generic name for a synthetic linear polymer with repeating amide groups (-NH-CO-) which is used in the manufacture of textile fibres. Carothers produced Nylon 66 by condensation reaction of adipic acid (a dicarboxylic acid with 6 carbon atoms) and hexamethylenediamine (a diamine with 6 carbon atoms) give the [-NH-(CH2)6-NH-CO(CH2)4-CO-] repeating unit. Nylon revolutionised the textile industry and was the forerunner for many of today's modern, synthetic fabrics.
You cannot throw an exception from a destructor?
Sure you can, but it's never a good idea. You must never allow an exception to escape from a destructor. To do so would terminate the destructor prematurely, unwinding the call stack in search of an exception handler. This means that any remaining resources consumed by the instance, including its base classes, would be left in an invalid state with no possible way to recover those resources besides terminating the program. Any object that has the potential to throw an exception during its own destruction should always be treated with suspicion; it is a major design flaw.
How should you design a scientific calculator using C plus plus?
The easiest way to implement a calculator is an RPN calculator (enter the numbers first, perform the operation last). You need a last-in-first-out stack (there's a "stack" class in C++, but you can also implement your own using an array or a linked list), and a set of functions that pop the last elements from the stack and push the result (e.g. Add() pops the last 2 values and pushes their addition).
You'll need the math.h library for scientific operations.
Why wont your c plus plus program stay open?
If you are talking about the program executing, but the output screen being displayed for a flash and then disappearing, I suggest adding getch() or getchar() function at the end of your main function. This will make sure that the output screen waits for you to press a character before the program terminates.
It has several meanings, none of which have anything to do with computer programming. In mathematics, a Quadrature is a numerical integration.
How do you pass an array to a copy constructor in c plus plus?
You cannot pass an array to a copy constructor. A copy constructor only accepts a constant reference to the object being copied, which must be of the same class as the object being constructed. An array is not an object of any class, and therefore cannot be used in any copy constructor.
Although you cannot pass an array to a copy constructor, you can pass an array to a non-trivial constructor. It is not recommended, however, as there's no way to bounds-check the array being passed, which could result in an invalid object being created -- which is never a good thing. Even if you pass the array and its dimension(s) to the constructor, how can you guarantee those dimensions are valid for the array being passed? And what will you do if they are invalid? After all, you cannot veto the construction of an object once you've called its class constructor.
Not knowing why you want to pass an array to a copy constructor, or how you intend to initialise the members via an array, makes it somewhat difficult to determine the best solution for you. However, I would consider using mutators instead of constructors. There's still the problem with bounds-checking but at least you won't have to deal with it during the object's construction.
Why recursive solution is better for tree traversal?
Because a tree is a recursive data-structure. It's easier to write (and easier to understand) a recursive program for handling it.
What Cygwin packages do I need to download for compiling C plus plus files?
g++, gdb and make. A simple search for "Cygwin c++" will tell you all you need to know.
How can you get a specific string from large string using c plus plus strings?
std::string::substr();
What is the use of Constructor with Dynamic allocation?
Constructors are necessary to initialize classes. It allows to avoid to a lot of problems with unauthorized access of memory.
Dynamic allocation makes possible allocation of memory during execution of program. If you do not use dynamic allocation, all required memory will be allocated during initialization phase (constructors are usually responsible for that). But you can't use more memory. Dynamic allocation was designed to overcome such problems.
What is named user plus perpetual?
Named User Plus is the licencing metric for a single unique user. Perpetual relates to the term of the licence. Being perpetual means that the licence lasts for life.
What is the advantage of breaking applications code into several small functions?
BY breaking the code into various member functions, it becomes easy to make any desired changes in the program. It becomes easy to comprehend the code.
The most important use of pointers comes when we pass value by reference to any function. You do not need to create a second memory location as in pass by value. You can mofify the original variable by using its address.