Friday, August 16, 2019

Count number of lines, words, characters from a file in C++

Here is a sample program that wrote using C++ as my programming language to count the number of lines, words, a character from a file.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.

Here in Bacolod I also accepting computer repair, networking and Arduino Project development at a very affordable price.

My personal website is http://www.jakerpomperada.com


Sample Program Output


Program Listing

#include <iostream>
#include <fstream>

using namespace std;

int main() {

   ifstream f1;
   char c;
   int numchars, numlines;

   f1.open("test.txt");

   numchars = 0;
   numlines = 0;
   system("COLOR F0");
   cout <<"\n\n";
   cout <<"\tCount number of lines, words, characters from a file";
   cout <<"\n\n";
   f1.get(c);
   while (f1) {
     while (f1 && c != '\n') {
       numchars = numchars + 1;
       f1.get(c);
     }
     numlines = numlines + 1;
     f1.get(c);
   }
   cout << "\tThe file has " << numlines << " lines and " 
     << numchars << " characters.";
   cout <<"\n\n"; 
   cout <<"\tEnd of Program";
   cout <<"\n\n";  
   system("pause");
   
}




Search a Name in the Text File in C++

Design a program using a text file that will allow the user to search a name of the person stored in a text file. If the name of the person found in the text file that program will inform the user that the name of the person is found. On the other hand, if the name of the person cannot be found in the text file, the program will inform the user that the name is not found.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.

Here in Bacolod I also accepting computer repair, networking and Arduino Project development at a very affordable price.

My personal website is http://www.jakerpomperada.com






Sample Program Output


Program Listing

// search.cpp
// Author   : Mr. Jake R. Pomperada,BSCS,MAED-IT
// Address  : Bacolod City, Negros Occidental Philippines
// Date     : September 6, 2018      Thursday   8:75 AM
// Website  : jakerpomperada.com
// Email    : jakerpomperada@jakerpomperada.com and jakerpomperada@aol.com
// Tool     : Dev C++ Version 5.11

#include <iostream>
#include <fstream>

using namespace std;

int search (char a[]) 
{
char *search = a ; 
int offset;
string line;
ifstream Myfile;
Myfile.open("demo.txt");
if(Myfile.is_open())
{
while(!Myfile.eof())
{
getline(Myfile,line);
if ((offset = line.find(search,0)) != string::npos) 
   {
 cout <<"\n\n";            
 cout << "\tThe name "<< search <<" is FOUND in the text file.";
 cout <<"\n\n";
 goto terminate;
  } 
}
cout <<"\n\n";    
cout << "\tThe name "<< search <<" is NOT FOUND in the text file.";
cout <<"\n\n";
Myfile.close();
}
else 
cout<<"Unable to open this file."<<endl;
terminate:
cout <<"\n";    
cout << "\tThank you for Using This Software.";
cout <<"\n\n";          
system("pause");
}

int main()
{
    char name[100];
    system("COLOR F0");
    cout <<"\n\n";
    cout <<"\tSearch a Name in the Text File in C++";
    cout <<"\n\n";
    cout<<"\tEnter name to search : ";
    fflush(stdin);
    cin.getline(name,50);
    search(name);
}



STUDENT GRADING DATABASE SYSTEM IN C++

Create a Student Grading System using a text file which allows the user to add student record, view student record, edit student record, find student record, remove or delete student record in the text file
database.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.

Here in Bacolod I also accepting computer repair, networking and Arduino Project development at a very affordable price.

My personal website is http://www.jakerpomperada.com







Sample Program Output


Program Listing

/ student.cpp
// Written By Mr. Jake R. Pomperada, BSCS, MAED-IT
// July 26, 2018  Thursday
// Bacolod City, Negros Occidental Philippines
// Website : http://www.jakerpomperada.com
// Email Address : jakerpomperada@jakerpomperada.com and jakerpomperada@aol.com

#include <iostream>
#include <iomanip>
#include <cmath>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>

using namespace std;


