Write a program that copies contents of one file into another file.

1 Answer

Answer :

Assuming input file to be copied file1.txt contents are “Hello Friends…” and file where the contents need to copy is file2.txt already created 

#include<iostream.h>

#include<conio.h>

#include<fstream.h>

#include<stdio.h>

#include<stdlib.h>

void main()

{

clrscr();

ifstream fs;

ofstream ft;

char ch, fname1[20], fname2[20];

cout<<"Enter source file name with extension (like files.txt) : ";

gets(fname1);

fs.open(fname1);

if(!fs)

{

cout<<"Error in opening source file..!!";

getch();

exit(1);

}

cout<<"Enter target file name with extension (like filet.txt) : ";

gets(fname2);

ft.open(fname2);

if(!ft)

{

cout<<"Error in opening target file..!!";

fs.close();

getch();

exit(2);

}

while(fs.eof()==0)

{

fs>>ch;

ft<<ch;

}

cout<<"File copied successfully..!!";

fs.close();

ft.close();

getch();

}

Related questions

Description : Write a program to count the number of lines in file.

Last Answer : #include<iostream.h> #include<fstream.h> #include<conio.h> void main() { ifstream file; char ch; int n=0; clrscr(); file.open("abc.txt"); while(file) { file. ... \n Number of lines in a file are:"<<n; file.close(); getch(); }

Description : Write a program to declare a class ‘book’ containing data members as ‘title’, ‘author-name’, ‘publication’, ‘price’. Accept and display the information for one object using pointer to that object.

Last Answer : #include<iostream.h> #include<conio.h> class book { char author_name[20]; char title[20]; char publication[20]; float price; public: void Accept(); void Display(); }; void ... title \t author_name \t publication \t price\n ; p-> Display(); getch(); }

Description : Write a program to implement the following hierarchy using suitable member functions. Refer Figure No.2.

Last Answer : # include <iostream.h> #include<conio.h> class Student { int roll_no; char name[10]; public: void read_studentData() { cout<< Enter student s roll no and name \n ; cin> ... { result r; clrscr(); r.read_result(); r.display_result(); getch(); }

Description : Write a program to overload the ‘—’ unary operator to negate the values.

Last Answer : #include<iostream.h> #include<conio.h> #include<string.h> class Number { int x,y; public: Number (int a, int b) { a =x; b =y; } void display() { cout<< ... ; -N1; cout<<"\n After negation:"; N1. display (); getch (); }

Description : Write a program to sort an 1-d array in ascending order.

Last Answer : #include<iostream.h> #include<conio.h> void main() { int arr[20]; int i, j, temp,n; clrscr(); cout<<"\n Enter the array size:"; cin>>n; cout<<"\n Enter ... 0;i<n;i++) {  cout<< \n <<arr[i]; } getch(); }

Description : Write a program to implement single inheritance from the following Refer Figure No.1

Last Answer : #include #include class employee { protected: int emp_id; char name[10]; }; class emp_info:public employee { int basic_salary; public: void getdata() { coutemp_id; coutname; coutbasic_salary; } void putdata() { cout

Description : Write a C++ program to count number of spaces present in contents of file.

Last Answer : #include<iostream.h> #include<fstream.h> #include<conio.h> void main() { ifstream file; charch; int s=0; clrscr(); file.open("abc.txt"); while(file) { ... of spaces present in the content of the given file are:"<<s; getch(); }

Description : What is the function of following UNIX command? WC - lb& (A) It runs the word count program to count the number of lines in its input, a, writing the result to b, as a foreground process. (B) It runs ... (D) It copies the l ' numbers of lines of program from file, a, and stores in file b.

Last Answer : (B) It runs the word count program to count the number of lines in its input, a, writing the result to b, but does it in the background.

Description : Write the applications of object oriented programming.

Last Answer : Applications of object oriented programming are: 1) Real time systems 2) Simulation and modeling 3) Object-oriented databases 4) Hypertext, hypermedia and expertext 5) AI and expert systems ... and parallel programming 7) Decision support and office automation systems 8) CIM/CAM/CAD systems

Description : Write any four benefits of OOP. 

Last Answer : Benefits of OOP: 1. We can eliminate redundant code and extend the use of existing classes. 2. We can build programs from the standard working modules that communicate with one another, ... interface descriptions with external systems much simpler. 10. Software complexity can be easily managed.

Description : Write two properties of static member function

