Student Report Card Project : c++

Here is how we all can create a software based on C++ without a GUI. Graphic will be generated through <graphic.h> and <windows.h> but all we need is an algorithm and logic to impplement it. How we store data, how we create record and how we manipulate them.

Even With this program you can get the logic to create it, with all extra functions.

We try to implement every single phenomena which will help you to understand the logic.

Continue reading

How To Convert A String (Containing Number Followed By Spaces ) Into Integer Array : C++

Have you ever think of converting a string ( containing numbers followed by space ) into integer array.
For that we need to learn : How to convert single char into integer in C++.
A smaller Logic and Everything become easy : Read Article to search beyond this.
Query By- Ruchir Gupta

Continue reading

ALGORITHM OPERATIONS

Question – WAP TO USE SORT,COPY,MERGE, FIND ALGORITHM.

Answer-

#include <iostream.h>    
#include <algorithm>    
#include <vector.h> 
#include <conio.h>      
using namespace std;
int main () 
{
  int arr[] = { 200, 100, 300 ,400, 50, 150, 246 };
  int prr[] = { 11, 22, 33, 44, 55, 66, 77 };
  int * p;
  
  //find algorithm
  cout<<"\n\t****FIND*****"<<endl<<endl;
  p = find (arr,arr+7,300);
  ++p;
  cout << "The element after 300 is " << *p <<endl;
  
  //copy algorithm
  cout<<"\n\t**** COPY *****"<<endl<<endl;
  vector <int> v(7);
  copy(arr,arr+7,v.begin());
  vector <int>::iterator it;
  for(it=v.begin(); it!=v.end(); ++it)
      cout << "The element is " << *it <<endl;
      
  //sorting algorithm
  cout<<"\n\t**** SORT *****"<<endl<<endl;
  sort(v.begin(),v.end());
  for(it=v.begin(); it!=v.end(); ++it)
      cout << "The element is " << *it <<endl;
     
  //merging algorithm
  cout<<"\n\t**** MERGING arr & 3 element of prr *****"<<endl<<endl;
  vector<int> v1(10);
  merge(arr,arr+7,prr,prr+3,v1.begin());
  vector<int>::iterator itt;
  for(itt=v1.begin(); itt!=v1.end(); ++itt)
      cout << "The element is " << *itt <<endl;
  cout<<"\nPROGRAMMING @ C#ODE STUDIO";
  getch();
  return 0;
}

algo_fin

FRIEND FUNCTION ( JOIN TWO CLASS )

QUESTION – MAKE TWO CLASS NAME EXTERNAL AND INTERNAL WITH DATA MEMBER CA MARKS AND THEORY MARKS.SUM THE BOTH MARKS USING DATA MEMBERS AND FRIEND FUNCTION.

ANSWER-

#include<iostream.h>
#include<conio.h>
class external;
class internal
{
int ca;
public: 
        void getdata()
        {
            cout<<"Enter marks ofinternal : ";
            cin>>ca;
        }
        friend void add(internal&,external&);
};
class external
{
int theory;
public: 
        void getdata()
        {
            cout<<"Enter marks of theory : ";
            cin>>theory;
        }
        friend void add(internal&,external&);
};
        
void add(internal& i,external& e)
{
        cout<<"\nTotal marks = "<<i.ca+e.theory;
}
        
int main()
{
        internal s1;
        s1.getdata();
        external s2;
        s2.getdata();
        add(s1,s2);
        cout<<"\n\nPROGRAMMING @ C#ODE STUDIO";
        getch();
}

friend_fn

THE STANDARD TEMPLATE LIBRARY

The Standard Function Library: This library consists of general-purpose,stand-alone functions that are not part of any class. The function library is inherited from C, it is a set of C++ template classes to provides general-purpose empathized classes and functions that implement commonly used algorithms and data structures like vectors, lists, and stacks.

Vectors are array which can be change in size; compared to arrays, vectors consume more memory in exchange for the ability to manage storage and grow dynamically in an efficient way.

Containers : Containers are used to manage collections of objects of a certain kind. We Use <vector> in our syllabus.

Algorithms : Algorithms act on containers. They provide the means by which you will perform initialization, sorting, searching, and transforming of the contents of containers.

Iterators : Iterators are used to step through or move pointer in a container.

  • The push_back( ) member function inserts value at the end of the vector, expanding its size as needed.
  • The size( ) function displays the size of the vector.
  • The function begin( ) returns an iterator to the start of the vector.
  • The function end( ) returns an iterator to the end of the vector.
  • The function empty() returns whether the vector is empty (i.e. whether its size is 0).

A NORMAL PROGRAM IS HERE TO GET INPUT IN A VECTOR, DISPLAY THAT VECTOR, INPUT VALUE AT PARTICULAR POSITION;

