Wednesday, October 29, 2014

Write a program in C++ to create a RAMDRIVE and associate an acyclic directory structure to it. Use this RAMDRIVE to store input, out files to run a calculator program.

Problem Statement:

Write a program in C++ to create a RAMDRIVE and associate an acyclic directory structure to it. Use this RAMDRIVE to store input, out files to run a calculator program.

PROGRAM

ramdisk.cpp

#include<iostream>
#include <stdlib.h>
using namespace std;
int main(){
cout<<"Creating Ramdisk...\n\n";
system("mkdir /mnt/ramdisk");
system("mount -t tmpfs -o size=256M tmpfs /mnt/ramdisk");
cout<<"Ramdisk created at /tmp/ramdisk/ "<<endl<<endl;
cout<<"Total size available on ramdrive:\n";
system("df -h /mnt/ramdisk");
cout<<"\n\n";
cout<<"Amount of Ramdrive used:\n";
system("du -h /mnt/ramdisk/");
system("cp input.txt /mnt/ramdisk");
system("cp calc.cpp /mnt/ramdisk");
return 0;

}

calc.cpp

#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ofstream fout;
fout.open("/mnt/ramdisk/input.txt");
int a,b,c,d,y=1;
while(y)
{
fout<<endl<<"First number : ";
cout<<"\n\nEnter Number ";
cin>>a;
fout<<a<<endl<<"Second number : ";
cout<<"\nEnter Another Number ";
cin>>b;
fout<<b<<endl;
cout<<"\nSelect your option\n\n1.Addition\n\n2.Subtraction\n\n3.Multiplication\n\n4.Division\n\nPress any key to exit ";
cin>>c;
switch(c)
{
case 1:
{
d=a+b;
cout<<"\n\nAnswer: "<<d;
fout<<"Addition is : "<<d;
break;
}
case 2:
{
d=a-b;
cout<<"\n\nAnswer: "<<d;
fout<<"Subtraction is : "<<d;
break;
}
case 3:
{
d=a*b;
cout<<"\n\nAnswer: "<<d;
fout<<"Multiplication is : "<<d;
break;
}
case 4:
{
d=a/b;
cout<<"\n\nAnswer: "<<d;
fout<<"Division is : "<<d;
break;
}
default:
{
y=0;
break;
}
}
}
fout.close();
return 0;

}

No comments:

Post a Comment

Perform a suitable assignment using Xen Hypervisor or equivalent open source to configure it. Give necessary GUI.

 To install kvm on Fedora:  yum install kvm  yum install virt-manager libvirt libvirt-python python-virtinst  su -c "yum install @v...