12.1932631112635318
if you have a calculator large enough, you can work the rest out yourself
How do you print a pyramid of numbers C plus plus?
#include<iostream>
#include<vector>
#include<string>
#include<random>
#include<ctime>
void print_pyramid (const std::vector<int>& v)
{
size_t tiers {v.size()}, spaces {1}, row {1};
while (tiers > row)
{
tiers -= row++;
++spaces;
}
tiers = spaces + 1;
std::vector<int>::const_iterator i=v.begin();
for (size_t tier=0; tier!=tiers; ++tier)
{
if (spaces)
std::cout << std::string(spaces--,'\t');
for (size_t num=0; num!=tier && i!=v.end(); ++num)
std::cout << *i++ << "\t\t";
std::cout << std::endl;
}
}
int main()
{
std::default_random_engine generator ((unsigned)time(0));
std::uniform_int_distribution<int> distribution (1,100);
for (size_t loop=0; loop!=5; ++loop)
{
size_t max = distribution (generator);
std::vector<int> v;
v.reserve (max);
for (size_t i=0; i!=max; ++i)
v.push_back (distribution (generator));
print_pyramid (v);
}
}
1>an array is a static data structure.after declaring an array it is impossible to change its size.thus sometime memory spaces are misused.
2>each element of array are of same data type as well as same size.we can not work with elements of different data type.
3>in an array the task of insertion and deletion is not easy because the elements are stored in contiguous memory location.
4>array is a static data structure thus the number of elements can be stored in it are somehow fixed.
C plus plus programming language program for hybrid inheritance?
There's no such thing as hybrid inheritance in C++. Hybrid inheritance implies two or more different types of inheritance but there are really only two types of inheritance in C++ and they are mutually exclusive: single inheritance and multiple inheritance.
A class that inherits directly from one class uses single inheritance.
A class that inherits directly from two or more classes uses multiple inheritance.
The only way to combine these two inheritance patterns is through multi-level inheritance, where a class inherits directly from one or more derived classes. However, whenever we create a derivative, we're only concerned with the base class or classes we are directly inheriting from. The fact they may or may not be derivatives themselves is largely irrelevant from the viewpoint of the derivative. Indeed, the only time we really need to consider one of the lower bases classes is when we need to explicitly invoke a virtual function of that particular class, as opposed to implicitly invoking the most-derived override of that function as we normally would. However, this is really no different to a derived class override invoking its direct base class method.
Virtual base classes are also thought of as being a type of hybrid inheritance, however virtual base classes merely determine which class is responsible for the construction of those classes. Normally, a derived class is responsible for the construction of all its direct base classes, which must be constructed before the derived class can begin construction. In turn, those base classes are responsible for the construction for their own base classes. In this way, derived classes are automatically constructed from the ground up, base classes before derived classes, in the order declared by the derived class.
For example, consider the following hierarchy:
struct X {};
struct Y : X {};
struct Z : Y {};
Z inherits from Y so in order for a Z to exist we must first construct a Y. By the same token, Y inherits from X so in order for a Y to exist we must first construct an X. Thus when we initiate construction of a Z, that initiates construction of a Y which initiates construction of an X.
Now consider a virtual base class:
struct X {};
struct Y : virtual X {};
struct Z : Y {};
The construction sequence is exactly the same as before (X before Y before Z), the only difference is that when we now instantiate a Z, as the most-derived class in the hierarchy it becomes responsible for the construction of the virtual X. Z is also (still) responsible for the construction of a Y, but Y no longer needs to construct an X because a (virtual) X already exists.
Virtual base classes become more relevant in multiple inheritance, where two or more base classes share a common base class:
struct W {};
struct X : virtual W {};
struct Y : virtual W {};
struct Z : X, Y {};
Here, Z uses multiple inheritance from X and Y. Both X and Y use single inheritance from W. Without virtual inheritance, Z would inherit two separate instances of W, specifically X::W and Y::W. But by declaring W as a virtual base of X and Y, the most-derived class, Z, becomes responsible for the construction of W, as well as its direct base classes, X and Y. Neither X nor Y need to construct a W because a W will already exist. Thus X::W and Y::W now refer to the same instance of W.
Note that we do not need to write any additional code for this mechanism to work. The virtual keyword alone is all we need. Even if X or Y provided explicit initialisation of W, those initialisers would be ignored by the compiler since initialisation of W is automatically the responsibility of the most-derived class. The only time those explicit initialisers would be invoked is if we explicitly instantiate an instance of X or Y, because then X or Y become the most-derived class.
What are range of character data type in c plus plus?
The range of character data types in C++ is the set of characters in the host's character set.
It is inappropriate to consider the numerical range of such things as characters, because that depends on the particular codeset involved, such as ASCII, EBCDIC, UNICODE, KANJI, etc. Doing that leads to non-portable code, and lazy programming practices. Do not write code that depends on the collating sequence of the character set, or the numerical difference between two characters.
Type char can be signed or unsigned, the value range is -128..127 or 0..255 respectively.
What is the difference between the calling function and called function?
Function calling is when you call a function yourself in a program. While function invoking is when it gets called automatically.
For example, consider this program
struct s
{
int a,b,s;
s()
{
a=2;
b=3;
}
void sum()
{
s=a+b;
}
};
void main()
{
struct s obj; //line 1
obj.sum(); // line 2
}
Here, when line 1 is executed, the function(constructor, i.e. s) is invoked.
When line 2 is executed, the function sum is called.
Disadvantages of object-oriented programming language?
There are no disadvantages in OOP itself -- it's just a tool. Like any other tool, if used appropriately, there can be no negatives. But if used inappropriately, companies could collapse and countries could fall. The secret to good OOP code is simply good design. Get that wrong and you'll spend most of your time redesigning instead of addressing the problem you were actually trying to solve.
Not every problem can be addressed with OOP -- it is not a silver bullet (and was never intended as such). If the data is modelled on a relational database, then OOP is probably the best approach, but for anything else you'd be better looking elsewhere before considering OOP. By the same token, C++ isn't always the best language to use when you want a working solution as quickly as possible, but at least you get the choice whether to use OOP or not. Some languages give you no option whatsoever, which is disadvantageous by itself.
#include <stdio.h>
int main ()
{
int year,days,d;
printf("year?"); scanf("%d",&year);
days = 365*year + (year-1)/4 - (year-1)/100 + (year-1)/400 ;
d=days%7;//to find which day of week
if(d==1)
printf("\n\n\tmonday");
else if(d==2)
printf("\n\n\ttuesday");
else if(d==3)
printf("\n\n\twednesday");
else if(d==4)
printf("\n\n\tthursday");
else if(d==5)
printf("\n\n\tfriday");
else if(d==6)
printf("\n\n\tsaturday");
else if(d==0)
printf("\n\n\tsunday");
return(0);
}
Sample of c plus plus program using a class?
#include <iostream>
class foo{}; // Minimal class declaration.
int main()
{
foo a; // Instantiate an object of the class.
foo b(a); // Instantiate a copy of the class.
return(0);
// Both objects fall from scope at this point.
}
What is an array and how do you use them in c and c plus plus?
#include<iostream>
#include<vector>
int main()
{
std::vector<int> v {1, 4, 8, 15, 23}; // initialise array with 5 elements
v.push_back (42); // add a 6th element
for (auto i : v) std::cout << i << std::endl; // print array elements
}
Conventional base class in c plus plus?
A conventional base class is a class that has a virtual destructor. Virtual destructors are important in most class hierarchies because while we may not always know the exact type of the most-derived class in a hierarchy, we will always know at least one of its base classes. If we destroy that base, it is reasonable to expect the entire object to be destroyed, not just the base, and this can only be achieved with a virtual destructor.
Note that a virtual destructor must be declared in the least-derived class in the hierarchy to ensure correct polymorphic behaviour.
Classes not intended to be used as base classes do not have virtual destructors. This does not mean they cannot be used as base classes, but if you choose to use them as base classes you must be aware of the "unconventional" problems that can arise, particularly when destroying objects through pointers or references to their base classes as will lead to resource leaks.
If you do not wish a class to be used as a base class, then the class should be declared final (since C++11). All other classes can still be used as base classes, however only classes with virtual destructors behave polymorphically.
Typically, if we define at least one virtual function in a class, we should also define a virtual destructor for that class. However, derived classes implicitly inherit virtual destructors from their bases thus the absence of a virtual destructor in a derived class should not be taken to mean the derived class is not intended to be used as a base class; always look at the least-derived class definition to determine if a virtual destructor exists or not.
Along with the final specifier, the overridespecifier was also introduced in C++11. This makes it much easier to document virtual functions and their overrides. That is, we can use the virtual specifier solely to introduce a new virtual function into the class hierarchy, and use the overridespecifier to show that we are explicitly overriding a virtual function rather than simply introducing a new virtual function. We can also use the final specifier to indicate that an individual virtual function cannot be overridden any further:
struct X {
virtual void f ();
virtual ~X ();
};
struct Y : X {
void f () override; // implies X::f() is either virtual or is itself an override
~Y () override; // implies ~X() is virtual or is itself an override
};
struct Z : Y {
void f () override; // implies Y::f() is either virtual or is itself an override
~Z () override; // implies ~Y() is virtual or is itself an override
};
The override and final keywords are only useful if used consistently. However, being part of the language itself means we can now enlist the help of the compiler to catch subtle errors that couldn't be easily caught before:
struct X {
void f () override; // error! X did not inherit an f () thus it cannot be an override!
virtual void g (); // ok
virtual ~X(); // ok
};
struct Y : X {
void g () override final; // ok
~Y () override; // ok
};
struct Z : Y {
void g () override; // error! Y::f() is declared final -- it cannot be overridden!
~Z () override; // ok
};
struct Z2 : Z final {}; // ok
struct Z3 : Z2 {}; // error: Z2 is final -- cannot be used as a base class!
How do you implement queue using stack in c plus plus?
A queue in any language is a singly-linked list structure that permits new data to be inserted only at the end of a list while existing data can only be extracted from the beginning of the list. Queues are also known as a first in, first out (FIFO) structure. Unlike a standard singly-linked list, the list maintains a pointer to the last node as well as the first, in order to insert new data and extract existing data in constant time.
Variations on the queue include the priority queue which permit data to be weighted, such that data with the greatest priority is promoted to the front of the queue, behind any existing data with the same or higher priority, using an insertion sort technique. Insertion is therefore achieved in linear time rather than constant time, however extraction is always in constant time.
Write c plus plus program of any desending number?
The problem with generating Fibonacci numbers is that they get large very fast. They will eventually exceed the range of even 64 bit integers. In C++, one way to solve this issue is to write a dynamic, arbitrary decimal class.
You could create a linked list, where each element represents a digit. The first element is the units digit, the second the tens digit, the third the hundreds digit, and so forth.
Imbed this linked list into a decimal number class, and provide operators to do various math operations such as addition between two instances of the class. When implementing operator+, for instance, iterate through the elements of both classes, adding them, and applying the carries in each step. If need be, invoke the AddDigit method of the linked list to make the r-value larger by one digit.
With this class, implementing construct, destruct, copy, assign, add, and print, you can generate a Fibonacci sequence using the algorithm of keeping three numbers, and iterating each sequence by adding the prior two numbers and then moving numbers around. (More efficient would be to rotate pointers to the three instances, rather than copying them.) As the instances get reused, it would also be helpful if you did not just delete elements, but, rather, allowed for them to be reused by keeping track of how many are in use versus how many are allocated. (Or you could just zero the excees digits. That is your choice, and it is part of your overall design. Keep in mind that you do know how long the list is, by knowing which element is the last element.)
As you develop this class, you will find more uses that involve other operations, such as multiply and divide. You can extend the class as necessary.
The following example demonstrates a very basic implementation that will generate Fibonacci numbers up to a given length (200 digits in the example, but you could easily generate arbitrary length from user input). The program can also be easily adapted to produce the nth Fibonacci. The implementation of the bignum class could be improved enormously by embedding a pointer to std::vector and implementing a move constructor (like a copy constructor, but ownership of the resources is swapped rather than shared). Also, storing one character per element is highly inefficient, it would be far better to store multiple digits in 64-bit elements. However I've kept the class as simple as possible for the purpose of clarity.
#include
#include
class bignum
{
friend std::ostream& operator<<(std::ostream& os, const bignum& n);
public:
bignum(unsigned int n=0);
bignum operator+(const bignum& );
size_t size()const{return(list.size());}
private:
std::list
};
bignum::bignum(unsigned int n)
{
if( n )do
{
unsigned char digit=n%10;
list.push_front( digit );
} while( n/=10 );
}
bignum bignum::operator+(const bignum& n)
{
bignum result;
unsigned char carry=0, digit=0;
std::list
std::list
while( first!=list.rend() second!=n.list.rend() carry )
{
digit=carry;
if( first!=list.rend() ) digit+=*first++;
if( second!=n.list.rend() ) digit+=*second++;
carry=digit/10;
digit%=10;
if( digit first!=list.rend() second!=n.list.rend() carry )
result.list.push_front( digit );
}
return( result );
}
std::ostream& operator<<(std::ostream& os, const bignum& n)
{
if( !n.list.size() )
os<<'0';
else for( std::list
os<<(unsigned int)*it;
return( os );
}
int main()
{
bignum* num1 = new bignum(0); std::cout<<*num1< bignum* num2 = new bignum(1); std::cout<<*num2< // generate the Fibonacci sequence up to a length of 200 digits while(num2->size()<200) { bignum* num3 = new bignum( *num1+*num2 ); delete(num1); num1 = num2; num2 = num3; std::cout<<*num2< } delete( num2 ); num2 = NULL; delete( num1 ); num1 = NULL; std::cout< }
How do you push and pop stack elements?
algorithm of push
if(top==Max-1)
{
cout<<"\n the stack is full";
}
else
top++;
arr[top]=item;
////////////////////////////////////////
algorithm of pop
if(top==-1)
{
cout<<"\n the stack is empty";
}
else
return arr[top];
top--;
}
Is swallowing semen dangerous if you both have an STD?
There is no risk for disease transmission if you both suffer from the same disease. If you have different diseases, the swallower is probably more at risk from disease transmission than the donor depending, of course, on the method of delivery.
#include<conio.h>
#include<stdio.h>
void main(void)
{
int sell_pr, profit, cost_pr, cost_pr_one_item ;
clrscr();
printf("Please enter the selling price of 15 items:");
scanf("%d", &sell_pr);
printf("Please enter the profit earned on 15 items:");
scanf("%d", &profit);
cost_pr = sell_pr - profit;
cost_pr_one_item = cost_pr/15;
printf("Cost price of one item is %d", cost_pr_one_item);
getch();
}
How does a 'string' type string differ from a c-type string?
A char is a single character. A String is a collection of characters. It may be empty (zero characters), have one character, two character, or many characters - even a fairly long text.
The single quote (') is used to deliniate a character during assignment:
char someChar = 'a';
The double quote (") is used to delineate a string during assignment:
String someString = new String("hello there");
Note that char is a primitive data type in Java, while String is an Object. You CANNOT directly assign a char to a String (or vice versa). There is, however, a Character object that wraps the char primitive type, and Java allows method calls to be made on the char primitive (automagically converting the char to Character before doing so).
i.e. these ALL FAIL:
someString = SomeChar;
someString = new String(someChar);
However, these WILL work:
someString = Character.toString(someChar);
someString = someChar.toString();
Also note that a String is a static memory allocation, while a character's is dynamic. By that, I mean that when a String is created, it is allocated a memory location exactly big enough to fit the assigned string. Any change to that String forces and entirely new memory location to be allocated, the contents of the old String copied in (with the appropriate changes), and the old String object subject to garbage collection. Thus, making changes to a String object are quite inefficient (if you want that kind of behaviour, use StringBuffer instead).
A character is allocated but once; all subsequent changes to a character variable simply overwrite that same memory location, so frequent changes to a character variable incur no real penalty.
What does a statement in c plus plus end with?
A simple statement ends with a semi-colon (';'). A compound statement contains one or more simple statements (with semi-colon terminators) enclosed within opening and closing braces ('{' and '}').
Recursive function to find nth number of the Fibonacci series?
STEP1. Set value of count=1, output=1, T1=0, T2=1
STEP2. Read value of n
STEP3. Print output
STEP4. Calculate
output=T1+T2
STEP5. T1=T2 & T2=output
STEP6. Calculate count= count+1
STEP7. If (count<=n>
go to STEP3
else
go to STEP8
STEP8. End
You could also just plug in n into this formula:
F(n) = [φ^n - (1-φ)^n] / sqrt(5)
φ is about 1.618033989 and is the Golden Ratio
[It's also the limit as n approaches infinity of the nth term in the Fibonacci sequence divided by the (n-1)th term]
Difference between Method overloading and method overriding in C plus plus?
Yes. Any base class method that is declared virtual can be overridden by a derived class. Overriding a method that is not declared virtual can still be called, but will not be called polymorphically. That is, if you call the base class method, the base class method will execute, not the override. To call a non-virtual override you must call it explicitly.
Two example of derived data types in c plus plus?
The fundamental built in data types in C++ are integral (char, short, int, and long) and floating (float, double, and long double1).
The fundamental derived data types in C++ are arrays, functions, pointers, and references.
The composed derivative data types in C++ are classes, structures, and unions.
----------------------------------------------------------
1Microsoft specific ??
Why do you use virtual functions in C plus plus?
Virtual means that decision would be taken at another stage... first base class constructor is called and construction of object cannot be held anonymous. that's y virtual constructors are not possible.
AnswerOne reason is that a constructor cannot be virtual is because it is the constructor's job to fill in the v-table for virtual functions. If a constructor was allowed to be virtual, then you end up with kind of a chicken and egg paradox. In order to call the constructor, the compiler would have to look in the v-table to find where the constructor is located. Unfortunately, it's the constructor's job to place the address of virtual functions (which would include itself) into the v-table. Without RTTI, it would be impossible to resolve which child's constructor to call. In most cases, a virtual helper function that the constructor calls is more then enough.How do you write a c plus plus program to find area of a triangle where base4 and height6?
pi x radius x radius the forula for working out the area of a circle if this is what you're asking.
========================================================
Please give the Proper Answer...
Object oriented design and procedural oriented design?
In object oriented programming main role plays objects and classes, in structure programming all programmes are represented as structures of block's, in procedure programming - that means high level programming languages, which are based on process description (sequence of processes) - all programmes are described like a set of subprogrammes or procedures.
For more information you may search these articles:
http:/en.wikipedia.org/wiki/Object-oriented_programming
http://alarmingdevelopment.org/?p=9
http:/en.wikipedia.org/wiki/Procedural_programming
Is the C Plus Plus language good for making software?
C++ is one of the most flexible programming-languages there is. So, my first answer would be 'Yes'. However the question is, if C++ is the most suited language for the software that you want to make. There may be a alternative, easier language, in wich you can develop your software. Jahewi :-)