What is the difference between a data type and a data structure?
Data type can be regarded as data structure because we can define our own data type by using typed function. Data types are the category in which the variable are listed to hold the specific value and data structures are the way in which the values and variables are stored in the memory. The use of a data type called structures allows a collection of values possibly of different types to be treated as a single item. Each data structure is built up from the basic data types of the underlying programming language using the available data structuring facilities, such as
arrays & pointers
Program to copy one file into another using command line arguments?
#include<iostream>
#include<fstream>
#include<algorithm>
#include<string>
int copy_file (const std::string& src_name, const std::string& dst_name)
{
// Ensure source exists for input.
if (!std::ifstream (src_name).good())
{
std::cerr << "The system cannot find the file specified.\n" << std::endl;
return -1;
}
// If destination exists (for input), ask to overwrite.
if (std::ifstream (dst_name).good())
{
std::string yn;
while (!yn.size())
{
std::cerr << "The destination file exists. Overwrite? [Y/N]";
std::getline (std::cin, yn);
if (yn.size())
{
switch (yn[0])
{
case ('Y'): case ('y'): continue;
case ('N'): case ('n'): return -1;
default: yn.clear();
}
}
}
}
// Try opening or creating the destination.
std::ofstream dst (dst_name, std::ios_base::binary);
if (!dst.good())
{
std::cerr << "The destination file could not be created or opened for writing.\n" << std::endl;
return -1;
}
// Definitely good to go.
std::ifstream src (src_name, std::ios_base::binary);
std::cout << "Copying " << src_name << " to " << dst_name << std::endl;
dst << src.rdbuf();
std::cout << "\t1 file copied.\n" << std::endl;
return 0;
// Note: both files close when they fall from scope...
}
int main (int argc, char* argv[])
{
switch (argc)
{
case (3):
return copy_file (argv[1], argv[2]);
case (2):
if (std::string(argv[1])!="/?")
break;
// strip the path and extension from the command
std::string command (argv[0]);
size_t last_backslash = command.rfind ('\\') + 1;
size_t last_period = command.rfind ('.');
std::string exe = command.substr (last_backslash, last_period-last_backslash);
std::transform (exe.begin(), exe.end(), exe.begin(), ::toupper);
std::cerr << "Copies a file to another location.\n\n"
<< exe << " source destination\n\n"
"source\t\tSpecifies the file to be copied.\n"
"destination\tSpecifies the filename for the new file.\n" << std::endl;
return 0;
}
std::cerr << "The syntax of the command is incorrect.\n" << std::endl;
return -1;
}
What are the Application of merge sort in real life?
It is used in tape drives to sort data - its good with parallel processing, which is why it is used there.
What is the algorithm for a for loop?
the for loop is basically a repitation or traversing loop means one's to write his name 100 times he use the for loop
example
for(i=0;i<=100;i++)
{
printf("my name is AA");
}
the for loop checks the condition until i<=100 repeates the name or check the condition upto 100 times and then terminates.
Sort the array of integers in Descending order?
Make use of Java's robust library:
// filled with various ints
int[] a;
// temporary variable for swapping values
int temp;
// sort with fast, built-in algorithm
java.util.Arrays.sort(a);
// reverse the array
for( int i = 0; i < a.length/2; ++i ) {
temp = a[i];
a[i] = a[a.length - i - 1];
a[a.length - i - 1] = temp;
}
Obviously, if you're concerned with execution speed you could write your own sort method which would sort into descending order instead of ascending order (perhaps by modifying Java's sort algorithm).
What are c in and c out in c plus plus?
C and C++ are two common languages used for writing programs and getting suitable desired outputs. They are both strongly typed and, like most other languages in widespread use, imperative.
C is a raw procedural language developed in 1969 to operate on UNIX systems; see the related link for an extensive history. It makes use of structures (simple groups of named values), functions, pre-processor macros, and pointers to memory addresses. It includes some built-in functions known as its standard library. The language, along with its libraries, was originally standardized in 1989 and again in 1999.
C++, begun in 1979 and standardized in 1998, is a step above C and intended to improve the language with object-oriented features such as classes, inheritance, polymorphism, etc. It is a super set of C, meaning that most C source is perfectly valid as C++. It is easier than C because of its extra features, but it is also much more complex and learning all its features is a major accomplishment. More Windows applications are written in C++ than C, but if either one provides a DLL file the other can talk to the first.
What are programming languages written in?
which programs?the easiest way to find out is to go to wikipedia and search for particular program and on right hand side you will see information in which programming language is written
Major difference of turbo c and ansi c and its structures?
Turbo C is an earlier C compiler from Borland. ANSI C is the standard for the C programming language. Therefore, the two are different by definition - Turbo C is a computer program, and ANSI C is a specification for a computer program, which can be implemented in various ways. If we rephrase the question as "what are the difference between the C versions as depicted in the ANSI standard and as implemented in Turbo C?" I would say that most are PC-specific such as the use of far pointers.
However you want!
Pseudo code is not a well defined programming language. The idea is to write something that looks like code, but doesn't necessarily have to run in any specific language.
For example, you could write:
for all values in some_array:
if value is empty:
fill value
without defining at this point what exactly it means for a value to be empty, or how to fill a value.
Write a program to input the square matrix and display the sum of diagonal elements?
#include<iostream>
#include<random>
#include<time.h>
int main()
{
std::default_random_engine generator ((unsigned)time(0));
std::uniform_int_distribution<int> distribution (1,9);
std::cout << "Array:\n" << std::endl;
int a[3][3];
for (size_t r=0; r!=3; ++r)
{
for (size_t c=0; c!=3; ++c)
{
a[r][c] = distribution (generator);
std::cout << a[r][c] << '\t';
}
std::cout << std::endl;
}
std::cout << std::endl;
int diagonal=0, anti_diagonal=0;
for (size_t i=0; i!=3; ++i)
{
diagonal += a[i][i];
anti_diagonal += a[2-i][i];
}
std::cout << "Diagonal sum : " << diagonal << std::endl;
std::cout << "Anti-diagonal sum : " << anti_diagonal << std::endl;
}
Basically it's a list.
Instead of typing x0, x1, x2, x3, x4... x99, an array lets you just type x[100]. Then to use each variable you just type x[number] and use it as normal. Arrays are so useful because you can iterate, or repeat, over them easily. You could define an array, then define an integer i. They you could make a loop in your program that increases each x value by 2. Just make it so I gets bigger each run of the loop and type this:
x[i] = x[i] + 2
A Note: if you define the array x to have 100 values, than it will go from 0 to 99, not 1 to 100.
There are also more advanced arrays that can get bigger as you need them to. They will grow without you thinking about it. You can also add data in the middle, and have all the data after it shifted one place. Or you could delete a piece of data from the middle and have all data after it shifted back one place. These arrays are generally called mutable (which means changeable) arrays. Normal arrays are called immutable arrays.
How do you find the sum of series 1 plus 2 plus 3 plus n using a c program?
#include<iostream.h>
#include<conio.h>
void main()
{
int num_last,res=0;
cout<<"Enter the last number : ";
cin>>num_last;
for(int i=0;i<=num_last;i++)
res=res+i;
cout<<"Result is "<<res<<endl;
getch();
}
Which is the unary operator used to dereference a pointer and return the value stored in it?
The asterisk (*) operator dereferences a pointer and returns the value stored in the memory pointed to by the pointer.
Which language is processor to c programming language?
That depends on each individual compiler. Some are written in assembly, some in C/C++, others are written in whatever high-level language the author likes best.
It is much easier to discover errors in a program that is well analyzed and well designed. Furthermore, a thoroughly analyzed and carefully designed program is much easier to follow and modify.Even the most experienced programmers spend a considerable amount of time analyzing a problem and designing an algorithm
What is the C program for byte stuffing?
#include
#include
main()
{
char a[20],fs[50]="",t[6],r[5];
int i,j,p=0,q=0;
clrscr();
printf("enter bit string : ");
scanf("%s",a);
strcat(fs,"01111110");
if(strlen(a)<5)
{
strcat(fs,a);
}
else
{
for(i=0;i
{
for(j=i;j
{
t[p++]=a[j];
}
t[p]='\0';
if(strcmp(t,"11111")==0)
{
strcat(fs,"111110");
i=j-1;
}
else
{
r[0]=a[i];
r[1]='\0';
strcat(fs,r);
}
p=0;
}
for(q=i;q
{
t[p++]=a[q];
}
t[p]='\0';
strcat(fs,t);
}
strcat(fs,"01111110");
printf("After stuffing : %s",fs);
getch();
}
What is pseudo code for GCD of two numbers?
public class GCD {
public static void main(String[] args) {
//Example how to use this method
System.out.println(GCD(15,50));
}
//find the greatest common divisor of two numbers
public static int GCD(int a, int b){
if (b == 0) return a;
return GCD(b, a % b);
}
}
Hope this help to solve you problem.
Write a programme in c to convert Fahrenheit to celsius and vice versa?
double celsiusToFahrenheit(double degreesC)
{
return degreesC * 9.0 / 5.0 + 32.0;
}
double fahrenheitToCelsius(double degreesF)
{
return (degreesF - 32.0) * 5.0 / 9.0;
}
Or instead of having to divide and multiply you can simply use (Celsius +32)1.8.
(C+32)1.8
Fahrenheit -32 divided by 1.8.
F-32/1.8.
Write an algorithm for addition of two integer?
1.Declare three variables as
int a,b,c;
2.Get the Input of two numbers of Integers from the user:
scanf("%d",&a);
scanf("%d",&b);
3.add a and b and store the result in c
4. print c
How do you provide the default values of function parameters?
It depends on the programming language, however in languages based upon C, we simply assign the default values within the function declaration.
int f (int x; int y=0; int z=42);
Note that if we provide a default value for any argument, all the remaining arguments must also have default values. Here, x has no default but y does, thus z requires one as well.
When defaults are given, the caller need not provide values if the defaults suffice:
f (1, 2, 3); // ok -- all three values given
f (1, 2); // ok, f (1, 2, 42) implied
f (1); // ok, f (1, 0, 42) implied
f (); // error -- missing argument! x has no default
We can also provide default values in the function definition (because a definition is itself a declaration), however the declaration (alone) is preferred because it provides the best means of documenting functions; it's what the compiler "sees" and is what the user refers to. If a function has no forward declaration then it was never intended for users anyway; it's an implementation detail. But providing defaults in both the declaration and definition (or even just the definition) is frowned upon, and most compilers will guard against this.
In C++ and other object-oriented languages, although many classes do have a "natural" default value (a string defaults to an empty string, for instance), we cannot use this as an implied default. All default values (including natural default values) must be explicitly stated in the function declaration otherwise values are expected to be passed via the caller:
int g (std::string s, std::string s2="");
Here, although std::string defaults to an empty string, the argument s does not: thus the caller is expected to provide a value for s. However, s2 has an explicitly stated default (the natural default), so the caller need not provide a value for s2:
g("hello", "world"); // ok -- both arguments given
g ("foobar"); // ok - s is given, s2 defaults to empty
g (); // error - missing argument! s has no default
Binary search program for 8085?
Res db " position",13,10,"$"
msg2 db 'key not found!!!!!!!!!!!!!. $'
.code
mov ax,@data
mov ds,ax
mov bx,00
mov dx,len
mov cx,key
again:cmp bx,dx
ja fail
mov ax,bx
add ax,dx
shr ax,1
mov si,ax
add si,si
cmp cx,arr[si]
jae big
dec ax
mov dx,ax
jmp again
big:je success
inc ax
mov bx,ax
jmp again
success:add al,01
add al,'0'
mov res,al
lea dx,msg1
jmp disp
fail:lea dx,msg2
disp:mov ah,09h
int 21h
mov ah,4ch
Why we use extension as cpp in c plus plus programs?
Source files use a .cpp file extension, while headers use .hpp. However, this is merely a convention. Most C++ programmers use .h for all headers, even though this convention implies a C-style header rather than a C++ header. Ultimately, the extension is immaterial. If the file can be included in other files, then it is a header, otherwise it is a source file.
flow charts are useful in getting a lot of information or methods across by a systematic order of flow of informaion. some people are visual in learning information and this is a form of a 'pictorial' diagram of conveying info. in an organizaed manner. It depicts a map of info.