A program that focuses on the general writing and implementation of generic and customized programs to drive operating systems and that generally prepares individuals to apply the methods and procedures of software design and programming to software installation and maintenance.
Sunday, 12 June 2016
10 Articles Every Programmer Must Read
person encoding is some other vicinity, in which many programmer warfare, and "absolutely the minimal every software program Developer virtually, undoubtedly need to recognise about Unicode and person units (No Excuses!)" objectives to fill that hole. On aspect note, yes it is the whole title of that article. It changed into written via Joel Spolsky, one of the founder of statckoverflow.Com. Joel has written this submit on his weblog almost 10 years returned, however it's miles nevertheless relevant in nowadays’s international. This article will teach you approximately what is Unicode, what's individual encoding, how characters are represented the use of bytes and lots of extra. One of the fine thing approximately this newsletter is language and waft, even in case you do not know something approximately Unicode, you may effortlessly comply with. In quick, one more should examine for all programmers, coders and software program engineers.
Friday, 10 June 2016
C++ Snake and Ladder Game Project Source Code
This is a sample C++ snake and ladder Game Project for class 11 CBSE board. Select this program and save as .cpp file and compile it on Turbo C++.
//***************************************************************
// Source Code
//****************************************************************
// Source Code
//****************************************************************
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
void draw_line(int n,char ch);
void board();
void gamescore(char name1[],char name2[],int p1, int p2);
void play_dice(int &score);
void board();
void gamescore(char name1[],char name2[],int p1, int p2);
void play_dice(int &score);
void main()
{
int player1=0,player2=0,lastposition;
char player1name[80],player2name[80];
clrscr();
randomize();
draw_line(50,'=');
cout<<"\n\n\n\n\t\tSNAKE LADDER GAME\n\n\n\n";
draw_line(50,'=');
cout<<"\n\n\nEnter Name of player 1 :";
gets(player1name);
cout<<"\n\n\Enter Name of player 2 :";
gets(player2name);
while(player1<=100 && player2<=100)
{
board();
gamescore(player1name,player2name,player1,player2);
cout<<"\n\n--->" <<player1name<<" Now your Turn >> Press any key to play ";
getch();
lastposition=player1;
play_dice(player1);
if(player1<lastposition)
cout<<"\n\aOops!! Snake found !! You are at postion "<<player1<<"\n";
else if(player1>lastposition+6)
cout<<"\nGreat!! you got a ladder !! You are at position "<<player1;
cout<<"\n\n--->"<<player2name<<" Now your Turn >> Press any key to play ";
getch();
lastposition=player2;
play_dice(player2);
if(player2<lastposition)
cout<<"\n\n\aOops!! Snake found !! You are at position "<<player2<<"\n";
else if(player2>lastposition+6)
cout<<"\n\nGreat!! you got a ladder !! You are at position "<<player2<<"\n";
getch();
}
clrscr();
cout<<"\n\n\n";
draw_line(50,'+');
cout<<"\n\n\t\tRESULT\n\n";
draw_line(50,'+');
cout<<endl;
gamescore(player1name,player2name,player1,player2);
cout<<"\n\n\n";
if(player1>=player2)
cout<<player1name<<" !! You are the winner of the game\n\n";
else
cout<<player2name<<" !! You are the winner of the game\n\n";
draw_line(50,'+');
getch();
}
{
int player1=0,player2=0,lastposition;
char player1name[80],player2name[80];
clrscr();
randomize();
draw_line(50,'=');
cout<<"\n\n\n\n\t\tSNAKE LADDER GAME\n\n\n\n";
draw_line(50,'=');
cout<<"\n\n\nEnter Name of player 1 :";
gets(player1name);
cout<<"\n\n\Enter Name of player 2 :";
gets(player2name);
while(player1<=100 && player2<=100)
{
board();
gamescore(player1name,player2name,player1,player2);
cout<<"\n\n--->" <<player1name<<" Now your Turn >> Press any key to play ";
getch();
lastposition=player1;
play_dice(player1);
if(player1<lastposition)
cout<<"\n\aOops!! Snake found !! You are at postion "<<player1<<"\n";
else if(player1>lastposition+6)
cout<<"\nGreat!! you got a ladder !! You are at position "<<player1;
cout<<"\n\n--->"<<player2name<<" Now your Turn >> Press any key to play ";
getch();
lastposition=player2;
play_dice(player2);
if(player2<lastposition)
cout<<"\n\n\aOops!! Snake found !! You are at position "<<player2<<"\n";
else if(player2>lastposition+6)
cout<<"\n\nGreat!! you got a ladder !! You are at position "<<player2<<"\n";
getch();
}
clrscr();
cout<<"\n\n\n";
draw_line(50,'+');
cout<<"\n\n\t\tRESULT\n\n";
draw_line(50,'+');
cout<<endl;
gamescore(player1name,player2name,player1,player2);
cout<<"\n\n\n";
if(player1>=player2)
cout<<player1name<<" !! You are the winner of the game\n\n";
else
cout<<player2name<<" !! You are the winner of the game\n\n";
draw_line(50,'+');
getch();
}
void draw_line(int n,char ch)
{
for(int i=0;i<n;i++)
cout<<ch;
}
{
for(int i=0;i<n;i++)
cout<<ch;
}
void board()
{
clrscr();
cout<<"\n\n";
draw_line(50,'-');
cout<<"\n\t\tSNAKE AT POSITION\n";
draw_line(50,'-');
cout<<"\n\tFrom 98 to 28 \n\tFrom 95 to 24\n\tFrom 92 to 51\n\tFrom 83 to 19\n\tFrom 73 to 1\n\tFrom 69 to 33\n\tFrom 64 to 36\n\tFrom 59 to 17\n\tFrom 55 to 7\n\tFrom 52 to 11\n\tFrom 48 to 9\n\tFrom 46 to 5\n\tFrom 44 to 22\n\n";
draw_line(50,'-');
cout<<"\n\t\t LADDER AT POSITION\n";
draw_line(50,'-');
cout<<"\n\tFrom 8 to 26\n\tFrom 21 to 82\n\tFrom 43 to 77\n\tFrom 50 to 91\n\tFrom 62 to 96\n\tFrom 66 to 87\n\tFrom 80 to 100\n";
draw_line(50,'-');
cout<<endl;
}
{
clrscr();
cout<<"\n\n";
draw_line(50,'-');
cout<<"\n\t\tSNAKE AT POSITION\n";
draw_line(50,'-');
cout<<"\n\tFrom 98 to 28 \n\tFrom 95 to 24\n\tFrom 92 to 51\n\tFrom 83 to 19\n\tFrom 73 to 1\n\tFrom 69 to 33\n\tFrom 64 to 36\n\tFrom 59 to 17\n\tFrom 55 to 7\n\tFrom 52 to 11\n\tFrom 48 to 9\n\tFrom 46 to 5\n\tFrom 44 to 22\n\n";
draw_line(50,'-');
cout<<"\n\t\t LADDER AT POSITION\n";
draw_line(50,'-');
cout<<"\n\tFrom 8 to 26\n\tFrom 21 to 82\n\tFrom 43 to 77\n\tFrom 50 to 91\n\tFrom 62 to 96\n\tFrom 66 to 87\n\tFrom 80 to 100\n";
draw_line(50,'-');
cout<<endl;
}
void gamescore(char name1[],char name2[],int p1, int p2)
{
cout<<"\n";
draw_line(50,'~');
cout<<"\n\t\tGAME STATUS\n";
draw_line(50,'~');
cout<<"\n\t--->"<<name1<<" is at position "<<p1<<endl;
cout<<"\t--->"<<name2<<" is at position "<<p2<<endl;
draw_line(50,'_');
cout<<endl;
}
{
cout<<"\n";
draw_line(50,'~');
cout<<"\n\t\tGAME STATUS\n";
draw_line(50,'~');
cout<<"\n\t--->"<<name1<<" is at position "<<p1<<endl;
cout<<"\t--->"<<name2<<" is at position "<<p2<<endl;
draw_line(50,'_');
cout<<endl;
}
void play_dice(int &score)
{
int dice;
dice=random(6)+1;
cout<<"\nYou got "<<dice<<" Point !! ";
score=score+dice;
cout<<"Now you are at position "<<score;
switch(score)
{
case 98 :score=28;break;
case 95 :score=24;break;
case 92 :score=51;break;
case 83 :score=19;break;
case 73 :score=1;break;
case 69 :score=33;break;
case 64 :score=36;break;
case 59 :score=17;break;
case 55 :score=7;break;
case 52 :score=11;break;
case 48 :score=9;break;
case 46 :score=5;break;
case 44 :score=22;break;
case 8 :score=26;break;
case 21 :score=82;break;
case 43 :score=77;break;
case 50 :score=91;break;
case 54 :score=93;break;
case 62 :score=96;break;
case 66 :score=87;break;
case 80 :score=100;
}
}
{
int dice;
dice=random(6)+1;
cout<<"\nYou got "<<dice<<" Point !! ";
score=score+dice;
cout<<"Now you are at position "<<score;
switch(score)
{
case 98 :score=28;break;
case 95 :score=24;break;
case 92 :score=51;break;
case 83 :score=19;break;
case 73 :score=1;break;
case 69 :score=33;break;
case 64 :score=36;break;
case 59 :score=17;break;
case 55 :score=7;break;
case 52 :score=11;break;
case 48 :score=9;break;
case 46 :score=5;break;
case 44 :score=22;break;
case 8 :score=26;break;
case 21 :score=82;break;
case 43 :score=77;break;
case 50 :score=91;break;
case 54 :score=93;break;
case 62 :score=96;break;
case 66 :score=87;break;
case 80 :score=100;
}
}
//***************************************************************
// END OF PROJECT
//***************************************************************
// END OF PROJECT
//***************************************************************
Casino Game : Number Guessing Program
#include <iostream> #include <string> // Needed to use strings #include <cstdlib> // Needed to use random numbers #include <ctime> using namespace std; void drawLine(int n, char symbol); void rules(); int main() { string playerName; int amount; // hold player's balance amount int bettingAmount; int guess; int dice; // hold computer generated number char choice; srand(time(0)); // "Seed" the random generator drawLine(60,'_'); cout << "\n\n\n\t\tCASINO GAME\n\n\n\n"; drawLine(60,'_'); cout << "\n\nEnter Your Name : "; getline(cin, playerName); cout << "\n\nEnter Deposit amount to play game : $"; cin >> amount; do { system("cls"); rules(); cout << "\n\nYour current balance is $ " << amount << "\n"; // Get player's betting amount do { cout <<playerName<<", enter money to bet : $"; cin >> bettingAmount; if(bettingAmount > amount) cout << "Your betting amount is more than your current balance\n" <<"\nRe-enter data\n "; }while(bettingAmount > amount); // Get player's numbers do { cout << "Guess your number to bet between 1 to 10 :"; cin >> guess; if(guess <= 0 || guess > 10) cout << "Please check the number!! should be between 1 to 10\n" <<"\nRe-enter data\n "; }while(guess <= 0 || guess > 10); dice = rand()%10 + 1; // Will hold the randomly generated integer between 1 and 10 if(dice == guess) { cout << "\n\nGood Luck!! You won Rs." << bettingAmount * 10; amount = amount + bettingAmount * 10; } else { cout << "Bad Luck this time !! You lost $ "<< bettingAmount <<"\n"; amount = amount - bettingAmount; } cout << "\nThe winning number was : " << dice <<"\n"; cout << "\n"<<playerName<<", You have $ " << amount << "\n"; if(amount == 0) { cout << "You have no money to play "; break; } cout << "\n\n-->Do you want to play again (y/n)? "; cin >> choice; }while(choice =='Y'|| choice=='y'); cout << "\n\n\n"; drawLine(70,'='); cout << "\n\nThanks for playing game. Your balance amount is $ " << amount << "\n\n"; drawLine(70,'='); return 0; } void drawLine(int n, char symbol) { for(int i=0; i<n; i++) cout << symbol; cout << "\n" ; } void rules() { system("cls"); cout << "\n\n"; drawLine(80,'-'); cout << "\t\tRULES OF THE GAME\n"; drawLine(80,'-'); cout << "\t1. Choose any number between 1 to 10\n"; cout << "\t2. If you win you will get 10 times of money you bet\n"; cout << "\t3. If you bet on wrong number you will lose your betting amount\n\n"; drawLine(80,'-'); } // END OF PROGRAM
Student Report Card System - source code of program
/*************************************************************** // HEADER FILE USED IN PROJECT //**************************************************************** #include<iostream> #include<fstream> #include<iomanip> using namespace std; //*************************************************************** // CLASS USED IN PROJECT //**************************************************************** class student { int rollno; char name[50]; int p_marks, c_marks, m_marks, e_marks, cs_marks; double per; char grade; void calculate(); //function to calculate grade public: void getdata(); //function to accept data from user void showdata() const; //function to show data on screen void show_tabular() const; int retrollno() const; }; //class ends here void student::calculate() { per=(p_marks+c_marks+m_marks+e_marks+cs_marks)/5.0; if(per>=60) grade='A'; else if(per>=50) grade='B'; else if(per>=33) grade='C'; else grade='F'; } void student::getdata() { cout<<"\nEnter The roll number of student "; cin>>rollno; cout<<"\n\nEnter The Name of student "; cin.ignore(); cin.getline(name,50); cout<<"\nEnter The marks in physics out of 100 : "; cin>>p_marks; cout<<"\nEnter The marks in chemistry out of 100 : "; cin>>c_marks; cout<<"\nEnter The marks in maths out of 100 : "; cin>>m_marks; cout<<"\nEnter The marks in english out of 100 : "; cin>>e_marks; cout<<"\nEnter The marks in computer science out of 100 : "; cin>>cs_marks; calculate(); } void student::showdata() const { cout<<"\nRoll number of student : "<<rollno; cout<<"\nName of student : "<<name; cout<<"\nMarks in Physics : "<<p_marks; cout<<"\nMarks in Chemistry : "<<c_marks; cout<<"\nMarks in Maths : "<<m_marks; cout<<"\nMarks in English : "<<e_marks; cout<<"\nMarks in Computer Science :"<<cs_marks; cout<<"\nPercentage of student is :"<<per; cout<<"\nGrade of student is :"<<grade; } void student::show_tabular() const { cout<<rollno<<setw(6)<<" "<<name<<setw(10)<<p_marks<<setw(4)<<c_marks<<setw(4)<<m_marks<<setw(4) <<e_marks<<setw(4)<<cs_marks<<setw(8)<<per<<setw(6)<<grade<<endl; } int student::retrollno() const { return rollno; } //*************************************************************** // function declaration //**************************************************************** void write_student(); //write the record in binary file void display_all(); //read all records from binary file void display_sp(int); //accept rollno and read record from binary file void modify_student(int); //accept rollno and update record of binary file void delete_student(int); //accept rollno and delete selected records from binary file void class_result(); //display all records in tabular format from binary file void result(); //display result menu void intro(); //display welcome screen void entry_menu(); //display entry menu on screen //*************************************************************** // THE MAIN FUNCTION OF PROGRAM //**************************************************************** int main() { char ch; cout.setf(ios::fixed|ios::showpoint); cout<<setprecision(2); // program outputs decimal number to two decimal places intro(); do { system("cls"); cout<<"\n\n\n\tMAIN MENU"; cout<<"\n\n\t01. RESULT MENU"; cout<<"\n\n\t02. ENTRY/EDIT MENU"; cout<<"\n\n\t03. EXIT"; cout<<"\n\n\tPlease Select Your Option (1-3) "; cin>>ch; switch(ch) { case '1': result(); break; case '2': entry_menu(); break; case '3': break; default :cout<<"\a"; } }while(ch!='3'); return 0; } //*************************************************************** // function to write in file //**************************************************************** void write_student() { student st; ofstream outFile; outFile.open("student.dat",ios::binary|ios::app); st.getdata(); outFile.write(reinterpret_cast<char *> (&st), sizeof(student)); outFile.close(); cout<<"\n\nStudent record Has Been Created "; cin.ignore(); cin.get(); } //*************************************************************** // function to read all records from file //**************************************************************** void display_all() { student st; ifstream inFile; inFile.open("student.dat",ios::binary); if(!inFile) { cout<<"File could not be open !! Press any Key..."; cin.ignore(); cin.get(); return; } cout<<"\n\n\n\t\tDISPLAY ALL RECORD !!!\n\n"; while(inFile.read(reinterpret_cast<char *> (&st), sizeof(student))) { st.showdata(); cout<<"\n\n====================================\n"; } inFile.close(); cin.ignore(); cin.get(); } //*************************************************************** // function to read specific record from file //**************************************************************** void display_sp(int n) { student st; ifstream inFile; inFile.open("student.dat",ios::binary); if(!inFile) { cout<<"File could not be open !! Press any Key..."; cin.ignore(); cin.get(); return; } bool flag=false; while(inFile.read(reinterpret_cast<char *> (&st), sizeof(student))) { if(st.retrollno()==n) { st.showdata(); flag=true; } } inFile.close(); if(flag==false) cout<<"\n\nrecord not exist"; cin.ignore(); cin.get(); } //*************************************************************** // function to modify record of file //**************************************************************** void modify_student(int n) { bool found=false; student st; fstream File; File.open("student.dat",ios::binary|ios::in|ios::out); if(!File) { cout<<"File could not be open !! Press any Key..."; cin.ignore(); cin.get(); return; } while(!File.eof() && found==false) { File.read(reinterpret_cast<char *> (&st), sizeof(student)); if(st.retrollno()==n) { st.showdata(); cout<<"\n\nPlease Enter The New Details of student"<<endl; st.getdata(); int pos=(-1)*static_cast<int>(sizeof(st)); File.seekp(pos,ios::cur); File.write(reinterpret_cast<char *> (&st), sizeof(student)); cout<<"\n\n\t Record Updated"; found=true; } } File.close(); if(found==false) cout<<"\n\n Record Not Found "; cin.ignore(); cin.get(); } //*************************************************************** // function to delete record of file //**************************************************************** void delete_student(int n) { student st; ifstream inFile; inFile.open("student.dat",ios::binary); if(!inFile) { cout<<"File could not be open !! Press any Key..."; cin.ignore(); cin.get(); return; } ofstream outFile; outFile.open("Temp.dat",ios::out); inFile.seekg(0,ios::beg); while(inFile.read(reinterpret_cast<char *> (&st), sizeof(student))) { if(st.retrollno()!=n) { outFile.write(reinterpret_cast<char *> (&st), sizeof(student)); } } outFile.close(); inFile.close(); remove("student.dat"); rename("Temp.dat","student.dat"); cout<<"\n\n\tRecord Deleted .."; cin.ignore(); cin.get(); } //*************************************************************** // function to display all students grade report //**************************************************************** void class_result() { student st; ifstream inFile; inFile.open("student.dat",ios::binary); if(!inFile) { cout<<"File could not be open !! Press any Key..."; cin.ignore(); cin.get(); return; } cout<<"\n\n\t\tALL STUDENTS RESULT \n\n"; cout<<"==========================================================\n"; cout<<"R.No Name P C M E CS %age Grade"<<endl; cout<<"==========================================================\n"; while(inFile.read(reinterpret_cast<char *> (&st), sizeof(student))) { st.show_tabular(); } cin.ignore(); cin.get(); inFile.close(); } //*************************************************************** // function to display result menu //**************************************************************** void result() { char ch; int rno; system("cls"); cout<<"\n\n\n\tRESULT MENU"; cout<<"\n\n\n\t1. Class Result"; cout<<"\n\n\t2. Student Report Card"; cout<<"\n\n\t3. Back to Main Menu"; cout<<"\n\n\n\tEnter Choice (1/2/3)? "; cin>>ch; system("cls"); switch(ch) { case '1' : class_result(); break; case '2' : cout<<"\n\n\tEnter Roll Number Of Student : "; cin>>rno; display_sp(rno); break; case '3' : break; default: cout<<"\a"; } } //*************************************************************** // INTRODUCTION FUNCTION //**************************************************************** void intro() { cout<<"\n\n\n\t\t STUDENT"; cout<<"\n\n\t\tREPORT CARD"; cout<<"\n\n\t\t PROJECT"; cout<<"\n\n\n\tMADE BY : SULABH AGRAWAL"; cout<<"\n\tSCHOOL : CAMBRIDGE SCHOOL"; cin.get(); } //*************************************************************** // ENTRY / EDIT MENU FUNCTION //**************************************************************** void entry_menu() { char ch; int num; system("cls"); cout<<"\n\n\n\tENTRY MENU"; cout<<"\n\n\t1.CREATE STUDENT RECORD"; cout<<"\n\n\t2.DISPLAY ALL STUDENTS RECORDS"; cout<<"\n\n\t3.SEARCH STUDENT RECORD "; cout<<"\n\n\t4.MODIFY STUDENT RECORD"; cout<<"\n\n\t5.DELETE STUDENT RECORD"; cout<<"\n\n\t6.BACK TO MAIN MENU"; cout<<"\n\n\tPlease Enter Your Choice (1-6) "; cin>>ch; system("cls"); switch(ch) { case '1': write_student(); break; case '2': display_all(); break; case '3': cout<<"\n\n\tPlease Enter The roll number "; cin>>num; display_sp(num); break; case '4': cout<<"\n\n\tPlease Enter The roll number "; cin>>num; modify_student(num);break; case '5': cout<<"\n\n\tPlease Enter The roll number "; cin>>num; delete_student(num);break; case '6': break; default: cout<<"\a"; entry_menu(); } } //*************************************************************** // END OF PROJECT //***************************************************************
Subscribe to:
Posts (Atom)