Posts

Showing posts from January, 2020

complete example creating , updating and deleting a text file in C++

Hello From IQBAL , guys, we often come across situations to store little data in .txt file. in the code below i have covered:  creating txt file to store records of employees showing records from the file(reading file) updating salary of the employee(updating specific text in the file) deleting old file when program runs. An Employee Class with needed Methods your comments and suggestions are welcomed #include <iostream> #include <string> #include <fstream> #include <streambuf> #include <bits/stdc++.h>  using namespace std; class Employee{ public:   void add(string code,string name,int salary) {   cout<<"Employee: "<<name<<" with Salary :"<<salary<<" Addedd."; ofstream file;   file.open ("employee.txt",std::ios_base::app);   file <<code<<","<<name<<","<<salary<<";";  

printing Alphabets in a shape like diamond inside a square using C++

Image
Hello From IQBAL ! guys, after tiresome work i have produced the following code to print alphabets like below:   Below is the source code, feel free to comment your suggestions and corrections. #include <iostream> using namespace std; int main(void){     int a= 65;     char height = 'G'; // can get this as input via cin>>     int endchar = (int) height;     int rows, c, k;          rows =endchar-a-1; int steps = rows;     for (k=1; k<=rows+1; k++)     {      for(c=0; c<=steps; c++)     {     cout<<((char)(65+c));     }         for(c=1; c<=(2*k-2); c++)     {     cout<<" ";     }     if(k==1){         for(c=1; c<=rows; c++) {     cout<<((char)(endchar-c-1));     }     } else{     for(c=steps+1; c>0; c--)     {     cout<<((char)(a+c-1));     }     }     steps--;     cout<<"\n";         } //upper part ends here     //starts lower part