Last Answer : i) A static member function can have access to only other static data members and functions declared in the same class. ii) A static member function can be called using the class name with a scope resolution operator instead of object name as follows: class_name::function_name;

Description : Write the code in python to read the contents of “number.csv” file consisting of data from a mysql table and print the data of the table -Technology

Last Answer : f = open('numbers.csv', 'r') with f:reader = csv.reader(f)for row in reader:for e in row:print(e)

Description : The instruction fetch operation is initiated by loading the contents of program counter into the and sends _ request to memory: a. Memory register and read b. Memory register and write c. Data register and read d. Address register and read

Last Answer : d. Address register and read

Description : When I write a business letter to one party "through" another, can I send copies to both parties at the same time? Or am I obligated to send to the "through" party and wait for him/her to decide if the letter is worth endorsing to the ultimate addressee?

Last Answer : you send the letter to the board and copy everyone else. the cc list should be at the foot of the letter.

Description : Write A Program That Will Store The Contents Of An Accumulator And Flag Register At Locations 2000h And 2001h.?

Last Answer : Answer :By making use of the Push & Pop instructions the program can be written as: LXISP, 4000H - this step initiates the SP at 4000h. PUSH PSW - the contents of the accumulator and flag are pushed into the stack. POP B MOV A, B STA 2000H MOV A, C STA 2001H HLT

Description : The Secretary of a Company should file copies of Special Resolution passed at Extraordinary General Meeting to the Registrar of Companies within– (A) 7 days (B) 14 days (C) 21 days (D) 30 days

Last Answer : Answer: 30 days

Description : .What is the main advantage of creating links to a file instead of copies of the file?

Last Answer : The main advantage is not really that it saves disk space (though it does that too) but, rather, that a change of permissions on the file is applied to all the link access points. The link will ... original. With copies you have to find all of the copies and change permission on each of the copies

Description : A virus is a harmful program, which one entering a computer, starts creating copies of itself. -Technology

Last Answer : True Virus is a malicious program that is designed to make a system sick, just like a real virus.

Description : A malicious program that copies itself from computer to computer is - a. Spam b. Worm c. Trojan Horse d. None of the these

Last Answer : b. Worm

Description : A malicious program that copies itself from computer to computer is - a. Spam b. Worm c. Trojan Horse d. None of the these

Last Answer : b. Worm

Description : Write a program to copy content of one file to another file.

Last Answer : class fileCopy {  public static void main(String args[]) throws IOException { FileInputStream in= new FileInputStream("input.txt"); FileOutputStream out= new FileOutputStream("output.txt"); int c=0; ... .close();  if(out!=null)  out.close();  }  } }

Description : Explain the friend function with proper example.

Last Answer : Friend function: The private members of a class cannot be accessed from outside the class but in some situations two classes may need access of each other s private data. So a common function can be declared which can be made friend ... ; } friend void swap(A,B); }; void swap(A a,B b) { cout

Description : What is parameterized constructor?

Last Answer : A constructor that accepts parameters is called as parameterized constructor. In some applications, it may be necessary to initialize the various data members of different objects with different values when they are ... an argument. Member function put ( ) displays the value of data member m .

Description : What are the rules for virtual function?

Last Answer : Rules for virtual function: 1. The virtual functions must be members of some class. 2. They cannot be static members. 3. They are accessed by using object pointers. 4. A virtual function can ... virtual function is defined in the base class, it need not be necessarily redefined in the derived class.

Description : What is inheritance? Give different types of inheritance.

Last Answer : Inheritance: The mechanism of deriving new class from an old/existing class is called inheritance. OR Inheritance is the process by which objects of one class acquired the properties of ... is a combination of single, multiple, multilevel and hierarchical inheritance. Diagram:

Description : State the rules for writing destructor function.

Last Answer : Rules for writing destructor function are: 1) A destructor is a special member function which should destroy the objects that have been created by constructor. 2) Name of destructor and name of the class should ... should not be classified in any types. 7) A class can have at most one destructor. 

Description : Describe ‘this’ pointer with an example.

Last Answer : this' pointer:  C++ uses a unique keyword called this to represent an object that invokes a member function. This unique pointer is automatically passed to a member function when it is invoked. ... pointer is used to represent object s when setdata ( ) and putdata ( ) functions are called. 

Description : Describe memory allocation for objects.

Last Answer : The memory space for object is allocated when they are declared and not when the class is specified. The member functions are created and placed in memory space only once when they are ... are essential because the member variables will hold different data values for different objects.