#include"conio.h"
#include"iostream"
#include"vector" //HEADER FILE FOR VECTOR
using namespace std;
int main()
{
    vector <int> v;  //DECLARING VECTOR
    int i,n,l,num;
    cout<<"\nENTER TOTAL NUMBER OF ELEMENT : ";
    cin>>n;
    for(i=0;i<n;i++)
    {
        cout<<"\nEnter Value : ";
        cin>>num;
        v.push_back(num); //USING push_back FUNCTION TO PUT NO. IN VECTOR
    }
    cout<<"\n_______VALUES ARE________"<<endl;
    for(i=0;i<n;i++)
    {
        cout<<"\nValue at "<<i+1<<" is "<<v[i]<<endl; 
    }
    cout<<"\nEnter Value To Insert At Last Position : ";
    cin>>num;
    v.push_back(num);
    for(i=0;i<v.size();i++)
    {
        cout<<"\nValue at "<<i+1<<" is "<<v[i]<<endl;
    }
    cout<<endl;
    vector <int> :: iterator ie=v.begin(); //DEFINING iterator TO STARTING OF VECTOR USING <vector>.begin() function
    cout<<"\nEnter Steps You Want To Move Down : ";
    cin>>l;
    ie=ie+l; //SETTING VALUE TO STEP THROUGH
    cout<<"\nEnter Value to Insert at "<<l<<" Steps Down : ";
    cin>>num;
    v.insert(ie,num); INSERTING VALUE AT DEFINED POSITION USING <vector>.insert();
    cout<<endl;
    for(i=0;i<v.size();i++)
    {
        cout<<"\nValue at "<<i+1<<" is "<<v[i]<<endl;
    }
    cout<<"\n\nPROGRAMMING @ C#ODE STUDIO ";
    getch();
}

vector

COPY A FILE INTO ANOTHER ;

/*We can read a file and can put same data into another file
but keep the statement in mind that “A file can’t be deleted by a normal program. We can only change its name
that it looks like file has been deleted” so the program follows by : */

Ques – MAKE A CLASS STUDENT WITH DATA MEMBER NAME, ROLL, REG AND CGPA. TAKE INPUT FROM USER. WRITE DATA INTO A FILE AND COPY THE SAME FILE INTO ANOTHER FILE. CHECK IF DESTINATION FILE DOESN’T EXISTS, SUGGEST USER TO CREATE ONE.

#include<iostream>
#include<conio.h>
#include<fstream>
using namespace std;
class student
{
      char Name[20];
      int Regno;
      int Rollno;
      float CGP;
      public:
             void enter()
             {
                  cout<<"\n____Enter the details as follow:-____"<<endl;
                  cout<<"Name of student:";
                  cin>>Name;
                  cout<<"Enter the Reg. No.:";
                  cin>>Regno;
                  cout<<"Enter the Roll no:";
                  cin>>Rollno;
                  cout<<"Enter the CGP:";
                  cin>>CGP;
                  }
                  void display()
                  {
                       cout<<"NAME: "<<Name<<endl;
                       cout<<"REGISTRATION NUMBER: "<<Regno<<endl;
                       cout<<"ROLL NUMBER: "<<Rollno<<endl;
                       cout<<"CGP: "<<CGP<<endl;
                  }
};
void write()
{
          cout<<"\n\n______ UPDATE DATA ______\n\n";
          char fname[10];
          cout<<"\nENTER FILE NAME WITH EXTENSION : ";
          cin>>fname;
          student obj;
          ofstream fp2(fname,ios::app);
          //fp2.open(fname,ios::app);
          if(fp2==NULL)
          {
              cout<<"\nFILE DOESN'T EXISTS : NEW FILE CREATED "<<endl;
          }
          obj.enter();
          fp2.write((char*)&obj,sizeof(obj));
          fp2.close();
}
void out()
{
            cout<<"\n\n______ READING DATA ______\n\n";
            char fname[10];
          cout<<"\nENTER FILE NAME WITH EXTENSION : ";
          cin>>fname;
          student obj;
          ifstream fp1;
          fp1.open(fname,ios::out);
          if(fp1==NULL)
          {
              cout<<"\nFILE DOESN'T EXISTS :"<<endl;
          }
          else
          {
              while(fp1.read((char*)&obj,sizeof(obj)))
              {
                  cout<<endl;
                obj.display();
              }
          }
          fp1.close();
}
void copy()
{
          student obj;
          char fname[10],tname[10];
          ifstream fp3;
          ofstream fp4;
          cout<<"\n\n______ COPYING FILE ______\n\n";
          cout<<"\nENTER DESTINATION FILE WITH EXTENSION : ";
          cin>>fname;
          fp3.open(fname,ios::out);
          cout<<"\nENTER TARGET FILE WITH EXTENSION : ";
          cin>>tname;
          fp4.open(tname,ios::app);
          if(fp3==NULL)
          {
              cout<<"\nDESTINATION FILE DOESN'T EXISTS :"<<endl;
          }
          else
          {
              while(fp3.read((char*)&obj,sizeof(obj)))
              {
                  cout<<endl;
                  cout<<"\n______ WRITING DATA _______"<<endl;
                obj.display();
                fp4.write((char*)&obj,sizeof(obj));
              }
          }
          fp3.close();
          fp4.close();
          cout<<"\n\n______ FILE COPIED______\n\n";
}
int main()
{
    int a;
    line:
    cout<<"\n1:UPDATING DATA, 2:READ DATA, 3:COPY FILE 4:EXIT PROGRAM : ";
    cin>>a;
    switch(a)
    {
        case 1: write();
                goto line;
        case 2: out();
                goto line;
          case 3: copy();
                goto line;
          case 4: cout<<"\n\nEXITING PROGRAM .......";
                  break;
          default:
                  cout<<"\nWRONG CHOICE... MAKE CHOICE AGAIN \n";
                  goto line;
    }
    cout<<"\n\nPROGRAMMING @ C#ODE STUDIO ";
    getch();
    return 0;
}

