Is the double a modifier in c plus plus?
A double is a floating point type, greater than or equal in size to a float.
Write a program in c language to accept 10 strings as input and printthem in lexicographic order?
#include <stdio.h>
#include <string.h>
void main()
{
char a[4][25],temp[25];
int i,j;
clrscr();
printf("Enter the names\n");
for (i=0;i<4;i++)
gets(a[i]);
for (i=0;i<3;i++)
for (j=i+1;j<4;j++)
{
if (strcmp(a[i],a[j])>0)
{
strcpy(temp,a[i]);
strcpy(a[i],a[j]);
strcpy(a[j],temp);
}
}
printf("Sorted strings are \n");
for (i=0;i<4;i++)
puts (a[i]);
getch();
}
How do you calculate cgpa using c plus plus program?
#include <stdio.h>
void main()
{
int num,num1,num2, cal;
num=cal=0;
char grade1=cal=0,grade2=cal=0;
printf("\n Enter the number of subjects taken in Spring Semester:");
scanf("%d", &num);
fflush(stdin);//
if(grade1==4){
printf("\n\nEnter the Math Grade(A,B,C): %c",grade1);
do{
printf("\ngrade1=");
scanf("%d",&cal);
}
else if(
printf("\nError!\n\n");
}while(1);
printf("\nEnter the Math Credit hours(1~3):");
num1 = getchar();
grade1=4;
}
else if(grade2==3){
grade2=3;
}
printf("\nEnter the Math Grade(A,B,C):\n");
scanf("%c",&grade1);
printf("Enter the Physics Grade(A,B,C):");
grade2 = getchar();
printf("\nEnter the Physics Credit hours(1~3):");
num2 = getchar();
printf("\nMath Credit hours: %d",num1);
printf("\nPhysics Grade: %c",grade2);
printf("\nPhysics Credit hours:%d\n",num2);
printf("\n <Math Credit hours> \n");
do{
printf("\n 1 + 1 = ");
scanf("%d", &cal);
}while(cal != 3);
printf("\n Error!\n\n");
}
printf("\n <Physics Credit hours> \n");
do{
printf("\n 4 - 1 = ");
scanf("%d", &cal);
}while(cal != 3);
printf("\n Error!\n");
}
printf("\n The End.\n");
system("pause");
}
How do you write a C program to Print 1st 30 Perfect numbers starting from 0?
int i;
for (i=2; i<=30; i+=2) printf ("%d\n", i);
A priority queue is a collection of elements that each element has been assigned a priority and such that order in which elements are deleted and processed comes from the following riles: 1) An element of higher priority is processed before any element of lower priority. 2) Two element with the same priority are processed according to the order in which they were added to the queue.
What do you mean by garbage collection in data structure?
all classes and variables created in a program are put on something called the Heap, which is stored in main memory (RAM).
The Garbage collector gets rid of any class or variable that becomes impossible to reference ever again in the program.
For example, say you have a main method and from there you call another method, any local variables created in that other method will be put on the heap while they are in use, ie that function is running. As soon as the method ends, the Garbage collector will come and "release" the memory where those variables were for use in other parts, because you can never access them again when the method finishes.
Write program in c to show the pattern 1 23 456?
hi.... char *arr = argv[1];
if (arr!=NULL)
{
int len = strlen(argv[1]);
len--;
arr = argv[1];
while(len>=0)
printf("%c",arr[len--]);
}
How are string stored in c language?
Strings represented by the language character set (e.g., ASCII) are stored as null-terminated arrays of type char. Wide-character strings are stored as null-terminated arrays of type wchar_t. Other types are also available, such as char16 and char32 (for UTF16 and UTF32 encodings, respectively).
How do you download c programming software?
Visual C++ Express http://www.microsoft.com/exPress/ is the best place to get a full C++ IDE (Integrated Development Environment). There are many other IDEs around, but I find this is the best one.
Other IDEs:
Eclipse http://www.eclipse.org/cdt/
Code::Blocks http://www.codeblocks.org/
Bloodshed Dev-C++ http://www.bloodshed.net/devcpp.html
Write a c program to print 1 232 34543 5678765 using for loop?
If you visualize 1123581321 as a set of numbers (without spaces in between) instead of one number, you'll see that it's a set of the first 8 Fibnocci nos. - 1 1 2 3 5 8 13 21.
The following program would print the required no. using a For looping structure.
int main (void)
{
int i=1;
int j=1;
int k, num=1;
for(k=0; k<7; k++){
if(k==0){
printf("%d", num);
}
printf("%d", num);
//next no. is the sum of previous two nos. in the series
i=j;
j=num;
num=i+j;
// 1 + 1 = 2 ... 1 + 2 = 3 ... 2 + 3 = 5 ... 3 + 5 = 8
// sum=i + j ... i takes value of j ... j takes value of sum ... repeat.
}
}
What is the storage allocation and scope of global extern static local and register variables?
Nooo Nooo
Static variable will be stored in .BSS segment... (Block Started By Symbol)
Where string arrays belong in a C program?
There is no data type string in C. String is handled as an array of characters. To identify the end of the string, a null character is put. This is called a null terminated character array. So array of strings will be a double dimensioned array of chars. It is implemented as an array of pointers, each pointer pointing to an array of chars.
Maximum static memory size in c plus plus?
The maximum size of an array in C++ is the same as the maximum number that can be represented by an int (usually 2,147,483,647 elements, or just over 2 billion). An int is defined as being dependent on a CPU's architecture, so the 2 billion number is based on 32-bit compilation. Some 64-bit processors also compile to a 32-bit int, and would be limited to just over 2 billion elements.
Available memory is also a consideration on the maximum size of an array. The larger the elements, the fewer elements you can achieve. This is unlikely to be a problem on 64-bit systems, but on 32-bit systems it could be.
What does BASIC as in the programming language stand for?
Beginners All-purpose Symbolic Instruction Code > B.A.S.I.C. > Basic.
John Kemeny and Thomas Kurtz developed the first version at Dartmouth University in 1964. It was originally created to allow non technical people to run a computer because, at that time, you couldn't operate a computer without programming it first. Basic was developed to give a more simple programming structure that was close to plain English so that anyone could use a computer. It has come a very long way since then becoming a very robust language.
What are the arithmetic and logical operator?
AND, OR, and NOT are the most common ones. There are others, too, such as XOR.
AND, OR, and NOT are the most common ones. There are others, too, such as XOR.
AND, OR, and NOT are the most common ones. There are others, too, such as XOR.
AND, OR, and NOT are the most common ones. There are others, too, such as XOR.
Writea c program to print the day for an input of date month and year?
#include<iostream>
#include<string>
#include<ctime>
using namespace std;
std::tm input_date()
{
while (true)
{
cout << "Enter date (dd/mm/yyyy): ";
string input;
getline (cin, input);
size_t d, m, y;
int n = sscanf (input.c_str(), "%u/%u/%u", &d, &m, &y);
if (n!=3)
cout << input << " is not a valid date." << endl;
else
{
tm date;
memset (&date, 0, sizeof(tm));
date.tm_isdst = -1;
date.tm_mday = d;
date.tm_mon = m-1;
date.tm_year = y-1900;
return date;
}
}
}
int main()
{
tm date = input_date();
time_t tt = mktime (&date);
date = *localtime(&tt);
switch (date.tm_wday)
{
case (0): std::cout << "Sunday"; break;
case (1): std::cout << "Monday"; break;
case (2): std::cout << "Tuesday"; break;
case (3): std::cout << "Wednesday"; break;
case (4): std::cout << "Thursday"; break;
case (5): std::cout << "Friday"; break;
case (6): std::cout << "Saturday"; break;
}
std::cout << std::endl;
}
Write a c program to arrange the digits of a number in ascending order?
#include
#include
void main()
{
int n ,i,j,temp,a[12]; //in a[] specify some number .
printf("Enter the no of inputs:");
scanf("%d", &n);
printf("Enter %d integer numbers :", n);
for(i=0;i { scanf("%d",&a[i]); } for (i=0;i for(j=i+1;j { if(a[i]>a[j]) { temp=a[j]; a[j]=a[i]; a[i]=temp; } } printf("THE %d NUMBERS SORTED IN ASCENDING ORDER ARE :\n", n); for(i=0;i { printf("%d ",a[i]); } getch(); } Here is another version of the program. While the previous one is obviously simpler, this one is a good program to master the basics of pointer and array problems which might plague them at the beginning. #include #include int a[100],i,j,k,n; void sort(int *a,int n); void swap(int *x,int *y); main() { printf("How many numbers? "); scanf("%d",&n); printf("Enter the %d numbers separated from each other by a blank space: \n\n",n); for (i=0;i scanf("%d",&a[i]); sort(a,n); printf("\nThe numbers in descending order is: \n"); for (k=0;k printf("\n%d",a[k]); printf("\n\n"); } void sort(int *a,int n) { int p=n-1; while (p>=0) { for(i=0;i<=(p-1);++i) { if (a[i]<=a[i+1]) swap(&a[i],&a[i+1]); else continue; } --p; } } void swap(int *x,int *y) { int t; t=*x; *x=*y; *y=t; }
How do you convert binary numbers to hexadecimal notation?
Each hexadecimal digit represent four binary bits. Using the table... 0 = 0000 1 = 0001 2 = 0010 3 = 0011 4 = 0100 5 = 0101 6 = 0110 7 = 0111 8 = 1000 9 = 1001 A = 1010 B = 1011 C = 1100 D = 1101 E = 1110 F = 1110 ... replace each hexadecimal digit with its correspnding binary digits. As an example, 37AB16 is 00110111101010112.
List and explain bitwise operators in C language?
void main()
{
unsigned int word1 = 077u, word2 = 0150u, word3 = 0210u;
printf ("%o ", word1 & word2);
printf ("%o ", word1 & word1);
printf ("%o ", word1 & word2 & word3);
printf ("%o\n", word1 & 1);
getch();
}
What are proxy classes in c plus plus?
A proxy is defined as any entity that acts on behalf of another entity. For instance, a proxy server is a server that you use to make network calls on your behalf. The proxy server effectively hides your identity from the network because the network only sees the proxy server.
A proxy class is a similar concept -- it is simply a class that acts on behalf of another class. Proxy classes are typically used to simplify the interface to a larger, more complex object.
Note that this is not the same as deriving one object from another. Although you can achieve the same sort of thing with derivation, a proxy class contains a member pointer to the class it acts upon, it does not derive from it. Thus it is free to override the class behaviour, but does not inherit any of its underlying complexity.
"Wrapper" classes are a form of proxy. They contain a class member pointer but they expose a limited or simplified interface to that class member, making more complex calls to that class on your behalf.
Proxy classes can also be used as a reference counting mechanism. Rather than having multiple copies of the same complex object, you can have several lightweight proxy classes all pointing to a single instance of an object, each of which acts on its behalf. Copying lightweight objects does not copy the original object, thus reducing the memory footprint of that object, and when all the lightweight classes finally fall from scope, the original object also falls from scope.
memcpy()
C program to create symbol table?
Aim:
To write a C program to implement Symbol Table system software lab CS1207
Algorithm:
Start the program for performing insert, display, delete, search and modify option in symbol table
Define the structure of the Symbol Table
Enter the choice for performing the operations in the symbol Table
If the entered choice is 1, search the symbol table for the symbol to be inserted. If the symbol is already present, it displays "Duplicate Symbol". Else, insert the symbol and the corresponding address in the symbol table.
If the entered choice is 2, the symbols present in the symbol table are displayed.
If the entered choice is 3, the symbol to be deleted is searched in the symbol table. If it is not found in the symbol table it displays "Label Not found". Else, the symbol is deleted.
If the entered choice is 5, the symbol to be modified is searched in the symbol table. The label or address or both can be modified.
Source Code program in c implement symbol table
# include
# include
# include
# include
# define null 0
int size=0;
void insert();
void del();
int search(char lab[]);
void modify();
void display();
struct symbtab
{
char label[10];
int addr;
struct symtab *next;
};
struct symbtab *first,*last;
void main()
{
int op;
int y;
char la[10];
clrscr();
do
{
printf("\nSYMBOL TABLE IMPLEMENTATION\n");
printf("1. INSERT\n");
printf("2. DISPLAY\n");
printf("3. DELETE\n");
printf("4. SEARCH\n");
printf("5. MODIFY\n");
printf("6. END\n");
printf("Enter your option : ");
scanf("%d",&op);
switch(op)
{
case 1:
insert();
display();
break;
case 2:
display();
break;
case 3:
del();
display();
break;
case 4:
printf("Enter the label to be searched : ");
scanf("%s",la);
y=search(la);
if(y==1)
{
printf("The label is already in the symbol Table");
}
else
{
printf("The label is not found in the symbol table");
}
break;
case 5:
modify();
display();
break;
case 6:
break;
}
}
while(op<6);
getch();
}
void insert()
{
int n;
char l[10];
printf("Enter the label : ");
scanf("%s",l);
n=search(l);
if(n==1)
{
printf("The label already exists. Duplicate cant be inserted\n");
}
else
{
struct symbtab *p;
p=malloc(sizeof(struct symbtab));
strcpy(p->label,l);
printf("Enter the address : ");
scanf("%d",&p->addr);
p->next=null;
if(size==0)
{
first=p;
last=p;
}
else
{
last->next=p;
last=p;
}
size++;
}
}
void display()
{
int i;
struct symbtab *p;
p=first;
printf("LABEL\tADDRESS\n");
for(i=0;i
printf("%s\t%d\n",p->label,p->addr);
p=p->next;
}
}
int search(char lab[])
{
int i,flag=0;
struct symbtab *p;
p=first;
for(i=0;i
if(strcmp(p->label,lab)==0)
{
flag=1;
}
p=p->next;
}
return flag;
}
void modify()
{
char l[10],nl[10];
int add, choice, i, s;
struct symbtab *p;
p=first;
printf("What do you want to modify?\n");
printf("1. Only the label\n");
printf("2. Only the address of a particular label\n");
printf("3. Both the label and address\n");
printf("Enter your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Enter the old label\n");
scanf("%s",l);
printf("Enter the new label\n");
scanf("%s",nl);
s=search(l);
if(s==0)
{
printf("NO such label");
}
else
{
for(i=0;i
if(strcmp(p->label,l)==0)
{
strcpy(p->label,nl);
}
p=p->next;
}
}
break;
case 2:
printf("Enter the label whose address is to modified\n");
scanf("%s",l);
printf("Enter the new address\n");
scanf("%d",&add);
s=search(l);
if(s==0)
{
printf("NO such label");
}
else
{
for(i=0;i
if(strcmp(p->label,l)==0)
{
p->addr=add;
}
p=p->next;
}
}
break;
case 3:
printf("Enter the old label : ");
scanf("%s",l);
printf("Enter the new label : ");
scanf("%s",nl);
printf("Enter the new address : ");
scanf("%d",&add);
s=search(l);
if(s==0)
{
printf("NO such label");
}
else
{
for(i=0;i
if(strcmp(p->label,l)==0)
{
strcpy(p->label,nl);
p->addr=add;
}
p=p->next;
}
}
break;
}
}
void del()
{
int a;
char l[10];
struct symbtab *p,*q;
p=first;
printf("Enter the label to be deleted\n");
scanf("%s",l);
a=search(l);
if(a==0)
{
printf("Label not found\n");
}
else
{
if(strcmp(first->label,l)==0)
{
first=first->next;
}
else if(strcmp(last->label,l)==0)
{
q=p->next;
while(strcmp(q->label,l)!=0)
{
p=p->next;
q=q->next;
}
p->next=null;
last=p;
}
else
{
q=p->next;
while(strcmp(q->label,l)!=0)
{
p=p->next;
q=q->next;
}
p->next=q->next;
}
size--;
}
}
What are Principles of object oriented programming language?
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.