Write a c plus plus program that prints your name and address?
#include<iostream>
#include<string>
int main()
{
using namespace std;
std::cout << "Enter your full name: ";
std::string name;
std::getline (std::cin, name);
std::cout << "Your full name is: " << name << std::endl;
}
Which data structure allows deleting data elements from front and inserting at rear?
A linked list is an example for a data structure that allows removal from one end and insertion of new items to the other. Many other data structures support the same operations. They differ in what else they can do, and how efficient the operations can be performed.
What is compound statement in c plus plus program?
A compound statement is a code block. We typically use compound statements as the body of
another statement, such as a while statement:
while (i >= 0)
{
a[i] = x;
++x;
--i;
}
Note that all compound statements are surrounded by braces {}.
What value of c makes the polynomial below a perfect square trinomial x2 8x plus c?
9x + 2 + 24x + c = 33x + 2 + c
If = 0 then c = -33x - 2
if = 1 then c = -33x - 1
if = 4 then c = -33x + 2
in general,
c = -33x -2 + n2 where n is any integer.
C++ is a programming language developed by Bjarne Stroustrup.It inherits many of its functionality from c but also has its own unique features like polymorphism, encapsulation,abstraction, etc. It is both procedural and object oriented programming language. For more information, visit the link below:
Where is the function declare in c plus plus language?
All function interfaces must be declared before they can be used. This is known as a forward declaration and is strictly enforced in C++ (but not in C). To facilitate this, interfaces are typically placed in a header file which can then be included in every source file that requires access to that function. The interface need not be defined (implemented) in the header unless the function is a template function. Typically, implementations are kept separate from interfaces (template function implementations are kept in the header but typically separated from the interface) since the interface contains everything the user needs to know in order to make use of the function.
How do you use Graph in data structure?
Em depends on the points your plotting on the graph. If they are evenly distributed then it's probably a linear graph.
How polymorphism can be achieved by means of virtual functions in C plus plus?
Virtual functions of a class are functions (methods) that can be redefined in a child class and, through polymorphism, the correct function will be invoked depending on the type of the class involved. Virtual functions are declared with the virtual keyword... class myclass {
... virtual int myfunction(...);
... etc.
} When a class contains at least one virtual function, a static virtual table (vtable) is implemented behind the scenes by the compiler. This table is used to point to the correct implementation for that type of class at run-time. Abstract base classes are a special form of class, where they must be derived. They often declare virtual functions which is the defined interface, but through the keyword "= 0" enforce the requirement that the class be derived, i.e. that the class can not be instantiated directly... class myclass {
... virtual int myfunction(...) = 0;
... etc.
} class mysubclass : public myclass {
... virtual int myfunction(...);
... etc.
}
A flowchart is a diagram that shows a continuous flow of materials or steps to (WIP), work in process. Basically it shows the process, steps or task for something to be completed from beginning to end.some give 2 ways give's Can you like show me a picture of one? from:daggettl0976
What is the difference between switch case and if else?
If else can have values based on constraints, where as switch case can have values based on user choice.In if else, first condition is verified, then it comes to else whereas in the switch case first it cheaks the case and then it switches to that particular case.
What are disadvantages of virtual functions in c plus plus?
Virtual functions have many advantages, but here are a couple of their disadvantages:
What is the function of constants in c plus plus?
Constants are simply variables that do not change value. This is particularly useful when we need to continually refer to the same value, such as the length of a fixed-length array:
const int array_max = 100;
int array[array_max];
for (int i=0; i<array_max; ++i) {
array[i] = i * i;
}
// ...
Using a constant in this way reduces the maintenance burden considerably. For example, suppose we later decide that we really needed 200 integers in our array instead of just 100. So long as our code uses the constant, array_max, we need only change the constant's value and that change will be reflected wherever the constant is used. If we has used the literal constant, 100, instead, we'd need to search through our code and update each usage of that literal. That can lead to human errors and inconsistency in our code.
All constants are allocated in the static segment (where all static variables are allocated) even when they are declare locally. The one exception is a constant formal argument:
void f (const int i) {
// ...
}
Arguments are always passed by value, so i will hold a copy of whichever value was passed to it. Being a copy, any changes made to i will not be reflected in the calling code, however if the function must not modify the value, declaring the formal argument constant ensures we don't inadvertently change the value.
Typically we use constant formal arguments when those arguments are pointers or references rather than values. When we pass an object by reference or by pointer, we are passing a copy of the object's address and this would allow the function to indirectly modify the object. This is known as a side-effect and is undesirable. To give assurance to the caller that the object will not be changed, we use a constant reference or pointer:
void f (const obj& x) {
// ...
}
If we actually want the function to modify the object, the best method of doing so is to return a new object by value and leave the argument constant:
obj f (const obj& x) {
// ...
}
In this way the caller can decide what to do with the returned object:
obj y;
obj z = f (y); // create a new object from y without changing y
y = f (y); // modify y
f (z); // ignore the modification completely
Note that returning objects by value is normally expensive as the object must be copied. However, objects that implement the move semantic can be returned extremely efficiently, particularly those objects that are really just resource handles. This includes all the standard library containers such as std::vector and std::list. Moving a vector is many times quicker than copying one because all we're really doing is changing ownership of the resource; and that's (almost) as efficient as copying a pointer and assigning NULL to the original.
What is the difference between int main and int void?
int main() refers that main function returns an integer value, where the integer value represent the program execution status. This status value is sent to the Operating System. If you follow strictly follow the rules, then it should be int main not void main()
Concept of object oriented programming?
Java is an object oriented programming language. The main concepts used in Java are:
Class
Defines the abstract characteristics of a thing (object), including the thing's characteristics (its attributes, fields or properties) and the thing's behaviors (the things it can do, or methods, operations or features). One might say that a class is a blueprint or factory that describes the nature of something. For example, the class Dog would consist of traits shared by all dogs, such as breed and fur color (characteristics), and the ability to bark and sit (behaviors). Classes provide modularity and structure in an object-oriented computer program. A class should typically be recognizable to a non-programmer familiar with the problem domain, meaning that the characteristics of the class should make sense in context. Also, the code for a class should be relatively self-contained (generally using encapsulation). Collectively, the properties and methods defined by a class are called members.
Object
A pattern (exemplar) of a class. The class of Dog defines all possible dogs by listing the characteristics and behaviors they can have; the object Lassie is one particular dog, with particular versions of the characteristics. A Dog has fur; Lassie has brown-and-white fur.
Instance
One can have an instance of a class or a particular object. The instance is the actual object created at runtime. In programmer jargon, the Lassie object is an instance of the Dog class. The set of values of the attributes of a particular object is called its state. The object consists of state and the behaviour that's defined in the object's class.
Method
An object's abilities. In language, methods (sometimes referred to as "functions") are verbs. Lassie, being a Dog, has the ability to bark. So bark() is one of Lassie's methods. She may have other methods as well, for example sit() or eat() or walk() or save_timmy(). Within the program, using a method usually affects only one particular object; all Dogs can bark, but you need only one particular dog to do the barking.
Message passing
"The process by which an object sends data to another object or asks the other object to invoke a method." Also known to some programming languages as interfacing. For example, the object called Breeder may tell the Lassie object to sit by passing a "sit" message which invokes Lassie's "sit" method. The syntax varies between languages, for example: [Lassie sit] in Objective-C. In Java, code-level message passing corresponds to "method calling". Some dynamic languages use double-dispatch or multi-dispatch to find and pass messages.
Inheritance
"Subclasses" are more specialized versions of a class, which inherit attributes and behaviors from their parent classes, and can introduce their own.
For example, the class Dog might have sub-classes called Collie, Chihuahua, and GoldenRetriever. In this case, Lassie would be an instance of the Collie subclass. Suppose the Dog class defines a method called bark() and a property called furColor. Each of its sub-classes (Collie, Chihuahua, and GoldenRetriever) will inherit these members, meaning that the programmer only needs to write the code for them once.
Each subclass can alter its inherited traits. For example, the Collie class might specify that the default furColor for a collie is brown-and-white. The Chihuahua subclass might specify that the bark() method produces a high pitch by default. Subclasses can also add new members. The Chihuahua subclass could add a method called tremble(). So an individual chihuahua instance would use a high-pitched bark() from the Chihuahua subclass, which in turn inherited the usual bark() from Dog. The chihuahua object would also have the tremble() method, but Lassie would not, because she is a Collie, not a Chihuahua. In fact, inheritance is an "a... is a" relationship between classes, while instantiation is an "is a" relationship between an object and a class: a Collie is a Dog ("a... is a"), but Lassie is a Collie ("is a"). Thus, the object named Lassie has the methods from both classes Collie and Dog.
Multiple inheritance is inheritance from more than one ancestor class, neither of these ancestors being an ancestor of the other. For example, independent classes could define Dogs and Cats, and a Chimera object could be created from these two which inherits all the (multiple) behavior of cats and dogs. This is not always supported, as it can be hard both to implement and to use well.
Abstraction
Abstraction is simplifying complex reality by modelling classes appropriate to the problem, and working at the most appropriate level of inheritance for a given aspect of the problem.
For example, Lassie the Dog may be treated as a Dog much of the time, a Collie when necessary to access Collie-specific attributes or behaviors, and as an Animal (perhaps the parent class of Dog) when counting Timmy's pets.
Abstraction is also achieved through Composition. For example, a class Car would be made up of an Engine, Gearbox, Steering objects, and many more components. To build the Car class, one does not need to know how the different components work internally, but only how to interface with them, i.e., send messages to them, receive messages from them, and perhaps make the different objects composing the class interact with each other.
Encapsulation
Encapsulation conceals the functional details of a class from objects that send messages to it.
For example, the Dog class has a bark() method. The code for the bark() method defines exactly how a bark happens (e.g., by inhale() and then exhale(), at a particular pitch and volume). Timmy, Lassie's friend, however, does not need to know exactly how she barks. Encapsulation is achieved by specifying which classes may use the members of an object. The result is that each object exposes to any class a certain interface - those members accessible to that class. The reason for encapsulation is to prevent clients of an interface from depending on those parts of the implementation that are likely to change in future, thereby allowing those changes to be made more easily, that is, without changes to clients. For example, an interface can ensure that puppies can only be added to an object of the class Dog by code in that class. Members are often specified as public, protected or private, determining whether they are available to all classes, sub-classes or only the defining class. Some languages go further: Java uses the default access modifier to restrict access also to classes in the same package, C# and VB.NET reserve some members to classes in the same assembly using keywords internal (C#) or Friend (VB.NET), and Eiffel and C++ allow one to specify which classes may access any member.
Polymorphism
Polymorphism allows the programmer to treat derived class members just like their parent class' members. More precisely, Polymorphism in object-oriented programming is the ability of objects belonging to different data types to respond to method calls of methods of the same name, each one according to an appropriate type-specific behavior. One method, or an operator such as +, -, or *, can be abstractly applied in many different situations. If a Dog is commanded to speak(), this may elicit a bark(). However, if a Pig is commanded to speak(), this may elicit an oink(). They both inherit speak() from Animal, but their derived class methods override the methods of the parent class; this is Overriding Polymorphism. Overloading Polymorphism is the use of one method signature, or one operator such as "+", to perform several different functions depending on the implementation. The "+" operator, for example, may be used to perform integer addition, float addition, list concatenation, or string concatenation. Any two subclasses of Number, such as Integer and Double, are expected to add together properly in an OOP language. The language must therefore overload the addition operator, "+", to work this way. This helps improve code readability. How this is implemented varies from language to language, but most OOP languages support at least some level of overloading polymorphism. Many OOP languages also support Parametric Polymorphism, where code is written without mention of any specific type and thus can be used transparently with any number of new types. Pointers are an example of a simple polymorphic routine that can be used with many different types of objects.
Decoupling
Decoupling allows for the separation of object interactions from classes and inheritance into distinct layers of abstraction. A common use of decoupling is to polymorphically decouple the encapsulation, which is the practice of using reusable code to prevent discrete code modules from interacting with each other. However, in practice decoupling often involves trade-offs with regard to which patterns of change to favor. The science of measuring these trade-offs in respect to actual change in an objective way is still in its infancy.
Note: Not all of the above concepts are to be found in all object-oriented programming languages, and so object-oriented programming that uses classes is called sometimes class-based programming. In particular, prototype-based programming does not typically use classes. As a result, a significantly different yet analogous terminology is used to define the concepts of object and instance.
How do you install Turbo C plus plus on Windows XP?
Borland Turbo C++ is a 16-bit DOS implementation of C++. As such it cannot be run natively on 32-bit architecture, including Windows XP. Emulation programs such as Dosbox can be used to emulate a virtual 16-bit environment, however you will need to install a slightly modified version of Turbo C++ that is capable of running within this environment.
What is a header node in c plus plus?
A header node, or head node, is a node that marks the start of a series of nodes, usually as part of a list or queue structure. The head node is often a sentinal that holds no data of its own. Sentinels are used to simplify algorithms by ensuring that a list can never be empty, even when it has no data.
What is issue in throwing an exception in a destructor?
If a destructor throws an exception, the instance is left in an invalid state. When an exception is thrown, the destructor automatically terminates at the point of the throw, unwinding the call stack until an exception handler is found (if one is provided). However, any resources yet to be released by the destructor, including all the instance's base classes, cannot be destroyed.
When writing your own destructors, it is important to never throw an exception. If an exception could be thrown from within your destructor, you must catch it and handle it within the same destructor -- you must not rethrow the exception.
There isn't one; C is strictly non object oriented. Although C++ is often considered to be an object-oriented extension for C (it was originally called C with Classes), it would be more accurate to describe them as siblings. The two have evolved separately and while they still retain a high-level of compatibility through their common ancestry, they are not the same language.
What is the difference between compilers and interpreters in c plus plus in tabular form?
C-compiler translates the C-source into Assembly or machine code.
On the other hand, C-interpreter -- well, there is no such thing as C-interpreter.
What is difference between define and typedef in c plus plus?
defines are handled by a preprocessor (a program run before the actual c compiler) which works like replace all in you editor. Typedef is handled by the c compiler itself, and is an actual definition of a new type. The distinction given between #define and typedef has one significant error: typedef does not in fact create a new type. According to Kernighan & Richie, the authors of the authoritative and universally acclaimed book, "The C Programming Language": It must be emphasized that a typedef declaration does not create a new type in any sense; it merely adds a new name for some existing type. Nor are there any new semantics: variables declared this way have exactly the same properties as variables whose declarations are spelled out explicitly. In effect, typedef is like #define, except that since it is interpreted by the compiler, it can cope with textual substitutions that are beyond the capabilities of the preprocessor. There are some more subtleties though. The type defined with a typedef is exactly like its counterpart as far as its type declaring power is concerned BUT it cannot be modified like its counterpart. For example, let's say you define a synonim for the int type with: typedef int MYINT Now you can declare an int variable either with int a; or MYINT a; But you cannot declare an unsigned int (using the unsigned modifier) with unsigned MYINT a; although unsigned int a; would be perfectly acceptable. typedefs can correctly encode pointer types.where as #DEFINES are just replacements done by the preprocessor. For example, # typedef char *String_t; # #define String_d char * # String_t s1, s2; String_d s3, s4; s1, s2, and s3 are all declared as char *, but s4 is declared as a char, which is probably not the intention. typedef also allows to delcare arrays, # typedef char char_arr[]; # char_arr my_arr = "Hello World!\n"; This is equal to
# char my_arr[] = "Hello World!\n"; This may lead to obfuscated code when used too much, but when used correctly it is extremely useful to make code more compat and easier to read.
How can you calculate the c program running time through c plus plus coding?
This is a big question... but I'll try for a shortish answer. Try to do things in approximately the following order.
1) Use the right algorithms. Look into the Big O efficiency of any algorithms you are using, and make sure there aren't more efficient algorithms available.
2) Think about trading using more memory for a faster algorithm. Perhaps pre-computing tables of intermediate results.
3) Use a profiler to see where the bottle necks are and try improving them.
4) Optimize the inner most loops using assembly language to get the last little bit faster.
5) Run it on a faster computer.
6) Make it run in parallel across many computers or CPUs. This is especially good on the newer Intel chips where you have access to multiple CPUs on one chip. Distributed network computing sometimes is a good idea. Cloud computing is another possibility these days.
7) Make sure that C really is the right answer. It might not be in all cases.
A more specific question might yield a more specific answer.
When do you make class virtual?
Whenever a derived class requires direct inheritance from a base class, even if it inherits that base class indirectly. That is, if V is a base class from which B is derived, and D is derived from B, then D inherits from V indirectly (through B). But if B is virtually derived from V, then D will inherit directly from V.
This feature is commonly used in conjunction with multiple inheritance. Examine the following declarations:
class V{};
class B1: public V{};
class B2: public V{};
class M: public B1, public B2{};
Now suppose you have the following code:
M m; // Declare an instance of M.
V& v = m; // Ambiguous...
The problem with this is that M inherits V from both B1 and B2, and therefore inherits two separate instances of V. The compiler is unable to determine which instance of V you want to refer to. One solution to this would be to use static casts to indirectly refer to an explicit instance of V:
V& v = static_cast<B1&>(m);
or
V& v = static_cast<B2&>(m);
While this is certainly workable, it is an ugly approach that places far too much responsibility upon the programmer to ensure the correct instance of V is being referred to. However, unless there is a specific need to have two instances of V within M, the problem can be resolved with virtual inheritance.
By virtually deriving both B1 and B2 from V, M will directly inherit just one instance of V, which is then shared, virtually, between B1 and B2:
class V{};
class B1: public virtual V{};
class B2: public virtual V{};
class M: public B1, public B2{};
M m;
V& v = m; // No ambiguity.
Now M can access all the members of V directly, as can B1 and B2, because they now share the same instance of V.
Note that it doesn't matter whether the virtual keyword is placed before or after the access specifier (which is public in this case). "virtual public" and "public virtual" have the same meaning.
Write a program using c plus plus to whether the given square matrix is symmetric or not?
int sym_test (const int **a, int n) {
int i, j, sym;
i=1, j=0, sym=1;
while (sym && i
else if (j
}
return sym;
}
What is single inheritance in c plus plus?
Multiple inheritance occurs when a class is derived directly from two or more base classes.
class b1 {};
class b2 {};
class d: public b1, public b2 {}; // multiple inheritance class
Write a c plus plus programs for stack using arrays?
//Program on Stack ADT Using Arrays
#include<iostream.h>
#include<conio.h>
#define maxSize 10
#include<stdlib.h>
class stack
{
public:
stack(); // constructor call the display function
void pop(); //used to pop the value as per user demand
void push(); //used for push the value as per user demand
int empty(); //used to check the stack
int full(); //used to check the stack whether it is full as max limit is 80
void display(); //used to display menu for operations
void stackDisplay(); //used to display whole stack items
void operation(); //used to enter the user choice
private:
int top;
int item[maxSize];
};
stack::stack()
{
top = 0;
display();
}
void stack :: display()
{
cout << "STACK MAIN MENU GIVEN BELOW" << endl;
cout << "PRESS 1 FOR PUSH THE ITEM ON STACK" << endl;
cout << "PRESS 2 FOR POP THE ITEM ON STACK" << endl;
cout << "PRESS 3 FOR DISPLAY THE WHOLE STACK" << endl;
cout << "PRESS 4 FOR EXIT THE PROGRAM" << endl;
cout<<"ENTER YOUR CHOICE" << endl;
operation();
}
void stack :: operation()
{
int choice;
cin >> choice;
switch(choice)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
stackDisplay();
break;
case 4:
exit(4);
default:
cout << "PLZ ENTER VALID NUMBER" <<endl;
operation();
}
}
int stack::empty()
{
if( top 0)
{
cout<<"THE STACK IS EMPTY UNDERFLOW" << endl;
cin.get();
}
else
{
char ch;
cout<<"AS THE LAST ELEMENT IN STACK IS "<<item[top] << endl;
top = top-1;
cout<<"WANT TO POP OUT ANOTHER ELEMENT y/n" << endl;
cin>>ch;
if(ch=='y')
pop();
cin.get();
}
cout<<"PRESS ENTER TO GO TO MAIN MENU " << endl;
cin.get();
clrscr();
display();
}
void stack::stackDisplay()
{
cout<<"THE ELEMENTS IN STACK IS"<<endl;
for(int i = 1;i <= top; i++)
{
cout << item[i] << endl;
}
cin.get();
cout<<"PRESS ENTER FOR MAIN MENU " << endl;
cin.get();
clrscr();
display();
}
void main()
{
clrscr();
gotoxy(15,10);
cout<<"WELCOME TO THE PROGRAM OF STACK MADE BY SAURABH " << endl;
gotoxy(15,11);
cout<<"________________________________________________" << endl;
cin.get();
clrscr();
stack obj;
getch();
}
BY. SAURABH (GNDU RC JAL CSE 2nd YEAR)