Factorial program in C++ [call-by-reference]
Factorial program in C++ with call-by-reference
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#include<iostream> using namespace std; void Factorial(int, int *); int main() { int Mynum, fact=1; cout<<"Enter the Mynumber: "; cin>>Mynum; Factorial(Mynum, &fact); cout<<"\nFactorial = "<<fact; cout<<endl; return 0; } void Factorial(int n, int *f) { int i; for(i=n; i>=1; i--) *f = (*f)*i; } |
Output Enter the Number: 4 Factorial = 24
C++ Project download [Student Record Management System]
C++ Project download [Student Record Management System].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
#include <stdio.h> #include <string.h> #include <conio.h> #include <stdlib.h> #include <windows.h> struct student{ char ID[15]; char name[20]; char add[20]; char fathername[20]; int Section_Class; long unsigned int phone_no; }; struct student stu; ///This will set the forground color for printing in a console window. void SetColor(int ForgC) { WORD wColor; ///We will need this handle to get the current background attribute HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFO csbi; ///We use csbi for the wAttributes word. if(GetConsoleScreenBufferInfo(hStdOut, &csbi)) { ///Mask out all but the background attribute, and add in the forgournd color wColor = (csbi.wAttributes & 0xF0) + (ForgC & 0x0F); SetConsoleTextAttribute(hStdOut, wColor); } return; } void ClearConsoleToColors(int ForgC, int BackC) { WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F); ///Get the handle to the current output buffer... HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); ///This is used to reset the carat/cursor to the top left. COORD coord = {0, 0}; ///A return value... indicating how many chars were written /// not used but we need to capture this since it will be /// written anyway (passing NULL causes an access violation). DWORD count; ///This is a structure containing all of the console info /// it is used here to find the size of the console. CONSOLE_SCREEN_BUFFER_INFO csbi; ///Here we will set the current color SetConsoleTextAttribute(hStdOut, wColor); if(GetConsoleScreenBufferInfo(hStdOut, &csbi)) { ///This fills the buffer with a given character (in this case 32=space). FillConsoleOutputCharacter(hStdOut, (TCHAR) 32, csbi.dwSize.X * csbi.dwSize.Y, coord, &count); FillConsoleOutputAttribute(hStdOut, csbi.wAttributes, csbi.dwSize.X * csbi.dwSize.Y, coord, &count ); ///This will set our cursor position for the next print statement. SetConsoleCursorPosition(hStdOut, coord); } return; } void SetColorAndBackground(int ForgC, int BackC) { WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor); return; } COORD coord = {0,0}; ///set the cordinate to 0, 0 (top-left corner of window); void gotoxy(int x, int y){ coord.X = x; coord.Y = y; /// X and Y coordinates SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); } void drawRectangle(){ int i, j; gotoxy(0,0); printf("%c",201); for(i = 1; i < 78; i++){ gotoxy(i, 0); printf("%c",205); } gotoxy(78,0); printf("%c",187); for(i = 1; i < 25; i++){ gotoxy(78, i); if(i == 6){ printf("%c",185); }else{ printf("%c",186); } } gotoxy(78, 25); printf("%c",188); for(i = 77; i > 0; i--){ gotoxy(i,25); if(i == 35){ printf("%c",202); }else{ printf("%c",205); } } gotoxy(0,25); printf("%c",200); for(i = 24; i > 0; i--){ gotoxy(0,i); if(i == 6){ printf("%c",204); }else{ printf("%c",186); } } for(i = 1; i < 78; i++){ gotoxy(i,6); if(i == 35){ printf("%c",203); }else{ printf("%c",205); } } for(i = 7; i < 25; i++){ gotoxy(35,i); printf("%c",186); } } void clearWindow(){ int i,j; for(i = 37; i < 78; i++){ for(j = 7; j < 25; j++){ gotoxy(i,j);printf(" "); } } return; } void window(){ drawRectangle(); gotoxy(28,2); SetColor(35); printf("STUDENT RECORD SYSTEM"); gotoxy(20,3); printf("Tribhuvan University, Kathmandu, Nepal"); gotoxy(31,4); printf("Estd.: 2016 B.S."); gotoxy(25,24); SetColor(17); } void get_password(char* pass) { char temp_passP[25]; int i=0; while(1) { temp_passP[i]=getch(); if(temp_passP[i]==13){break;} else if(temp_passP[i]==8) { if(i!=0) { printf("\b \b"); i--; } else {printf("\a");} } else { printf("*"); *(pass+i) = temp_passP[i]; i++; } *(pass+i)='\0'; } } void use_pass_field(){ int x = 15, y = 16; int use; char pass[10]; SetColor(10); gotoxy(15,12);printf("The database is password protected."); gotoxy(15,13);printf(" Enter Valid username and password"); SetColor(17); gotoxy(20,x);printf("USERNAME:- "); gotoxy(20,y);printf("PASSWORD:- "); gotoxy(34,x);scanf("%d",use); gotoxy(34,y);get_password(pass); } void print_heading(const char st[]){ SetColorAndBackground(31,28); gotoxy(45,8);printf("SRS : %s",st); SetColorAndBackground(17,15); } int conf_record(char id[]){ // left for you //it checks whether the entered id for //new record is already in the database. } void add_student(){ clearWindow(); print_heading("Add Record"); int print = 37; FILE *fp; fp = fopen("record.txt","ab+"); SetColor(45); if(fp == NULL){ MessageBox(0,"Error in Opening file\nMake sure your file is not write protected","Warning",0); }else{ fflush(stdin); gotoxy(print,10);printf("ID: ");gets(stu.ID); //here you can confirms the ID gotoxy(print,12);printf("Name: ");gets(stu.name); gotoxy(print,14);printf("Address: ");gets(stu.add); gotoxy(print,16);printf("Parent's name: ");gets(stu.fathername); gotoxy(print,18);printf("Section_Class: ");scanf("%d",&stu.Section_Class); gotoxy(print,20);printf("Phone Number: ");scanf("%ld",&stu.phone_no); fwrite(&stu, sizeof(stu), 1, fp); gotoxy(40,22); printf("The record is sucessfully added"); } SetColor(28); fclose(fp); return; } void search_student(){ clearWindow(); print_heading("Search Record"); SetColor(45); char s_id[15]; int isFound = 0; gotoxy(37,10);printf("Enter ID to Search: ");fflush(stdin); gets(s_id); FILE *fp; fp = fopen("record.txt","rb"); while(fread(&stu,sizeof(stu),1,fp) == 1){ if(strcmp(s_id,stu.ID) == 0){ isFound = 1; break; } } if(isFound == 1){ gotoxy(37,12);printf("The record is Found"); gotoxy(37,14);printf("ID: %s",stu.ID); gotoxy(37,15);printf("Name: %s",stu.name); gotoxy(37,16);printf("Address: %s",stu.add); gotoxy(37,17);printf("Parent's Name: %s",stu.fathername); gotoxy(37,18);printf("Section_Class: %d",stu.Section_Class); gotoxy(37,19);printf("Phone No: %ld",stu.phone_no); }else{ gotoxy(37,12);printf("Sory, No record found in the database"); } SetColor(28); fclose(fp); return; } void mod_student(){ clearWindow(); print_heading("Modify Record"); SetColor(45); char s_id[15]; int isFound = 0, print = 37; gotoxy(37,10);printf("Enter ID to Modify: ");fflush(stdin); gets(s_id); FILE *fp; fp = fopen("record.txt","rb+"); while(fread(&stu, sizeof(stu),1,fp) == 1){ if(strcmp(s_id, stu.ID) == 0){ fflush(stdin); gotoxy(print,12);printf("ID: ");gets(stu.ID); gotoxy(print,13);printf("Name: ");gets(stu.name); gotoxy(print,14);printf("Address: ");gets(stu.add); gotoxy(print,15);printf("Parent's name: ");gets(stu.fathername); gotoxy(print,16);printf("Section_Class: ");scanf("%d",&stu.Section_Class); gotoxy(print,17);printf("Phone Number: ");scanf("%ld",&stu.phone_no); fseek(fp,-sizeof(stu), SEEK_CUR); fwrite(&stu,sizeof(stu), 1, fp); isFound = 1; break; } } if(!isFound){ gotoxy(print, 12);printf("No Record Found"); } fclose(fp); SetColor(28); return; } void gen_marksheet(){ //left for further enhancement } void delete_student(){ clearWindow(); print_heading("Delete Record"); SetColor(45); char s_id[15]; int isFound = 0, print = 37; gotoxy(37,10);printf("Enter ID to Modify: ");fflush(stdin); gets(s_id); FILE *fp, *temp; fp = fopen("record.txt","rb"); temp = fopen("temp.txt", "wb"); while(fread(&stu, sizeof(stu),1,fp) == 1){ if(strcmp(s_id, stu.ID) == 0){ fwrite(&stu,sizeof(stu),1,temp); } } fclose(fp); fclose(temp); remove("record.txt"); rename("temp.txt","record.txt"); gotoxy(37,12);printf("The record is sucessfully deleted"); SetColor(28); return; } void main_window(){ int choice; SetColor(28); int x = 2; while(1){ gotoxy(x,8);printf("1. Add Student"); gotoxy(x,10);printf("2. Search Student"); gotoxy(x,12);printf("3. Modify Student Record"); gotoxy(x,14);printf("4. Generate Marksheet"); gotoxy(x,16);printf("5. Delete Student Record"); gotoxy(x,18);printf("6. Change password"); gotoxy(x,20);printf("7. Exit"); gotoxy(x,22);printf("Enter your choice: "); scanf("%d",&choice); switch(choice){ case 1: add_student(); break; case 2: search_student(); break; case 3: mod_student(); break; case 4: break; case 5: delete_student(); break; case 6: break; case 7: exit(0); break; default: break; } } } int main(){ ClearConsoleToColors(17,15); SetConsoleTitle("Programming-technique.blogspot.com - Student Record System"); window(); //use_pass_field(); main_window(); return 0; } |
C++ Code Tic Tac Toe Game
Let me share with you C++ Code of Tic Tac Toe Game project.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
#include <iostream> using namespace std; char square[10] = {'o','1','2','3','4','5','6','7','8','9'}; int IsItWinner(); void board(); int main() { int Game_Player = 1,i,Selection; char mark; do { board(); Game_Player=(Game_Player%2)?1:2; cout << "Game_Player " << Game_Player << ", enter a number: "; cin >> Selection; mark=(Game_Player == 1) ? 'X' : 'O'; if (Selection == 1 && square[1] == '1') square[1] = mark; else if (Selection == 2 && square[2] == '2') square[2] = mark; else if (Selection == 3 && square[3] == '3') square[3] = mark; else if (Selection == 4 && square[4] == '4') square[4] = mark; else if (Selection == 5 && square[5] == '5') square[5] = mark; else if (Selection == 6 && square[6] == '6') square[6] = mark; else if (Selection == 7 && square[7] == '7') square[7] = mark; else if (Selection == 8 && square[8] == '8') square[8] = mark; else if (Selection == 9 && square[9] == '9') square[9] = mark; else { cout<<"Invalid or wrong move "; Game_Player--; cin.ignore(); cin.get(); } i=IsItWinner(); Game_Player++; }while(i==-1); board(); if(i==1) cout<<"==>\aGame_Player "<<--Game_Player<<" win "; else cout<<"==>\aGame draw"; cin.ignore(); cin.get(); return 0; } /* FUNCTION TO RETURN GAME STATUS 1 FOR GAME IS OVER WITH RESULT -1 FOR GAME IS IN PROGRESS O GAME IS OVER AND NO RESULT */ void board() { system("cls"); cout << "\n\n\tTic Tac Toe\n\n"; cout << "Game_Player 1 (X) - Game_Player 2 (O)" << endl << endl<< endl; cout << endl<< endl; cout << " | | " << endl<< endl; cout << " " << square[1] << " | " << square[2] << " | " << square[3] << endl<< endl; cout << "*******|*******|*******" << endl<< endl; cout << " | | " << endl<< endl; cout << " " << square[4] << " | " << square[5] << " | " << square[6] << endl<< endl; cout << "*******|*******|*******" << endl<< endl; cout << " | | " << endl<< endl; cout << " " << square[7] << " | " << square[8] << " | " << square[9] << endl<< endl; cout << " | | " << endl << endl<< endl; } int IsItWinner() { if (square[1] == square[2] && square[2] == square[3]) return 1; else if (square[4] == square[5] && square[5] == square[6]) return 1; else if (square[7] == square[8] && square[8] == square[9]) return 1; else if (square[1] == square[4] && square[4] == square[7]) return 1; else if (square[2] == square[5] && square[5] == square[8]) return 1; else if (square[3] == square[6] && square[6] == square[9]) return 1; else if (square[1] == square[5] && square[5] == square[9]) return 1; else if (square[3] == square[5] && square[5] == square[7]) return 1; else if (square[1] != '1' && square[2] != '2' && square[3] != '3' && square[4] != '4' && square[5] != '5' && square[6] != '6' && square[7] != '7' && square[8] != '8' && square[9] != '9') return 0; else return -1; } |
Output Tic Tac Toe Game_Player 1 (X) – Game_Player 2 (O) | | 1 | 2 | X *******|*******|******* | | O | X | 6 *******|*******|******* | | 7 | 8 | 9 | | Game_Player 2, enter a…
Doctor Appointment C++ Project
Free source code download for Doctor Appointment Project in C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
#include <iostream> #include <string> #include <fstream> #include <cstring> using namespace std; int Booking() { system("cls"); cout<<"\n ||- Book Your Appointment || \n"; cout<<"\n ||- Availbale slots || \n"; //check if record already exist.. ifstream read; read.open("appointment.dat"); int hoursbook = 8; int arr[13] = {0,0,0,0,0,0,0,0,0,0,0,0,0}; int Found =0; if(read) { string line; char key = 'A'; int i = 9; while(getline(read, line)) { char temporary = line[0]; int index = (temporary - 65); arr[index]=1; Found = 1; } if(Found == 1) { cout<<"\n Appointment Summary by hours:"; char key = 'A'; int hours = 9; for(int i = 0; i<=12; i++) { if(i == 0){ if(arr[i] == 0) cout<<"\n "<<key<<"-> 0"<<hours<<" - Available"; else cout<<"\n "<<key<<"-> 0"<<hours<<" - Booked"; } else { if(arr[i] == 0) cout<<"\n "<<key<<"->"<<hours<<" - Available"; else cout<<"\n "<<key<<"->"<<hours<<" - Booked"; } hours++; key++; } } read.close(); } if(Found == 0){ cout<<"\n Appointment Available for following hours :"; char key = 'A'; for(int i = 9; i<=21; i++) { if(i==9) cout<<"\n "<<key<<" -> 0"<<i<<" - Available"; else cout<<"\n "<<key<<" -> "<<i<<" - Available"; key++; } } char choice; cout<<"\n\n Input your choice : "; cin>>choice; if( !(choice >= 'A' && choice <='Z')) { cout<"\n Error : Invalid Selection"; cout<<"\n Please selction correct value from menu A- Z"; cout<"\n Press any key to continue"; getchar();getchar(); system("cls"); Booking(); } int index = (choice-65 ); int isBooked = 1; if(arr[index] == 0) isBooked = 0; if(isBooked ==1) { cout<<"\n Error : Appointment is already booked for this Hour"; cout<<"\n Please select different time !!"; cout<<"\n Press any key to continue!!"; getchar();getchar(); system("cls"); Booking(); } string name; cout<<"\n Please Enter your first name:"; cin>>name; ofstream out; out.open("appointment.dat", ios::app); if(out){ out<<choice<<":"<<name.c_str()<<"\n"; out.close(); cout<<"\n Appointment booked for Hours : "<< (choice-65) + 9 <<" successfully !!"; } else { cout<<"\n Error while saving booking"; } cout<<"\n Please any key to continue.."; getchar(); getchar(); return 0; } int existingAppointment() { system("cls"); cout<<"\n ||- Appointments Summary || \n"; //check if record already exist.. ifstream read; read.open("appointment.dat"); int hoursbook = 8; int arr[13] = {0,0,0,0,0,0,0,0,0,0,0,0,0}; int Found =0; if(read) { string line; char key = 'A'; int i = 9; while(getline(read, line)) { char temporary = line[0]; int index = (temporary - 65); arr[index]=1; Found = 1; } if(Found == 1) { cout<<"\n Appointment Summary by hours:"; char key = 'A'; int hours = 9; for(int i = 0; i<=12; i++) { if(arr[i] == 0) cout<<"\n "<<key<<"->"<<hours<<" - Available"; else cout<<"\n "<<key<<"->"<<hours<<" - Booked"; hours++; key++; } } read.close(); } else { char key = 'A'; for(int i = 9; i<=21; i++) { if(i==9) cout<<"\n "<<key<<" -> 0"<<i<<" - Available"; else cout<<"\n "<<key<<" -> "<<i<<" - Available"; key++; } } cout<<"\n Please any key to continue.."; getchar(); getchar(); return 0; } int main(int argc, char** argv) { while(1) { system("cls"); cout<<"\t\t\tDoctor Appointment System\n"; cout<<"||||||||||||||||||||\n\n"; cout<<"Welcome to projectsinventory.com\n"; cout<<"Press1 For. Book Appointment\n"; cout<<"Press2 For. Check Existing Appointment\n"; cout<<"For 0 For. Exit\n"; int choice; cout<<"\n Please Enter you choice: "; cin>>choice; switch(choice) { case 1: Booking(); break; case 2: existingAppointment(); break; case 0: while(1) { system("cls"); cout<<"\n Are you sure, you want to exit? y | n \n"; char ex; cin>>ex; if(ex == 'y' || ex == 'Y') exit(0); else if(ex == 'n' || ex == 'N') { break; } else{ cout<<"\n Invalid choice !!!"; getchar(); } } break; default: cout<<"\n Invalid choice. Please Enter again "; getchar(); } } return 0; } |
Output Doctor Appointment System |||||||||||||||||||| Welcome to projectsinventory.com Press1 For. Book Appointment Press2 For. Check Existing Appointment For 0 For. Exit Please Enter you choice: 1 ||- Book Your Appointment || ||- Availbale slots || Appointment Available for following hours : A -> 09…
Database Design or Schema of Beauty Parlour/Salon Management system
More Helpful content about Beauty Parlour/Salon Management system SRS Documentation of Beauty Parlour/Salon Management system Functional & Non Functional Requirements of Beauty Parlour/Salon Use case Description of Beauty Parlour/Salon Management system Database Design or Schema of Beauty Parlour/Salon Management system
Use case Description of Beauty Parlour/Salon Management system
3.5 Use Cases Table 1: Use Case 1 Use Case Login Actor Users, Parlor ,Admin Description The Use case is start when the actors sign in. 1. User wishes to login. 2. The system displays the login page that asks the actor to enter email and password. Basic course of 3. The actor submits…
Beauty Parlour/Salon Functional Non Functional Requirements
REQUIREMENT ANALYSIS 3.1 SYSTEM REQUIREMENT SPECIFICATION 3.1.1 Product Description: This system consists a website which provide the online beauty parlor service. Web site should be able to help the customer for searching beauty parlor and services online. It help the parlor admin to sell all detail in brief like total number of customer, total number…
Beauty Parlour/Salon Management system SRS Documentation
INTRODUCTION Beauty Parlor Management System is basically a web-based application that is built in Codeigniter, PHP, Html, Bootstrap, CSS, JS (javascript), and jQuery. And for the backend of the system, SQL server has been used (i.e. Database) so that it will be easy to retrieve later. Also, the main aim of the system is to…
Things You Need to Know Before Submitting Your Project Report
There are so many things that require a document format, and documents are not the only thing that uses the format. PDF files have become a critical part of everyday reporting and recording tasks. PDFs, from project reports, assignments, and proposals to signed contracts, are used to record, store, and share valuable data between teams…