int main( )
{
FILE *fp, *ft ;
char another, choice ;
struct student
{
char stud_id_no[300];
char name[300];
char course[300];
char subject[300];
float prelim,midterm,endterm,final_grade;
} ;
struct student grade;
char student_id[300];
long int recsize;
    int flag=0;
fp = fopen ("GRADE_DB.DAT", "rb+" ) ;
if ( fp == NULL )
{
fp = fopen ( "GRADE_DB.DAT", "wb+" ) ;
if ( fp == NULL )
{
puts ( "Cannot open file" ) ;
exit(0) ;
}
}
recsize = sizeof ( grade ) ;
while ( 1 )
{
        system("CLS");
        system("COLOR F0"); 
setprecision(0);
        cout <<"\n";
cout << "\n\t==========================================";
cout <<"\n";
cout <<"\n\t STUDENT GRADING DATABASE SYSTEM IN C++";
cout <<"\n\n";
cout << "\tCreated By Mr. Jake R. Pomperada,MAED-IT";
cout <<"\n\t==========================================";
cout <<"\n\n";
cout << "\t[1] INSERT STUDENT RECORD";
cout <<"\n";
cout << "\t[2] BROWSE STUDENT RECORD";
cout <<"\n";
cout << "\t[3] EDIT STUDENT RECORDS" ;
cout <<"\n";
cout  <<"\t[4] FIND STUDENT RECORDS";
cout <<"\n";
cout << "\t[5] REMOVE STUDENT RECORDS";
cout <<"\n";
cout  << "\t[6] QUIT PROGRAM" ;
cout <<"\n\n";
cout  <<"\tSELECT YOUR OPTION :=> ";
fflush (stdin) ;
choice = getche() ;
switch ( choice )
{
case '1' :
fseek ( fp, 0 , SEEK_END ) ;
another = 'Y' ;
while ( another == 'Y' )
{
system("cls");
cout <<"\n\n";
cout << "\t=== INSERT NEW STUDENT GRADE RECORD ===";
cout <<"\n\n";
cout <<"\tEnter Student ID Number : ";
                    cin >> grade.stud_id_no;
cout << "\tEnter Student Name: ";
fflush (stdin) ;
gets(grade.name);
cout <<"\tEnter Course : ";
fflush (stdin) ;
gets(grade.course);
                    cout <<"\tEnter Subject : ";
fflush (stdin) ;
gets(grade.subject);
cout <<"\tEnter Prelim Grade: ";
cin >> grade.prelim;
cout << "\tEnter Midtem Grade: ";
cin >> grade.midterm;
cout << "\tEnter Endterm Grade: ";
cin >> grade.endterm;
grade.final_grade = (grade.prelim * 0.30) + (grade.midterm * 0.30) + (grade.endterm * 0.40);
cout << "\n";
                    cout << "\n\tStudent Final Grade : "  << round(grade.final_grade);
fwrite (&grade, recsize, 1, fp ) ;
cout << "\n\n";
cout  << "\n\tAdd New Student Record (Y/N) : " ;
fflush (stdin) ;
another = toupper(getche()) ;
}
break ;
case '2' :
        system("cls");
rewind ( fp );
cout << "\n\n";
                cout <<"\t=== VIEW STUDENT GRADE RECORD ===";
                cout <<"\n\n";
while ( fread ( &grade, recsize, 1, fp ) == 1 )
        {
       cout <<"\n";
       cout <<"\n\t  ID Number        : " <<grade.stud_id_no;
       cout <<"\n\t  Name             : " <<grade.name;
       cout <<"\n\t  Course           : " <<grade.course;
       cout <<"\n\t  Subject          : " << grade.subject;
       cout <<"\n\t  Prelim Grade     : " <<grade.prelim;
       cout <<"\n\t  Midterm Grade    : " <<grade.midterm;
       cout <<"\n\t  Endterm Grade    : " <<grade.endterm;
       cout <<"\n";
       grade.final_grade = (grade.prelim * 0.30) + (grade.midterm * 0.30) + (grade.endterm * 0.40);
       cout <<"\n\t Student Final Grade : " <<round(grade.final_grade);
  }
          cout <<"\n\n";
         system("pause");
break ;
case '3' :
another = 'Y' ;
while ( another == 'Y' )
{
system("cls");
          cout <<"\t=== EDIT STUDENT GRADE RECORD ===";
        cout <<"\n\n";
          cout <<"\tEnter Student ID Number : ";
                cin >> student_id;
    rewind ( fp ) ;
cout <<"\n";
while ( fread ( &grade, recsize, 1, fp ) == 1 )
{
if ( strcmp ( grade.stud_id_no, student_id) == 0 )
{
cout <<"\tEnter Student ID Number : ";
                            fflush (stdin) ;
                            gets(grade.stud_id_no);
cout <<"\tEnter Student Name : ";
fflush ( stdin ) ;
gets(grade.name);
        cout <<"\tEnter Course: ";
fflush ( stdin ) ;
gets(grade.course);
cout <<"\tEnter Subject : ";
fflush ( stdin ) ;
gets(grade.subject);
cout <<"\tEnter Prelim Grade : ";
cin >> grade.prelim;
cout <<"\tEnter Midtem Grade : ";
cin >> grade.midterm;
cout <<"\tEnter Endterm Grade: ";
cin >> grade.endterm;
cout <<"\n";
grade.final_grade = (grade.prelim * 0.20) + (grade.midterm * 0.30) + (grade.endterm * 0.50);
cout <<"\n\tStudent Final Grade : " << round(grade.final_grade);
fseek ( fp, - recsize, SEEK_CUR ) ;
fwrite ( &grade, recsize, 1, fp ) ;
break ;
}
}
if (strcmp(grade.stud_id_no,student_id) != 0 )
                 {  
                   cout <<"\n\n";
                   cout <<"\tNo Student Record in the Database.";
                   cout <<"\n";
                   system("pause");
                   break;
                   }
                 cout <<"\n\n";
     cout  <<"\n\tEdit Another Student Record (Y/N) : ";
fflush ( stdin ) ;
another = toupper(getche());
}
break ;
      case '4' :
   rewind ( fp ) ;
   another = 'Y' ;
while ( another == 'Y' )
{
system("cls");
        cout <<"\t=== Find Student Records ===";
        cout <<"\n\n";
     cout <<"\tEnter Student ID Number : ";
                 cin >>student_id;
cout <<"\n";
rewind ( fp ) ;
while ( fread ( &grade, recsize, 1, fp ) == 1 )
{
if ( strcmp (grade.stud_id_no,student_id) == 0 )
{
                    cout <<"\n";
cout <<"\n\tID Number      : " <<grade.stud_id_no;
cout <<"\n\tName           : " << grade.name;
cout <<"\n\tCourse         :  " <<grade.course;
            cout <<"\n\tSubject        : " <<grade.subject;
                    cout <<"\n\tPrelim Grade   :  " <<grade.prelim;
                   cout <<"\n\tMidterm Grade  :  " <<grade.midterm;
                   cout <<"\n\tEndterm Grade  : " << grade.endterm;
                   cout <<"\n";
       grade.final_grade = (grade.prelim * 0.30) + (grade.midterm * 0.30) + (grade.endterm * 0.40);
       cout <<"\n\tStudent Final Grade : " << round(grade.final_grade);
       cout <<"\n\n";
       system("pause");
       break;
}
}
      if (strcmp(grade.stud_id_no,student_id) != 0 )
          {
            cout <<"\n\n";
            cout <<"\tNo Student Record found in the Database.";
            cout <<"\n";
            system("pause");
            break;
           }
                    cout  <<"\n\n";
cout  <<"\n\tFind Another Student Record (Y/N) : " ;
fflush ( stdin ) ;
another = toupper(getche());
}
break ;
case '5' :
another = 'Y' ;
while ( another == 'Y' )
{
system("cls");
                    cout <<"\t=== REMOVE STUDENT GRADE RECORD ===";
                    cout <<"\n\n";
cout <<"\tEnter Student ID Number : ";
                    cin >> student_id;
cout <<"\n";
ft = fopen ( "TEMP.DAT", "wb" ) ;
rewind ( fp ) ;
while ( fread ( &grade, recsize, 1, fp ) == 1 )
{
if ( strcmp (grade.stud_id_no, student_id) != 0 )
fwrite ( &grade, recsize, 1, ft ) ;
                 else
                flag=1;
                  }
fclose ( fp ) ;
fclose ( ft ) ;
remove ( "GRADE_DB.DAT" ) ;
rename ( "TEMP.DAT", "GRADE_DB.DAT" ) ;
    fp = fopen ( "GRADE_DB.DAT", "rb+" ) ;
       if(flag==1) {
         cout <<"\n\n";
         cout <<"\tRecord Successfully Deleted From the Database.";
         cout <<"\n";
         system("pause");
         }
else if (flag!=1) {
             cout <<"\n\n";
             cout <<"\tRecord Not Found in the Database.";
             cout <<"\n";
            system("pause");
             }
                    cout <<"\n\n";
cout << "\tRemove Another Student Record (Y/N) : " ;
fflush (stdin) ;
another = toupper(getche());
}
break ;
case '6' :
fclose ( fp ) ;
cout <<"\n\n";
cout <<"\tEND OF PROGRAM";
cout <<"\n\n";
cout << "\tThank You Very Much For Using This Software.";
cout <<"\n\n";
system("PAUSE");
exit(0);
}
}
} // End of Code




Area of the Circle and Rectangle Solver

It this article I would like to share with you a sample program that will compute the area of the circle and rectangle using QBasic.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.

Here in Bacolod I also accepting computer repair, networking and Arduino Project development at a very affordable price.

My personal website is http://www.jakerpomperada.com



Sample Program Output


Program Listing

CLS
PRINT
PRINT "Area of Circle and Rectangle Solver"
PRINT
INPUT "ENTER THE RADIUS   : "; R
INPUT "ENTER THE LENGTH  : "; L
INPUT "ENTER THE BREADTH : "; B
AOC = (22 / 7) * R ^ 2
AOR = L * B
PRINT
PRINT "THE AREA OF CIRCLE ="; AOC
PRINT "AREA OF THE RECTANGLE="; AOR
PRINT
PRINT "End of Program"
END