TARGET FILE-

file_copy2

 

DESTINATION FILE-

file_copy

OUTPUT –file_copy1

DELETE FILE;

/* We can ask user which file he/she want to open. the program defines it below */
Que -Make a class student with data member name,reg,roll and cgpa and with member function enter_data and display;
get input from user as many time he wants and write data into file in one function, also read data file in another function. Make a function in which you can delete particular file:

As we know a file cant be deleted by a delete function it can be renamed to another file  ;

#include<iostream>
#include<conio.h>
#include<fstream>
using namespace std;
class student
{
      char Name[20];
      int Regno;
      int Rollno;
      float CGP;
      public:
             void enter()
             {
                  cout<<"\n____Enter the details as follow:-____"<<endl;
                  cout<<"Name of student:";
                  cin>>Name;
                  cout<<"Enter the Reg. No.:";
                  cin>>Regno;
                  cout<<"Enter the Roll no:";
                  cin>>Rollno;
                  cout<<"Enter the CGP:";
                  cin>>CGP;
                  }
                  void display()
                  {
                       cout<<"NAME: "<<Name<<endl;
                       cout<<"REGISTRATION NUMBER: "<<Regno<<endl;
                       cout<<"ROLL NUMBER: "<<Rollno<<endl;
                       cout<<"CGP: "<<CGP<<endl;
                  }
};
void write()
{
          cout<<"\n\n______ UPDATE DATA ______\n\n";
          char fname[10];
          cout<<"\nENTER FILE NAME WITH EXTENSION : ";
          cin>>fname; //take file name from user
          student obj;
          ofstream fp2(fname,ios::app); //put string as file name;
          if(fp2==NULL)
          {
              cout<<"\nFILE DOESN'T EXISTS : NEW FILE CREATED "<<endl;
          }
          obj.enter();
          fp2.write((char*)&obj,sizeof(obj));
          fp2.close();
}
void out()
{
            cout<<"\n\n______ READING DATA ______\n\n";
            char fname[10];
          cout<<"\nENTER FILE NAME WITH EXTENSION : ";
          cin>>fname;
          student obj;
          ifstream fp1(fname,ios::out);
          //fp1.open(fname,ios::out);
          if(fp1==NULL)
          {
              cout<<"\nFILE DOESN'T EXISTS :"<<endl;
          }
          else
          {
              while(fp1.read((char*)&obj,sizeof(obj)))
              {
                  cout<<endl;
                obj.display();
              }
          }
          fp1.close();
}
void del()
{
          cout<<"\n\n______ DELETING FILE ______\n\n";
          char fname[10];
          cout<<"\nENTER FILE NAME WITH EXTENSION : ";
          cin>>fname;
          rename(fname,"temp.txt");
          cout<<"\n\n______ FILE DELETED______\n\n";
}
int main()
{
    int a;
    line:
    cout<<"\n1:UPDATING DATA, 2:READ DATA, 3:DELETE FILE 4:EXIT PROGRAM : "<<endl;
    cin>>a;
    switch(a)
    {
        case 1: write();
                goto line;
        case 2: out();
                goto line;
          case 3: del();
                goto line;
          case 4: cout<<"\n\nEXITING PROGRAM .......";
                  break;
          default:
                  cout<<"\nWRONG CHOICE... MAKE CHOICE AGAIN \n";
                  goto line;
    }
    cout<<"\n\nPROGRAMMING @ C#ODE STUDIO ";
    getch();
    return 0;
}

file_user1

file_user2

file_user