#include <bits/stdc++.h> #include <ctime> #include <cstring> #include <string> #include <vector> #include <fstream> #include <ctype.h> #include <iomanip> #include <stdio.h> #include <iostream> #include <stdlib.h> #include <string.h> using namespace std; char seriesf[20] = "series.txt"; char tempf[20] = "temp.txt"; struct cont { char s_name[20], s_lang[20], s_ses[20], s_epi[20], s_status[2]; }; class series { public: void s_pack(cont r); cont s_unpack(char a[]); void s_writedata(); void s_display(); void s_search(); void s_modify(); void s_modify_status(); void s_modify_all(); void s_del(); }; void intro(); void fordelay(int n); void series ::s_pack(cont r) { fstream fp; fp.open(seriesf, ios::out | ios::app); if (!fp) { cout << "\n\t FILE NOT FOUND ! ! ! "; exit(0); } char buff[45]; strcpy(buff, r.s_name); strcat(buff, "|"); strcat(buff, r.s_lang); strcat(buff, "|"); strcat(buff, r.s_ses); strcat(buff, "|"); strcat(buff, r.s_epi); strcat(buff, "|"); strcat(buff, r.s_status); strcat(buff, "|"); for (int i = 0; i < 45 - strlen(buff); i++) strcat(buff, "|"); fp << buff << endl; fp.close(); } cont series::s_unpack(char buff[]) { cont r; int i = 0, j = 0; while (buff[j] != '|') r.s_name[i++] = buff[j++]; r.s_name[i] = '\0'; i = 0; j++; while (buff[j] != '|') r.s_lang[i++] = buff[j++]; r.s_lang[i] = '\0'; i = 0; j++; while (buff[j] != '|') r.s_ses[i++] = buff[j++]; r.s_ses[i] = '\0'; i = 0; j++; while (buff[j] != '|') r.s_epi[i++] = buff[j++]; r.s_epi[i] = '\0'; i = 0; j++; while (buff[j] != '|') r.s_status[i++] = buff[j++]; r.s_status[i] = '\0'; return (r); } void series::s_writedata() { cout << "\n\n\t ADD Series option \n"; cout << "________________________________________________________"; cont r; cout << "\n\n\t\t ENTER SERIES NAME : "; fflush(stdin); gets(r.s_name); cout << "\n\n\t\t ENTER SERIES LANGAUGE : "; fflush(stdin); gets(r.s_lang); cout << "\n\n\t\t ENTER SERIES SEASON NO. : "; cin >> r.s_ses; cout << "\n\n\t\t ENTER SERIES EPISODE NO. : "; cin >> r.s_epi; cout << "\n\n\t\t ENTER STATUES OF SERIES (Y/N/W): "; cin >> r.s_status; s_pack(r); cout << "\n\t * * * SERIES ADDED SUCESSFULLY * * *" << endl; } void series::s_display() { fstream fp; char buff[45]; cont r; cout << "\n\n\t DISPLAY Series option \n"; cout << "________________________________________________________ \n"; fp.open(seriesf, ios::in); if (!fp) { cout << "\n\t FILE NOT FOUND ! ! ! "; return; } cout << "\n------------------------------------------------------------------------------------------------------------------------\n" << endl; cout << "\tSr No.\t\tNAME\t\t\tLANGAUGE\tSEASON NO.\tEPISODE NO.\tSTATUS(Y/N/W)" << endl; cout << "------------------------------------------------------------------------------------------------------------------------\n" << endl; int c = 1; while (1) { fp.getline(buff, 45); if (fp.eof()) break; r = s_unpack(buff); cout << "\t|" << c++ << "\t\t|" << r.s_name << "\t\t|" << r.s_lang << "\t|" << r.s_ses << " S\t\t|" << r.s_epi << " E\t\t|" << r.s_status << endl; } fp.close(); return; } void series ::s_modify_all() { fstream fp; char s_name[15], buff[45]; int i, j; cont s[100]; cout << "\n\n\t MODIFY ALL SERIES OPTION \n"; cout << "________________________________________________________"; fp.open(seriesf, ios::in); if (!fp) { cout << "\n\t FILE NOT FOUND ! ! ! "; return; } cout << "\n\n\t Enter series name to be updated : "; fflush(stdin); gets(s_name); i = 0; while (1) { fp.getline(buff, 45); if (fp.eof()) break; s[i] = s_unpack(buff); i++; } for (j = 0; j < i; j++) { if (strcmp(s[j].s_name, s_name) == 0) { cout << "\n\n\t Your series Details are:\n"; cout << "\n\n\t\t Name : " << s[j].s_name; cout << "\n\n\t\t langauge : " << s[j].s_lang; cout << "\n\n\t\t No.of Seasons: " << s[j].s_ses; cout << "\n\n\t\t No.of episodes: " << s[j].s_epi; cout << "\n\n\t\t Status : " << s[j].s_status; cout << "\n\n\t\t----- ENTER VALUES TO CHANGE THE STATUS ----- "; cout << "\n\n\t\t Name to update : "; fflush(stdin); gets(s[j].s_name); cout << "\n\n\t\t langauge to update : "; fflush(stdin); gets(s[j].s_lang); cout << "\n\n\t\t No.of Season to update : "; cin >> s[j].s_epi; cout << "\n\n\t\t No.of episodes to update : "; cin >> s[j].s_ses; cout << "\n\n\t\t Status to update (Y/N/W) : "; cin >> s[j].s_status; system("cls"); cout << "\n\n\t \n\t * * * SERIES UPDATED SUCESSFULLY * * *\n"; cout << "\n\n\t\t Name : " << s[j].s_name; cout << "\n\n\t\t nlangauge : " << s[j].s_lang; cout << "\n\n\t\t No.of Season : " << s[j].s_ses; cout << "\n\n\t\t No.of episodes : " << s[j].s_epi; cout << "\n\n\t\t Status: " << s[j].s_status; break; } } if (j == i) { cout << "\n\t ! ! ! RECORD NOT FOUND ! ! ! "; return; } fp.close(); fstream fd; fd.open(seriesf, ios::out | ios::trunc); if (!fd) { cout << "\n\t FILE NOT FOUND ! ! ! "; return; } for (j = 0; j < i; j++) s_pack(s[j]); fd.close(); } void series ::s_modify_status() { fstream fp; char s_name[15], buff[45]; int i, j; cont s[100]; cout << "\n\n\t MODIFY SERIES STATUS OPTION \n"; cout << "________________________________________________________"; fp.open(seriesf, ios::in); if (!fp) { cout << "\n\t FILE NOT FOUND ! ! ! "; return; } cout << "\n\n\t Enter series name to be updated : "; fflush(stdin); gets(s_name); i = 0; while (1) { fp.getline(buff, 45); if (fp.eof()) break; s[i] = s_unpack(buff); i++; } for (j = 0; j < i; j++) { if (strcmp(s[j].s_name, s_name) == 0) { cout << "\n\n\t Your series Details are:\n"; cout << "\n\n\t\t Name : " << s[j].s_name; cout << "\n\n\t\t langauge : " << s[j].s_lang; cout << "\n\n\t\t No.of Seasons: " << s[j].s_ses; cout << "\n\n\t\t No.of episodes: " << s[j].s_epi; cout << "\n\n\t\t Status : " << s[j].s_status; cout << "\n\n\t\t----- ENTER VALUES TO CHANGE THE STATUS ----- "; cout << "\n\n\t\t Status to update (Y/N/W) : "; cin >> s[j].s_status; system("cls"); cout << "\n\n\t \n\t * * * SERIES STATUS UPDATED SUCESSFULLY * * *\n"; cout << "\n\n\t\t Name : " << s[j].s_name; cout << "\n\n\t\t nlangauge : " << s[j].s_lang; cout << "\n\n\t\t No.of Season : " << s[j].s_ses; cout << "\n\n\t\t No.of episodes : " << s[j].s_epi; cout << "\n\n\t\t Status: " << s[j].s_status; break; } } if (j == i) { cout << "\n\t ! ! ! RECORD NOT FOUND ! ! ! "; return; } fp.close(); fstream fd; fd.open(seriesf, ios::out | ios::trunc); if (!fd) { cout << "\n\t FILE NOT FOUND ! ! ! "; return; } for (j = 0; j < i; j++) s_pack(s[j]); fd.close(); } void series ::s_modify() { fstream fp; char s_name[15], buff[45]; int i, j; cont s[100]; cout << "\n\n\t MODIFY SERIES SEASONS AND EPISOD OPTION \n"; cout << "________________________________________________________"; fp.open(seriesf, ios::in); if (!fp) { cout << "\n\t FILE NOT FOUND ! ! ! "; return; } cout << "\n\n\t Enter series name to be updated : "; fflush(stdin); gets(s_name); i = 0; while (1) { fp.getline(buff, 45); if (fp.eof()) break; s[i] = s_unpack(buff); i++; } for (j = 0; j < i; j++) { if (strcmp(s[j].s_name, s_name) == 0) { cout << "\n\n\t Your series Details are:\n"; cout << "\n\n\t\t Name : " << s[j].s_name; cout << "\n\n\t\t langauge : " << s[j].s_lang; cout << "\n\n\t\t No.of Seasons: " << s[j].s_ses; cout << "\n\n\t\t No.of episodes: " << s[j].s_epi; cout << "\n\n\t\t Status : " << s[j].s_status; cout << "\n\n\t\t----- ENTER VALUES TO CHANGE SEASON AND EPISODS ----- "; cout << "\n\n\t\t No.of Season to update : "; cin >> s[j].s_epi; cout << "\n\n\t\t No.of episodes to update : "; cin >> s[j].s_ses; system("cls"); cout << "\n\n\t \n\t * * * SERIES STATUS UPDATED SUCESSFULLY * * *\n"; cout << "\n\n\t\t Name : " << s[j].s_name; cout << "\n\n\t\t nlangauge : " << s[j].s_lang; cout << "\n\n\t\t No.of Season : " << s[j].s_ses; cout << "\n\n\t\t No.of episodes : " << s[j].s_epi; cout << "\n\n\t\t Status: " << s[j].s_status; break; } } if (j == i) { cout << "\n\t ! ! ! RECORD NOT FOUND ! ! ! "; return; } fp.close(); fstream fd; fd.open(seriesf, ios::out | ios::trunc); if (!fd) { cout << "\n\t FILE NOT FOUND ! ! ! "; return; } for (j = 0; j < i; j++) s_pack(s[j]); fd.close(); } void series::s_search() { fstream fp; char s_name[15], buff[45]; int i, j; cont s; cout << "\n\n\t SEARCH Series option \n"; cout << "________________________________________________________"; fp.open(seriesf, ios::in); if (!fp) { cout << "\n\t FILE NOT FOUND ! ! ! "; return; } cout << "\n\n\t ENTER THE NAME OF SERIES TO BE SEARCHED : "; fflush(stdin); gets(s_name); i = 0; while (1) { fp.getline(buff, 45); if (fp.eof()) break; s = s_unpack(buff); if (strcmp(s.s_name, s_name) == 0) { cout << "\n\n\t\t * * * SERIES FOUND * * *\n"; cout << "\n\n\t\t NAME: " << s.s_name; cout << "\n\n\t\t LANGAUGE : " << s.s_lang; cout << "\n\n\t\t NO. OF SEASONS : " << s.s_ses; cout << "\n\n\t\t NO. OF EPISODES: " << s.s_epi; cout << "\n\n\t\t STATUS: " << s.s_status; return; } } cout << "\n\t ! ! ! SERIES NOT FOUND ! ! !"; return; } void series::s_del() { fstream fp; fstream temp; char dname[20]; int w = 0; int t = 0; int position; string line; cout << "\n\n\t DELETE Series option \n"; cout << "________________________________________________________"; fp.open(seriesf, ios::in); if (!fp) { cout << "\n\t FILE NOT FOUND ! ! ! "; return; } temp.open(tempf, ios::out | ios::app); cout << "\n\n\t ENTER THE SERIES NAME : "; fflush(stdin); gets(dname); while (getline(fp, line)) { position = line.find(dname); if (position != 0) { temp << line << endl; } } fp.close(); temp.close(); fp.open(seriesf, ios::in); while (getline(fp, line)) { w++; } w--; temp.open(tempf, ios::in); while (getline(temp, line)) { t++; } t--; if (w == t) { cout << "\n\t ! ! ! SERIES NOT FOUND ! ! !" << endl; } else { cout << "\n\t * * * SERIES DELETED SUCCESSFULLY * * *" << endl; } fp.close(); temp.close(); remove(seriesf); rename(tempf, seriesf); } int main() { char ch, ch1; int num; system("cls"); intro(); char pass[10]; char c; string s, name; series obj; int i = 0; cout << "\n\n\t\tFor Security Purpose:"; cout << "\n\n\t\tEnter the Login username:"; cin >> name; cout << "\n\n\t\tEnter the password to login:"; while (1) { c = getch(); printf("*"); s += c; if (c == '\r') { break; } } s = s.substr(0, s.size() - 1); cout << endl; if (s == "shetty" && (name == "raksha")) { printf("\n\nAccess Granted * * *\nLOADING"); for (i = 0; i <= 6; i++) { fordelay(100000000); printf("."); } system("cls"); do { system("cls"); time_t now = time(0); char *dt = ctime(&now); cout << " Date and Time is: " << dt << endl; cout << "________________________________________________________"; cout << "\n\n\t MAIN MENU \n"; cout << "________________________________________________________"; cout << "\n\n\t01. ADD NEW series"; cout << "\n\n\t02. UPDATE SERIES"; cout << "\n\n\t03. DELETE SERIES"; cout << "\n\n\t04. SERCH SPESIFIC SERIES"; cout << "\n\n\t05. ALL SERIES NAME LIST"; cout << "\n\n\t06. EXIT \n"; cout << "________________________________________________________"; cout << "\n\n\tSelect Your Option (1-6) "; cin >> ch; system("cls"); switch (ch) { case '1': obj.s_writedata(); break; case '2': um: system("cls"); cout << "________________________________________________________"; cout << "\n\n\t UPDATE MENU \n"; cout << "________________________________________________________"; cout << "\n\n\t01. UPDATE STATUES"; cout << "\n\n\t02. UPDATE SEASONS AND EPISODS"; cout << "\n\n\t03. UPDATE ALL"; cout << "\n\n\t04. EXIT \n"; cout << "________________________________________________________"; cout << "\n\n\tSelect Your Option (1-4) "; cin >> ch1; system("cls"); switch (ch1) { case '1': obj.s_modify_status(); break; case '2': obj.s_modify(); goto um; break; case '3': obj.s_modify_all(); goto um; break; case '4': cout << "\n\n\t EXITING UPDATE MENU!!!!"; break; } getch(); break; case '3': obj.s_del(); break; case '4': obj.s_search(); break; case '5': obj.s_display(); break; case '6': cout << "\n\n\tEnjoy watching series BYE!!!!"; break; default: cout << "\a"; } getch(); } while (ch != '6'); return 0; } else { printf("\n\nWrong password or username!!"); } } void fordelay(int j) { int i, k; for (i = 0; i < j; i++) k = i; } //*************************************************************** // INTRODUCTION FUNCTION //**************************************************************** void intro() { time_t now = time(0); char *dt = ctime(&now); cout << " Date and Time is: " << dt << endl; cout << "\n\n\n\t SERIES"; cout << " MANAGEMENT"; cout << " SYSTEM"; cout << "\n\n\n\n PROJECT BY :"; cout << "\n\t RAKSHA SHETTY"; getch(); } //*************************************************************** // END OF PROJECT //***************************************************************
Write, Run & Share C++ code online using OneCompiler's C++ online compiler for free. It's one of the robust, feature-rich online compilers for C++ language, running on the latest version 17. Getting started with the OneCompiler's C++ compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as C++
and start coding!
OneCompiler's C++ online compiler supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample program which takes name as input and print your name with hello.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
cout << "Enter name:";
getline (cin, name);
cout << "Hello " << name;
return 0;
}
C++ is a widely used middle-level programming language.
When ever you want to perform a set of operations based on a condition If-Else is used.
if(conditional-expression) {
//code
}
else {
//code
}
You can also use if-else for nested Ifs and If-Else-If ladder when multiple conditions are to be performed on a single variable.
Switch is an alternative to If-Else-If ladder.
switch(conditional-expression){
case value1:
// code
break; // optional
case value2:
// code
break; // optional
......
default:
code to be executed when all the above cases are not matched;
}
For loop is used to iterate a set of statements based on a condition.
for(Initialization; Condition; Increment/decrement){
//code
}
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while (condition) {
// code
}
Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.
do {
// code
} while (condition);
Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increases re-usuability and modularity. Function gets run only when it is called.
return_type function_name(parameters);
function_name (parameters)
return_type function_name(parameters) {
// code
}