70) Write a program in C++ to input roll no and total marks of 10 student from an input data file marks.txt. Print roll no and total marks of only those student who get 300 or more in his total marks?

#include<iostream.h> #include<fstream.h> #include<conio.h> void main() {                 int rn,tm,i;                 clrscr();                 ifstream myfile("marks.txt");                 for(i=0;i<10;i++)                                 {                                 myfile>>rn;                                 myfile>>tm;                                 if(tm>=300)                                                 cout<<rn<<"\t"<<tm<<endl;                                 }                 myfile.close();                 getch(); }  

Advertisements

69) Write a program in C++ to input name and roll no of 5 student from an input data file student.txt. Print both name and roll no of all student on screen?

#include<iostream.h> #include<fstream.h> #include<conio.h> void main() {                 char name[20];                 int rn,i;                 clrscr();                 ifstream myfile;                 myfile.open("student.txt");                 for(i=0;i<5;i++)                                 {                                 myfile>>name;                                 myfile>>rn;                                 cout<<name<<"\t"<<rn<<endl;                                 }                 myfile.close();                 getch(); }  

68) Write a program in C++ to input roll no and total marks of some student until total marks and greater than zero. Arrange both roll no and total marks in descending order on total marks and write it to an output file name as result.txt?

#include<iostream.h> #include<fstream.h> #include<conio.h> void main() {                 int rn[50],tm[50],temp,i,j,n=0;                 clrscr();                 while(1)                                 {                                 cout<<"Enter Roll No :- ";                                 cin>>rn[n];                                 cout<<"Enter Total Marks :- ";                                 cin>>tm[n];                                 if(tm[n]==0)                                                 break;                                 n++;                                 }                 for(i=0;i<n-1;i++)                                 for(j=i+1;j<n;j++)                                                 {                                                 if(tm[j]>tm[i])                                                                 {                                                                 temp=tm[j];                                                                 tm[j]=tm[i];                                                                 tm[i]=temp;... Continue Reading →

67) Write a program in C++ to input roll no and total marks of some student from keyboard until total marks greater than zero. Write roll no and total marks of those student to one output file with total marks greater than or equal to 300. Name of this output file is pass.txt. Write roll no and total marks of remaining students in other output file named as fail.txt?

  #include<iostream.h> #include<fstream.h> #include<conio.h> void main() {                 int rn,tm=1;                 clrscr();                 ofstream pass("pass.txt");                 ofstream fail("fail.txt");                 while(tm>0)                 {                                 cout<<"Enter Roll No:- ";                                 cin>>rn;                                 cout<<"Enter Tatal Marks:- ";                                 cin>>tm;                                 if(tm>=300)                                                 pass<<rn<<"\t"<<tm<<endl;                                 else if(tm>0)                                                 fail<<rn<<"\t"<<tm<<endl;                 }                 pass.close();                 fail.close();                 getch(); }

66) Write a program in C++ to input roll no and total marks of student until total marks is greater than zero. Write roll no and total marks to output file named as student.txt only when total marks greater than equal to four hundred?

#include<iostream.h> #include<fstream.h> #include<conio.h> void main() {                 int rn,tm;                 tm=1;                 clrscr();                 ofstream myfile;                 myfile.open("Test.txt");                 while(tm>0)                                 {                                 if(tm>=400)                                                 myfile<<rn<<"\t"<<tm<<endl;                                 cout<<"Enter Roll Number : - ";                                 cin>>rn;                                 cout<<"Enter Total Marks : - ";                                 cin>>tm;                                 }                 myfile.close();                 getch(); }  

65) An example of opening a file for output?

A. #include<iostream.h> #include<fstream.h> #include<conio.h> void main() {                 char name[20];                 int age;                 clrscr();                 ofstream outfile("Test.txt");                 cout<<"Enter Name - ";                 cin>>name;                 cout<<"Enter Age - ";                 cin>>age;                 outfile<<name<<"\t"<<age;                 outfile.close();                 getch(); } B. #include<iostream.h> #include<fstream.h> #include<conio.h> void main() {                 char name[20];                 int age;                 clrscr();                ... Continue Reading →

64) Write a program in C++ to input some integer and some floating point number in an array of class template. Arrange and print both integer and floating point number in ascending order?

#include<iostream.h> #include<conio.h> template <class T> class vector { private:                 T *v;                 int size; public:                 vector(int vector_size)                 {                                 size=vector_size;                                 v=new T[vector_size];                 }                 ~vector()                 {                                 delete v;                 }                 T &elem(int i)                 {                                 if(i>=size)                                                 cout<<"Error Out of Range";                                 return v[i];                 }... Continue Reading →

63) An example of template class?

#include<iostream.h> #include<conio.h> template <class T> class vector { private:                 T *v;                 int size; public:                 vector(int vector_size)                 {                                 size=vector_size;                                 v=new T[vector_size];                 }                 ~vector()                 {                                 delete v;                 }                 T &elem(int i)                 {                                 if(i>=size)                                                 cout<<endl<<"Error Out of Range ";                                 return v[i];                ... Continue Reading →

62) Write a program in C++ to input some values inform of integer and floating point number in an array. Array and print both type of number in descending order using function template?

#include<iostream.h> #include<conio.h> template <class T> void sort(T *a,int b) {                 T temp;                 int i,j;                 for(i=0;i<b-1;i++)                                 for(j=i+1;j<b;j++)                                                 if(a[j]>a[i])                                                                 {                                                                 temp=a[j];                                                                 a[j]=a[i];                                                                 a[i]=temp;                                                                 } } void main() {                 int n[100],size,i;                 clrscr();                 cout<<"Enter Size (Maximum [100]) :- ";                 cin>>size;                 cout<<"Enter Integer No \n";... Continue Reading →

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: