Posts

Showing posts with the label Create File

In Cpp, Write Student Details To File And Read It Back

Image
Download

Write Algorithm To Update Score In Flat File.

Problem Statement: A file exists on the disk named students.dat. The file contains several records, and each record contains two fields: (1) the student’s name, and (2) the student’s score for the final exam. Design an algorithm that changes Julie Milan’s score to 100. Solution: Start Declare InFile As File Declare OutFile As File Declare Name As String Declare Score As Integer Set InFile = "students.dat" Set OutFile = "students.tmp" For Each Line From InFile Read Next Line Split Line by <Tab> Set Name = Line[0] Set Score = Line[1] If "Julie Milan" = Name Then Set Score = 100 End If Set Line = Name + "<Tab>" + Score Write Line Into OutFile End For Close InFile Close OutFile Delete InFile Rename OutFile to InFile Exit

In C, Merge Sorted Data Files Into Single Output Data File

Image
/** * your name, * the course number, * the date the program was completed, * a brief description of theprogram. */ #include<stdio.h> int merge(const char*, const char*, const char*); int main(){ int error = merge("Data1.txt","Data2.txt","Merged.txt"); if(error){ printf("Error: File merging failed\n"); } else { printf("Success: File merged\n"); } return error; } int merge(const char* n1, const char* n2, const char* n3){ FILE *in1 = fopen(n1, "r"); if(!in1){ printf("Error: Could not read file: %s\n", n1); return 1; } FILE *in2 = fopen(n2, "r"); if(!in2){ fclose(in1); printf("Error: Could not read file: %s\n", n2); return 2; } FILE *out = fopen(n3, "w"); if(!out){ fclose(in1); fclose(in2); printf("Error: Could not write file: %s\n", n3); return 3; } int num1, num2; //until end of file whi...

Append 100 random integers to binary file with C++/Cpp programming

Image
#include<iostream> #include<fstream> #include<cstdlib> #include<ctime> using namespace std; int main(){ ofstream out("Exercise13_13.dat", (ios::out | ios::binary | ios_base::app)); if(!out){ cerr << "Error: failed to open file!" << endl; return 1; } srand(time(0)); int num; int bytes = sizeof(int); const char *addr = reinterpret_cast<const char*>(&num); for(int i = 1; 100 >= i; i++){ num = rand() % 100; out.write(addr, bytes); } out.close(); return 0; } Download

⚡ Cpp Program 🔥 Artist album tracks #tecqmate

Image
#include<iostream> #include<fstream> #include<string> #include<iomanip> using namespace std; int main(){ ifstream in("namedalbuminfo.txt"); if(!in){ cerr << "Failed to load input file!" << endl; return 1; } ofstream out("namedtracklist.txt"); string line; int hours, mins, sum_hrs = 0, sum_mins = 0, count = 0, diff; getline(in, line); out << "Album title: " << line << endl; getline(in, line); out << "Artist: " << line << endl; cout << "Welcome to 's tracklist generator!" << endl; out << "Tracks:" << endl; out << "--------------------------------------------------" << endl; while(!in.eof()){ count ++; getline(in, line); in >> hours >> mins; in.ignore(); out << setfill('0') << setw(2) << count; out << " - " <...

✔ C Sharp Code ⚡ Find avg per student from .csv file 🔥

Image
using System; using System.IO; class Ex{ public static void Main(string[]args){ float avg; string line; string[]parts; using(StreamReader inf = new StreamReader("ex2.csv")){ using(StreamWriter outf = new StreamWriter("ex2-out.csv")){ while(null != (line = inf.ReadLine())){ parts = line.Split(','); avg = ((int.Parse(parts[1])+int.Parse(parts[2])+int.Parse(parts[3]))/3.0f); outf.WriteLine("{0},{1:0.00}",parts[0],avg); } } } } } Download

Tecq Mate | XML to HTML | Transform XML to HTML with XSLT | MSXSL

Image
Download code here .

C plus plus read and write plain text into file

Image
Download code here .

Notepad trick to create new file | Windows notepad

Image