Description : Give syntax and use of fclose ( ) function.

Last Answer : Syntax:  int fclose(FILE* stream); Use: This function is used to close a file stream. The data that is buffered but not written is flushed to the OS and all unread buffered data is discarded.

Description : Explain virtual base class with suitable example.

Last Answer : Consider a situation where all three kinds of inheritance, namely, multilevel, multiple, hierarchical inheritance, are involved. This illustrated in fig a. the child has two direct base classes, parent1 & ... Grandparent { }; class Child: public Parent1,public Parent2 { };

Description : Explain use of scope resolution operator.

Last Answer : It is used to uncover a hidden variable. Scope resolution operator allows access to the global version of a variable. The scope resolution operator is used to refer variable of class anywhere in program. ... outside of class. Return_type class_name:: function_name( ) { Function body }

Description : What is multilevel inheritance? Draw the diagram to show multilevel inheritance. using classes with data member and member function. 

Last Answer : When a class is derived from another derived class then it is called as multilevel inheritance.

Description : What is a class? Give its example. 

Last Answer : Class is a user defined data type that combines data and functions together. It is a collection of objects of similar type. Example: class Student { int rollno; char name[10]; public: void getdata( ); void putdata( ); };

Description : State the difference between OOP and POP.

Last Answer : OBJECT ORIENTED PROGRAMMING (OOP) PROCEDURE ORIENTED PROGRAMMING (POP) Focus is on data rather than procedure. Focus is on doing things (procedure). Programs are divided into multiple ... approach is used in C++ language. Procedure oriented approach is used in C language.

Description : DOS batch file that prints out contents of a folder in notepad?

Last Answer : You must not have looked very hard :) First result on Google when searching for: contents of a folder into a notepad text file.

Description : Why Separates the contents in a file drawer?

Last Answer : Need answer

Description : Which command is used to display a file contents in octal form? A. cd B. od C. of D. oct E. None of the above

Last Answer : B. od

Description : What scrambles the contents of a file so you can't read it without having the right decryption key? a. Encryption b. Intrusion‐detection software c. Security‐auditing software d. All of the above

Last Answer : a. Encryption

Description : In Unix, the login prompt can be changed by changing the contents of the file ............... (A) contrab (B) init (C) gettydefs (D) inittab

Last Answer : Answer: C

Description : In the case of the program "Judge Judy" do you agree with the warning that its contents "aren't suitable for children"?

Last Answer : Absolutely. Kids should only watch continuous loops of Teletubbies, Bugs Bunny, and Robocop.

Description : Which of the following registers is loaded with the contents of the memory location pointed by the PC? A) Memory address registers B) Memory data registers C) Instruction register D) Program counter

Last Answer : Answer : C

Description : The contents of the program counter isthe __——__—oof the instruction to be run. a. Data b. Address c. Counter d. None of these

Last Answer : b. Address

Description : The instruction read from memory is then placed in the ___and contents of program counter is __ so that it contains the address of_ __ instruction in the program. a. Program counter, ... incremented and previous c. Instruction register, incremented and next d. Address register, decremented and next

Last Answer : c. Instruction register, incremented and next

Description : When subroutine is called contents of program counter is location address of __ instruction following call instruction is stored on _ __and program execution is transferred to __ address. a. Non ... , Stack and Main program Cc. Executable, Queue and Subroutine d. Executable, Stack and Subroutine

Last Answer : d. Executable, Stack and Subroutine

Description : Which of the following registers is loaded with the contents of the memory location pointed by the PC? a. Memory address registers b. Memory data registers c. Instruction register d. Program counter

Last Answer : Instruction register

Description : Which of the following registers is loaded with the contents of the memory location pointed by the PC? a. Memory address register b. Memory data register c. Instruction registers d. Program counter

Last Answer : c. Instruction registers

Description : Which of the following registers is loaded with the contents of the memory location pointed by the PC? a. Memory address registers b. Memory data registers c. Instruction register d. Program counter

Last Answer : c. Instruction register

Description : Which of the following registers is loaded with the contents of the memory location pointed by the PC? a. Memory address register b. Memory data register c. Instruction registers d. Program counter

Last Answer : c. Instruction registers

Description : Debugger is a program that (A) allows to examine and modify the contents of registers (B) does not allow execution of a segment of program (C) allows to set breakpoints, execute a segment of program and display contents of register (D) All of the above

Last Answer : (C) allows to set breakpoints, execute a segment of program and display contents of register