Write a C++ program which will accept ‘n’ integers from user through command line argument. Store Prime numbers in file “Prime.txt” and remaining numbers in “Others.txt”.
#include<stdlib.h>
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
int main(int n, char * a[]) //n=no of arguments , a=arguments
{
int x,i;
cout<<"\nArguments
are: ";
for(i=1;i<n;i++)
{
cout<<a[i]<<" ";
}
ofstream f,f2; //
f.open("prime.txt");
f2.open("others.txt");
for(i=1;i<n;i++)
{
x=atoi(a[i]); //
int flag=0;
for(int
j=2;j<=x/2;j++)
{
if(x%j==0)
{
flag=1;
break;
}
}
if(flag==0)
{
f<<x;
f<<"
";
}
else
{
f2<<x;
f2<<"
";
}
}
f.close();
f2.close();
ifstream fi; //
fi.open("prime.txt",ios::in);
cout<<"\nContent of
Prime File is: \n";
char c;
c=fi.get();
while(!fi.eof())
{
cout<<c;
c=fi.get();
}
fi.close(); //close the file
fi.open("others.txt",ios::in);
cout<<"\nContent of
Others File is: \n";
c=fi.get(); //
while(!fi.eof()) // eof= end of file
{
cout<<c;
c=fi.get();
}
fi.close();
getch();
return(0);
}
-
Next Create a class for inventory of Mobile containing Model_Number, Company_Name, Price, Stock as data members. Mobile can be sold, if stock is available, otherwise purchase will be made. Write a C++ program to perform following functions : i. To accept and display mobile details ii. To sale a Mobile (Sale contains Model_Number & Quantity of mobile) iii. To Purchase a Mobile (Purchase contains Model_Numbet & Quantity of mobile)
-
Previous Create a base class Conversion. Derive three different classes Weight (Gram, Kilogram), Volume(Milliliter, Liter), Currency(Rupees, Paise) from Conversion class. Write a C++ program to perform read, convert and display operations. (Use Pure virtual function)
0 Comments