Can you have nested switch case statement in C?
If that's what you really want to do, the compiler will allow it. It might indicate an inefficient design, though.
#include<iostream.h>
class student
{
char name[10];
int rollno;
public:
void get()
{
cout<<"enter student's name"<<endl;
cin>>name;
cout<<"enter student's rollno"<<endl;
cin>>rollno;
}
void disp()
{
cout<<"Name of the student is : "<<name<<endl;
cout<<"Rollno is : "<<rollno<<endl;
}
};
class marks:public student
{
char subjectname[15];
int subcode,intmarks,extmarks;
public:
void get()
{
student::get();
cout<<"enter subject name";
cin>>subjectname;
cout<<"enter subject code";
cin>>subcode;
cout<<"enter Internal marks";
cin>>intmarks;
cout<<"enter External marks";
cin>>extmarks;
}
void disp()
{
student::disp();
cout<<"Subject name is : "<<subjectname<<endl;
cout<<"Subject code is : "<<subcode<<endl;
cout<<"Internal marks : "<<intmarks<<endl;
cout<<"External marks : "<<extmarks<<endl;
}
};
void main()
{
marks m;
m.get();
m.disp();
}
You have to correctly identify the type of data, for storage efficiency, but even more important, to have the required flexibility. For example, you may decide to store a telephone number as a number. Later you find out that this is an invitation to trouble: if you define it as a number, you can only store digits, but no hyphens, spaces, or parentheses. So, in this case, some kind of alphanumeric data type (text, string; names vary in different programming languages) is more appropriate.
You should give your variable names so that they can be recognized. In a quick exercise, you may work with 3 or 4 variables, so you won't notice the difference. But in a real-world program, you may have scores, or hundreds, of variables; program maintenance would be a nightmare if you can't figure out what several of the variables are used for.
You have to correctly identify the type of data, for storage efficiency, but even more important, to have the required flexibility. For example, you may decide to store a telephone number as a number. Later you find out that this is an invitation to trouble: if you define it as a number, you can only store digits, but no hyphens, spaces, or parentheses. So, in this case, some kind of alphanumeric data type (text, string; names vary in different programming languages) is more appropriate.
You should give your variable names so that they can be recognized. In a quick exercise, you may work with 3 or 4 variables, so you won't notice the difference. But in a real-world program, you may have scores, or hundreds, of variables; program maintenance would be a nightmare if you can't figure out what several of the variables are used for.
You have to correctly identify the type of data, for storage efficiency, but even more important, to have the required flexibility. For example, you may decide to store a telephone number as a number. Later you find out that this is an invitation to trouble: if you define it as a number, you can only store digits, but no hyphens, spaces, or parentheses. So, in this case, some kind of alphanumeric data type (text, string; names vary in different programming languages) is more appropriate.
You should give your variable names so that they can be recognized. In a quick exercise, you may work with 3 or 4 variables, so you won't notice the difference. But in a real-world program, you may have scores, or hundreds, of variables; program maintenance would be a nightmare if you can't figure out what several of the variables are used for.
You have to correctly identify the type of data, for storage efficiency, but even more important, to have the required flexibility. For example, you may decide to store a telephone number as a number. Later you find out that this is an invitation to trouble: if you define it as a number, you can only store digits, but no hyphens, spaces, or parentheses. So, in this case, some kind of alphanumeric data type (text, string; names vary in different programming languages) is more appropriate.
You should give your variable names so that they can be recognized. In a quick exercise, you may work with 3 or 4 variables, so you won't notice the difference. But in a real-world program, you may have scores, or hundreds, of variables; program maintenance would be a nightmare if you can't figure out what several of the variables are used for.
Would you Write c plus plus program using array for Fibonacci number?
You can write a C++ fib pro using arrays but the problem is the prog becomes very complicated since u need to pass the next adding value in an array.....
How do you solve this game show program in Linux by C plus plus language?
this the question:
Write a program that will simulate the following situation 10,000 times so we can decide the answer to:
Suppose you're on a game show, and you're given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what's behind the doors, opens another door, say No. 3, which he knows has a goat. He then says to you, "Do you want to pick door No. 2?" Is it to your advantage to switch your choice?
The pseudocode for this assignment would be:
Run a loop 10,000 times that:
After the loop is done, output a message that tells how many times the "prize door" was the "first choice" and how many times the "prize door" was the "second choice" so we can know what is the best choice.
The output of the homework should look like:
Number of times staying was the correct strategy: [NUMBER]
Number of times switching was the correct strategy: [NUMBER]
Therefore, the best thing to do is to [STRATEGY].
Write a function to delete a specified node from linked list?
Presumably you have a situation like this:
Each node is an area in memory with (1) the address of the following node, (2) the address of the previous node, and (3) some more data.
Say the nodes are linked in alphabetical order and part of the list goes like this:
PrevNode
-> Data = "Cincinnati"
-> FrontPtr = address of "Cleveland"
-> BackPtr = address of "Amelia"
CurrNode
-> Data = "Cleveland"
-> FrontPtr = address of "Columbus"
-> BackPtr = address of "Cincinnati"
NextNode
-> Data = "Columbus"
-> FrontPtr = address of "Dayton"
-> BackPtr = address of "Cleveland"
...and you want to delete the middle one. Steps could be:
1. save the address of CurrNode as KillNode
2. copy CurrNode->FrontPtr (address of "Columbus") into
PrevNode->FrontPtr
3. copy CurrNode->BackPtr (address of "Cincinanti") into
NextNode->BackPtr
4. free up the space at the location named in KillNode
Can you create a list of famous people from wilmington N C?
Charlie Daniels, "The Devil Went Down to Georgia" Michael Jordan George "Meadowlark" Lemon, Harlem Globetrotter Trot Nixon, MLB Player, Boston Red Sox
What is reg52.h header in c language?
Not part of the standard C-library, so you have to contact its developer.
What is a Pure Virtual Function Write a C plus plus program using Pure Virtual Function?
A pure-virtual method is similar to a virtual method. A virtual method is a method that is expected to be overridden in a derived class while a pure-virtual method must be overridden in a derived class. The base class may provide a default implementation for a pure-virtual method, but it is not a requirement, whereas it must provide an implementation for a virtual method. In addition,
any base class that has a pure-virtual method becomes abstract; you cannot instantiate abstract classes -- you are expectedto derive from them.
#include
class Abstract
{
public:
// Pure-virtual method; note the '=0' to denote pure-virtual.
virtual void Show()=0;
};
class Derived : public Abstract
{
public:
virtual void Show()
{
// Implementation is required here!
std:: cout << "Derived" << std::end;
}
};
void main()
{
// Abstract a; // Compiler error!
Derived d;
d.Show(); // Call pure-virtual method.
return( 0 );
}
#include<iostream>
#include<sstream>
using namespace std;
int main()
{
std::vector<int> input;
for (size_t index=0; index<4; ++index)
{
cout << "Enter a number: ";
bool valid=false;
while (!valid)
{
string in;
cin >> in;
stringstream ss;
ss << in;
if (!(valid = (ss >> input[loop]))
std::cout << "Invalid input! Try again: ";
}
}
std::cout << "\n\nYou entered the following: ";
for (size_t index=0; index<4; ++index)
cout << input[loop] << ' ';
cout << '\n' << endl;
}
How can you write your name on c plus plus turbo v3.0?
#include<iostream>
int main()
{
std::cout << "Your name";
}
What notation does a condition statement use?
"if p then q" is denoted as p → q.
~p denotes negation of p.
So inverse of above statement is ~p → ~q, and contrapositive is ~q →~p.
˄ denotes 'and'
˅ denotes 'or'
Can we assign int and float values to the character data type in c language?
Yes, but this will result in an implicit conversion and possible narrowing. A char is always at least 8-bits in length, but an int may be 4 bytes in length (the actual length is implementation-defined) thus assigning an integer value outwith the range of a char will result in narrowing. Similarly when assigning a float (typically 16-bits in length); the fractional component will be lost and the integer value may be narrowed.
An unsigned char is only guaranteed to hold values in the range 0 through 255 and a signed char is only guaranteed to hold values in the range -127 through +127. Any values outwith those integer ranges may result in narrowing. Most modern architectures support twos-complement notation thus the signed range becomes -128 through +127, however this cannot be guaranteed across all implementations. Also, a "plain" char may be signed or unsigned depending on the implementation but is a distinct type from an explicitly signed or unsigned char. A plain char is only guaranteed to hold positive integer values in the range 0 through 127 across all implementations.
What is random access mavhine?
The term "random access" is not normally applied to machines. It is normally used to refer to a form of data storage in which data on any part of the medium can be accessed in constant time.
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int stack[10],n=0;
int fact(int);
int pop();
void push(int);
main()
{
int num;
printf("\n FACTORIAL USING STACK IMPLEMENTATED WITH ARRAY\n");
printf("\n Enter a number whose factorial is to be found(1-9): ");
scanf("%d",&num);
printf("\n The factorial is : %d",fact(num));
getch();
} void display()
{
int i;
printf("\n The stack is :\n");
for(i=1;i<=n;i++)
{
printf("%d\t",stack[i]);
}
}
int pop()
{ if(n==0)
{
printf("\n Stack empty!Pop not possible!");
exit(1);
}
else
{
int res=stack[n];
--n;
display();
return res;
}
} void push(int x)
{
if(n==9)
{
printf("\n Stack full!Push not possible");
exit(1);
}
else
{
n++;
stack[n]=x;
display();
}
}
int fact(int num)
{
if(num==2)
{
push(2);
push(1);
int res=1;
display();
while(n>=1)
res*=pop();
return res;
} else
{
push(num);
return fact(num-1);
}
}
False. A virtual base class is one that is common to two or more derived classes that are themselves base classes, and that may be combined through multiple inheritance. By declaring the common base class to be virtual in its direct derivatives, only one instance of the common base class exists in the multiple-inheritance classes.
Can you write a program for finding the prime factor using recursive function?
#include<stdio.h>
#include<conio.h>
void main()
{
int n=5,fact=1;
void fact();
printf("the value is %d",fact);
getch();
}
fact()
{
fact=fact(n)*fact(n-1);
return fact;
}
Where do c plus plus begin execution?
C++ begins its execution at int main(...parameters...) or int WINAPI WinMain(...parameters...). WinMain() is used in Win32 programming, for windows, message boxes etc. main() is used in console programming.
int main() either have no parameters ( int main()) or it can have two parameters ( int main(int argc, const char* argv[]) ). int argc is the argument count, and const char* argv[] is the argument vector (the values of the arguments). These parameters are only useful if you need to take arguments from the user when you start up the application.
int WINAPI WinMain() must have four parameters. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdParam, int nCmdShow). WINAPI is a method of passing parameters which comes from the days of Fortran and Pascal. It reverses the order the parameters are passed. Why this is necessary is not important WINAPI is simply required by Windows. HINSTANCE hInstance is a handle (a pointer) to the current application instance. HINSTANCE hPrevInstance is a handle to the previous instance. In theory, if there are multiple copies of an application open, then this would point to the last one created. LPSTR lpCmdParam is a long pointer to the command line calling existence to the application. If you were to open, let's say, "MyWin32App.exe" then this would be what lpCmdParam is pointing to. If you were to open "MyWin32App.exe -StartFullscreen" then that would be what it is pointing to. int nCmdShow is the parameter indicating how the window should be opened. You could start the application minimised, maximised etc.
References:
http://www.directxtutorial.com/Tutorial9/A-Win32/dx9A2.aspx
http://en.wikipedia.org/wiki/Main_function_(programming)#C_and_C.2B.2B
C program to find square of an integer?
#include
#include
void main()
{
long int n;
printf("Please enter the number");
scanf("%ld" ,&n);
n=n*n;
printf("Square of entered number = %ld ");
}
but if you want to show the entered number e.g.Square of the entered number 8=64
then below is the code.
#include
#include
void main()
{
long int m,n;
printf("Please enter the number");
scanf("%ld" ,&n);
m=n;
n=n*n;
printf("Square of entered number %ld = %ld ",m,n);
}
A recursive algorithm is an algorithm which calls itself with "smaller (or simpler)" input values, and which obtains the result for the current input by applying simple operations to the returned value for the smaller (or simpler) input.
Heres a recursive algorithm to reverse a string
char *rev(char str[],int pos1,int pos2)
{
if(pos1<pos2)
{
char temp=str[pos1];
str[pos1]=str[pos2];
str[pos2]=temp;
return rev(str,pos1+1,pos2-1);
}
return str;
}
You can call this function like this
char *r=rev("reverse it",0,9);
What is the use of c compiler in windows?
The c compiler in Windows converts the binary code from source files. C is a compiled programming language and it needs to be converted for the program to run.