What is C plus plus mainly used for?
C++ is a general purpose programming language. It has imperative, object-oriented and generic programming features, while also providing the facilities for low level memory manipulation. Source: Wikipedia.
How do you make a input and output basic statement in C plus plus?
The most basic input/output operations can be performed with std::cin for input and std::cout for output. For example:
#include<iostream>
int main (void) {
int n;
std::cout << "Enter a number: ";
std::cin >> n;
std::cout << "The value " << n << " was entered!\n";
}
How do you Calculate the average of two numbers then return the average in c plus plus?
Use the following function:
/* returns the average of two real numbers */
double average (const double a, const double b) {
return a/2.0 + b/2.0;
}
Note that we do not use (a+b) / 2.0 because the expression a+b could overflow the range of a double. By dividing each value by 2 before summing we ensure the result can never overflow no matter how large a and b are.
Ideally, you should write separate functions to cater for float and long double arguments independently:
/* returns the average of two long doubles */
long double average_lng (const long double a, const long double b) { return a/2.0 + b/2.0;
}
/* returns the average of two floats */
float average_flt (const float a, const float b) {
return a/2.0F + b/2.0F;
}
For mixed-mode arithmetic, always use the highest precision argument. E.g., the average of a float and a double is a double, so use the function that returns a double, not a float. The float argument will be implicitly cast to a double.
What Kind of reaction is symbolized by ab plus c CB plus a?
I suppose that you think to synthesis reaction.
When operator function is declared as friend function?
Ideally, never. Friend functions should only be employed when a function (whether an operator overload or not) requires private access to a class, and it is not otherwise possible to provide a public interface without unduly undermining the class encapsulation. However, as programmer, it is your responsibility to ensure all friend functions adhere to the same class rules (which you yourself define) as do the members of your class, even though friends are not regarded as being members of the class. Ultimately, if you have no control over the friend function implementation, then you must not allow that function to be a friend of your class, as this will seriously undermine the encapsulation.
Difference between C and C plus plus languages?
C was the C++ predecessor. As it's name implies, alot of C remains in C++. Although not actually being more powerful than C, C++ allows the programmer to more easily manage and operate with Objects, using an OOP (Object Oriented Programming) concept.
C++ allows the programmer to create classes, which are somewhat similar to C structures. However, to a class can be assigned methods, functions associated to it, of various prototypes, which can access and operate within the class, somewhat like C functions often operate on a supplied handler pointer.
Although it is possible to implement anything which C++ could implement in C, C++ aids to standarize a way in which objects are created and managed, whereas the C programmer who implements the same system has alot of liberty on how to actually implement the internals, and style among programmers will vary alot on the design choices made.
In C, some will prefer the handler-type, where a main function initializes a handler, and that handler can be supplied to other functions of the library as an object to operate on/through. Others will even want to have that handler link all the related function pointers within it which then must be called using a convention closer to C++.
To finish this discussion, C++ applications are generally slower at runtime, and are much slower to compile than C programs. The low-level infrastructure for C++ binary execution is also larger. For these reasons C is always commonly used even if C++ has alot of popularity, and will probably continue to be used in projects where size and speed are primary concerns, and portable code still required (assembly would be unsuitable then).
What is null pointer assignment?
This error message means that somewhere in your program you have used a pointer-varible containing NULL-value. (Within an actual OS it with stop the program immediately, but in MS-DOS it doesn't.)
What is diff between method and class?
method is a process
property is about it.
please check the answer from others also. because its only my guess.
SORRY
THANK YOU
What are escape sequences in c language?
Escape sequences are combination of characters which when used together form one single unit with a special meaning.Eg:
when a blackslash('\') and 'n' are written together like '\n', this represents a newline character.
For more escape sequences visit the related link.
What is meant by the data type of a variable in c plus plus?
The built-in (fundamental) data types are int, char, bool, float, double and pointer. All other integral types are either modified types or aliases (typedefs). User-defined types (including those provided by the standard library) are not considered part of the language.
What is meant by a function returning a value in c?
Consider this example:
#include
int add(int x, int y)
{ int n=x+y;
return n; }
int main()
{ Using namespace std;
cin >> x;
cin >> y;
cout << add(x,y);
return 0; }
What happens is the main() function asks the user for 2 integers then sends them to add() in the cout statement. Add() adds the two integers and returns the sum to the function that called it (main()) so technically 'add(x,y)' in the cout statement is replaced with add()'s return value. So if the user said x=1 and y=2, the program would print 3. NOTE:
For example, return 0 in main(). Anything else is an error code that is RETURNED TO THE OS or SHELL.
In the of Unix/Linux, we can see the returned value of main using
echo $?
In the case of Windows, we can see the returned value of main using
echo %ERROR_LEVEL%
while we are in DOS or Command prompt
Write program to implement stack with POP and PUSH operations?
SOURCE CODE:
#include
#include
void push(int st[],int data,int &top);
void disp(int st[],int &top);
int pop(int st[],int &top);
int flg=0;
int top=-1,tos=-1;
int st[50];
void push(int st[],int data,int &top)
{
if(top==50-1)
flg=0;
else
{
flg=1;
top++;
st[top]=data;
}
}
int pop(int st[],int &top)
{
int pe;
if(top==-1)
{
pe=0;
flg=0;
}
else
{
flg=1;
pe=st[top];
top--;
}
return(pe);
}
void disp(int st[],int &top)
{
int i;
if(top==-1)
{
printf("\nStack is Empty");
}
else
{
for(i=top;i>=0;i--)
printf("\t%d",st[i]);
}
}
void main()
{
int dt,opt;
int q=0;
clrscr();
printf("This Program Is Used to Perform PUSH & POP operations On Stack");
printf("\n\n\tMain Menu.........");
printf("\n\n1.Push");
printf("\n\n2.Pop");
printf("\n\n3.Exit");
do
{
printf("\n\n\tEnter Your Choice 1-3:");
scanf("%d",&opt);
switch(opt)
{
case 1:
printf("\nEnter the Element to be Push:");
scanf("%d",&dt);
push(st,dt,tos);
if(flg==1)
{
printf("\nAfter Inserting the Element, Stack is:\n\n");
disp(st,tos);
if(tos==50-1)
printf("\nStack is Now Full");
}
else
printf("\nStack Overflow Insertion Not Possible");
break;
case 2:
dt=pop(st,tos);
if(flg==1)
{
printf("\n\tData Deleted From the Stack is:%d\n",dt);
printf("\n\tAfter Deleting the Element from the stack is:\n\n");
disp(st,tos);
}
else
printf("\nStack Empty,Deletio Not Possible:");
break;
case 3:
q=1;
break;
default:printf("\nWrong Choice Enter 1-3 Only");
}
}while(q!=1);
}
OUTPUT
Main Menu.........
1.push
2.pop
3.exit
Enter your choice 1-3:1
Enter the element to be push:4
After inserting the elements,stack is:
4
Enter your choice 1-3:1
Enter the element to be push:7
After inserting the elements,stack is:
7 4
Enter your choice 1-3:1
Enter the element to be push:4
Program for row wise sort for a square matrix in C?
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],i,j,k,m,n;
printf("enter the order");
scanf("%d",&m,&n);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
for(k=0;k<m;k++)
{
for(i=0;i<=m-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if(a[k][j]>a[k][j+1])
temp=a[k][j];
a[k][j]=a[k][j+1];
a[k][j+1]=temp;
}
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("sorted matrix=%d",a[i][j]);
}
}
getch();
}
Source code for prim's algorithm in C plus plus programming?
#include<stdio.h>
#include<conio.h>
int a,b,u,v,n,i,j,ne=1;
int visited[10]={0},min,mincost=0,cost[10][10];
void main()
{
clrscr();
printf("\n Enter the number of nodes:");
scanf("%d",&n);
printf("\n Enter the adjacency matrix:\n");
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
scanf("%d",&cost[i][j]);
if(cost[i][j]==0)
cost[i][j]=999;
}
visited[1]=1;
printf("\n");
while(ne<n)
{
for(i=1,min=999;i<=n;i++)
for(j=1;j<=n;j++)
if(cost[i][j]<min)
if(visited[i]!=0)
{
min=cost[i][j];
a=u=i;
b=v=j;
}
if(visited[u]==0 visited[v]==0)
{
printf("\n Edge %d:(%d %d) cost:%d",ne++,a,b,min);
mincost+=min;
visited[b]=1;
}
cost[a][b]=cost[b][a]=999;
}
printf("\n Minimun cost=%d",mincost);
getch();
}
Why you use C when C plus plus is there?
C is a much simpler language than C++, with fewer keywords. The resultant machine code maps very closely to the source code, thus C is more low level than C++, but is sufficiently abstract that even assembler language programmers can develop highly efficient code much more easily than they can with assembler alone. C++ evolved from C, but has a far greater degree of abstraction and its object-oriented programming support is ideally suited to solving highly complex problems with more complex data structures more easily but every bit as efficiently as with C. However, since C is much older, there is still a wealth of useful and highly efficient C code that can still be used by C++ programmers to this day, thus it is still worthwhile learning C even if you already know C++, as the transition to C is much easier than the transition from C to C++, unless you are familiar with object-oriented principals.
What are the manipulator in c plus plus?
What is a manipulator?
C++ manipulators are functions or operators that are used specifically with input and output streams in order to manipulate those streams or to insert or extract special characters. Many manipulators apply to both input and output streams but some are specific to one or the other.
The following list briefly describes all the manipulators available in C++, including those only available in C++11. Most manipulators can be found in the
Output stream manipulators
std::flush - synchronises the output buffer with the controlled output sequence
std::endl - inserts a newline character (\n) and flushes the output stream
std::ends - inserts a null character (\0) without flushing the output stream
Input stream manipulators
std::ws - extracts and discards whitespace characters from the input stream
Numerical base format manipulators ("basefield" flags)
std::dec - inserts/extracts integral numeric data with decimal notation
std::hex - inserts/extracts integral numeric data with hexadecimal notation
std::oct - inserts/extracts integral numeric data with octal notation
Floating-point format manipulators ("floatfield" flags)
std::fixed - inserts/extracts floating point values with fixed notation
std::scientific - inserts/extracts floating point values with scientific notation
std::hexfloat - inserts/extracts floating point values with hecadecimal notation (C++11 only)
std::defaultfloat - default behaviour (C++11 only)
Adjustment manipulators ("adjustfield" flags)
std::internal - output is padded to the field width by inserting fill characters at a specified internal point
std::left - output is padded to the filed width by appending fill characters
std::right - output is padded to the field width by prepending fill characters
Flags (on)
std::boolalpha - generates text values "true" and "false" for boolean values
std::showbase - generates the base for basefield values
std::showpoint - generates a decimal point for "floatfield" values
std::showpos - generates positive sign to positive values
std::skipws - ignores whitespace characters
std::unitbuf - flushes the buffer after every insertion
std::uppercase - generates upper-case letters for generated letters
Flags (off)
std::noboolalpha - does not generate text values for boolean values
std::noshowbase - does not generate the base for basefield values
std::noshowpoint - does not generate decimal point for "floatfield" values unless the decimal portion is non-zero
std::noshowpos - does not generate positive sign for positive values
std::noskipws - does not ignore whitespace characters
std::nounitbuf - does not flush the buffer afer every insertion
std::nouppercase - does not generate upper-case letters for generated letters
Parameterised manipulators
std::setiosflags - set format flags
std::resetiosflags - reset format flags
std::setbase - set basefield flag
std::setfill - set fill character
std::setprecision - set floatfield precision
std::setw - set field width
Many of these manipulators work together. For instance, the std::internal, std::left and std::rightmanipulators all work in conjunction with the std::setwand std::setfill manipulators.
All manipulators are implemented as operators which can be chained together using the insertion (<<) or extraction (>>) operators as appropriate to the stream. Excluding the parameterised manipulators, most manipulators are also implemented as functions (passing the streram as an argument). Others, including all parameterised manipulators, are implemented as members of the stream. Some, such as std::flush, are implemented all three ways; as an operator, a function and a member function.
Some examples of manipulator usage:
// set field width to 8 characters for console output
std::cout << std::setw (8); // operator
std::cout.width (8); // member method
// set precision to 16 places for floatfields
std::cout << std::setprecision (16); // operator
std::cout.precision (16); // member method
// insert newline and flush stream
std::cout << std::endl; // operator
std::endl (std::cout); // function
// flush stream
std::cout << std::flush; // operator
std::flush (std::cout); // function
std::cout.flush (); // member method
// generate hexadecimal values with base prefix
std::cout << std::showbase << std::hex; // operator
std::showbase (std::cout); // function
std::hex (std::cout); // function
More information on manipulators can be found in the sources and related links section, below.
A Bell Labs researcher named Dennis Ritchie (who was one of the driving forces behind Unix) created the C programming language.
What are c plus plus statements?
Statements are how we tell the compiler what we want our program to do. In other words, they are the instructions written in C++ code. A statement may be a simple instruction to invoke a function call, such as:
foo();
Or to perform an operation, such as adding two integers:
x+=y;
Note that all statements end with a semi-colon.
We can also group individual statements together to form a compound statement. For instance, when we use an if statement to evaluate a condition, we might want more than one statement to execute if the condition were true. We use curly braces to create a compound statement:
if (x==42)
{
for(int i=0; i<100; ++i)
std::cout<<i<<std::endl;
foo();
}
In the above example, if x were 42, then we'd print the number 0 to 99 and then call foo(). If x were not 42, then we'd skip over the entire compound statement and execute the next statement instead.
Compound statements may also be nested. In the above example, for instance, the for loop might contain a compound statement:
if (x==42)
{
for(int i=0; i<100; ++i)
{
std::cout<<i<<std::endl;
foo(i);
}
}
In this case, we print the value 0 and then call foo(0) on the first iteration of the loop, then print 1 and call foo(1), and so on. But since the for loop constitutes the entire compound of the if statement, we can eliminate the outer set of braces completely:
if (x==42)
for(int i=0; i<100; ++i)
{
std::cout<<i<<std::endl;
foo(i);
}
We can also create compound statements using commas to separate the individual statements. For instance, when we delete a pointer we will typically nullify the pointer straight away. Like so:
if (p)
delete (p), p=NULL;
The above is simply a shorthand for the following compound statement:
if(p)
{
delete(p);
p=NULL;
}
Program to count number of leaf node in binary tree in c plus plus?
Add the following recursive method to your binary tree's node class:
size_t Node::count_leaves()
{
if (!left && !right) return 1; // this node is a leaf
size_t count = 0;
if (left) count += left-count_leaves(); // count leaves on left
if (right) count += right-leaves(); // count leaves on right;
return count; // return total leaves.
}
To count the leaves of the entire tree, call the method on the root node of the tree. To count the leaves of a subtree, call the method on the root node of the subtree.
What is the purpose of getch()?
getch() is a way to get a user-inputted character. It can be used to hold program execution, but the "holding" is simply a side-effect of its primary purpose, which is to wait until the user enters a character. getch() and getchar() are used to read a character from screen.
What is called pointers-c plus plus?
Yes, C++ has pointers, which are references to memory locations. which are variables that store memory addresses, or NULL (zero). If the pointer is non-NULL, the pointer is said to dereference the object (or variable) residing at the stored memory address, which permits indirect access to that object so long as the object remains in scope.
Characteristics of constructor?
Contains an access modifier followed by the name of the class and some parameters. More specifically:
public class MyClass {
//Constructor
public MyClass() {
}
}
Yes you can use the same function name for a member function and an external function. They are primarily distinguished by the number and type of arguments they accept (the function signature). If they match exactly, then the scope resolution operator (::) is used to differentiate them by namespace. The class namespace is the class name itself. The external function uses global scope unless scoped to another namespace. When the scope is not explicitly stated, then the scope is implied by the call site.
Note that whenever there is any ambiguity about which function is implied, the compiler will emit an error indicating where the ambiguity lies, and the program will ultimately fail to compile.
What key word is use as identifire in c programming?
A keyword identifier is one whose meaning has already been declared to the C compiler and we can't use it as variable,because if we want to do so we are trying to establish a new meaning to the keywords which is not permitted.
Who is the founder of C programming language?
C was developed by Dennis Ritchie at AT &T's Bell Laboratories of USA in 1972.