Posts

WAP that obtains the rotation factor and rotates the array as per it.

Image
/* WAP that obtains the rotation factor and rotates the array as per it. */ #include<iostream.h> int main() {       int Arr[15] = {22, 31, 12, 44, 5, 17, 1, 69, 11, 23, 6, 9, 23, 67, 90};       int r;       cout<<"\nEnter rotation factor (ie rotate by ?): ";       cin>>r;       cout<<"Originally array is: "<<endl;       for(int i=0;i<15;i++)       cout<<Arr[i]<<",";       cout<<":::"<<endl;       //now rotate the array       int temp[15];       for(i=14;i>=0;i--)       {             if((i+r) >=15)                   temp[i + r - 15] = Arr[i];             else                   temp[i+r] = Arr[i];       }       cout<<"Array after Rotation by factor "<<r<<" is: "<<endl;       for(i=0;i<15;i++)       {             Arr[i] = temp[i];             cout<<Arr[i]<<",";  

WAP to display contents of a file using get() function.

Image
//WAP to display contents of a file using get() function. #include<iostream.h> #include<fstream.h> #include<stdlib.h> int main() {       system("cls");       char ch;       ifstream fin;     //create input stream       fin.open("marks.dat", ios::in);     //open file       if(!fin)    //if fin stores zero i.e., false value       {             cout<<"Cannot open file!!\n";             return 1;       }       while(fin)       {     fin.get(ch);      //read a character             cout<<ch;   //display the character       }       fin.close();       return 0; } OUTPUT

WAP to create a single file and then display its contents.

Image
//WAP to create a single file and then display its contents. #include<iostream.h> #include<conio.h> #include<fstream.h> #include<stdlib.h> void main() {       system("cls");       ofstream fout("student", ios::out);       char name[30], ch;       float marks =0.0;       //Loop to get 5 records       for(int i=0;i<5;i++)       {             cout<<"Student "<<(i+1)<<":\tName: ";             cin.get(name,30);             cout<<"\t\tMarks: ";             cin>>marks;             cin.get(ch);      //to empty input buffer write to the file             fout<<name<<"\n"<<marks<<"\n";       }       fout.close();     //disconnect student file from fout       ifstream fin("student", ios::in);   //connect student file to input stream fin       fin.seekg(0);     //To bring file pointer at the f

WAP to get roll numbers and marks of the student of a class (get from the user) and store these details into a file called Marks.dat

Image
/*WAP to get roll numbers and marks of the student of a class (get from the user) and store these details into a file called Marks.dat*/ #include<iostream.h> #include<fstream.h> int main() {     ofstream filout;       filout.open("marks.dat",ios::out);       char ans = 'y';       int rollno;       float marks;       while(ans =='y'||ans =='Y')       {             cout<<"\nEnter Roll no.: ";             cin>>rollno;             cout<<"\nEnter Marks : ";             cin>>marks;             filout<<rollno<<'\n'<<marks<<'\n';             cout<<"\nWant to enter more records? (y/n)... ";             cin>>ans;       }       filout.close();       return 0; } OUTPUT

WAP using a class to store price list of 5 items and to print the largest prices as well as the sum of all prices.

Image
/*WAP using a class to store price list of 5 items and to print the largest prices as well as the sum of all prices.*/ #include<iostream.h> #include<stdlib.h> class ITEM{ int itemcode[5];                   float it_price[5];             public:                   void initialize (void);                   float largest (void);                   float sum (void);                   void display_items (void);             }; //.....Member Function Definitions Follow..... void ITEM::initialize (void) { for(int i=0;i<5;i++)       {     cout<<"\n"<<"Item No.: "<<(i+1);             cout<<"\n"<<"Enter item code: ";             cin>>itemcode[i];             cout<<"\n"<<"Enter item price: ";             cin>>it_price[i];             cout<<"\n";       } } float ITEM::largest(void) {     float large = it_price[

WAP to illustrate working of default arguments. Calculate interest amount making use of default arguments.

Image
/* WAP to illustrate working of default arguments. Calculate interest amount making use of default arguments. */ #include<iostream.h> #include<stdlib.h> void amount(float princ, int time = 2, float rate = 0.08); //prototype void amount(float princ, int time, float rate) {       cout<<"\nPrincipal Amount: "<<princ;       cout<<"\tTime: "<<time<<" years;";       cout<<"\tRate: "<<rate;       cout<<"\nInterest Amount: "<<(princ*time*rate)<<"\n"; } int main() {       system ("cls");       cout<<"Case 1";             amount(2000);       cout<<"Case 2";             amount(2500, 3);       cout<<"Case 3";             amount(2300, 3, 0.11);       cout<<"Case 4";             amount(2500, 0.12);       return 0; } OUTPUT

WAP to illustrate working of call-by-reference method of a function invoking.

Image
/* WAP to illustrate working of call-by-reference method of a function invoking. */ #include<iostream.h> #include<stdlib.h> int main() {       system ("cls");       void change(int &);     //notice prototype       int orig = 10;    //original value is 10.       cout<<"The original value is: "<<orig<<"\n";       change(orig);       cout<<"Value after change() is over: "<<orig<<"\n";       return 0; } void change(int &a) {     a = 20;       cout<<"Value of orig in function change() is: "<<a<<"\n";       return; } OUTPUT