Tuesday, 21 June 2016

FBI approach to investigations puts security at risk

In an essay to be posted on June 17, 2016 in technology magazine Susan Landau, professor of cybersecurity policy at Worcester Polytechnic Institute (WPI), argues that the FBI's latest and widely publicized efforts to compel Apple laptop to write down software program to liberate an iPhone utilized by a terrorist in California displays an old method to law enforcement that threatens to weaken the security of all smartphones, potentially placing the personal information of hundreds of thousands of smartphone customers at risk and undermining the developing use of smartphones as relied on authenticators for having access to on line facts.

The technology essay grew out of testimony Landau delivered in March earlier than a hearing of the U.S. House Judiciary Committee [Landau's testimony begins at 3:35:44]. In that discussion board, Landau countered the argument of FBI director James Comey that encrypted gadgets (which Comey has characterized as "warrant-proof areas") prevent the enterprise's ability to analyze crimes. Landau says the FBI is looking at smartphones thru a 20th century lens, a attitude this is especially troubling given the ability for smartphones to either update or augment static passwords as authenticators for logging into computers or accessing on-line debts.

Login credentials are a desired target of hackers, Landau says, considering they could offer access to treasured statistics and leave laptop structures open to assault. Increasingly more, corporations like facebook and Google and even some excessive-level authorities corporations are using smartphones as authenticators to make on line assets extensively more tough to breach. However for cellphone authentication to be powerful, smartphones, themselves, have to be comfortable.

Landau says the FBI's efforts to weaken telephone security replicate its previous approach to investigating crime and its inadequate sources for conducting current cyber investigations. Landau argues that the organisation needs to invest in constructing up its own "21st century investigative savvy," which include growing "an investigative middle with sellers with deep technical understanding of current communications technology and computer technology."

With the ability to expand new surveillance methods and equipment matched to the modern-day advances in communications technology, the organization will no longer want to searching for to weaken the gadgets that people, groups, and government groups international rely upon to securely speak, transact commercial enterprise, and transmit touchy records.

World's first 1,000-processor chip

A microchip containing 1,000 independent programmable processors has been designed by a team at the University of California, Davis, Department of Electrical and Computer Engineering. The energy-efficient "KiloCore" chip has a maximum computation rate of 1.78 trillion instructions per second and contains 621 million transistors. The KiloCore was presented at the 2016 Symposium on VLSI Technology and Circuits in Honolulu on June 16.

"To the best of our knowledge, it is the world's first 1,000-processor chip and it is the highest clock-rate processor ever designed in a university," said Bevan Baas, professor of electrical and computer engineering, who led the team that designed the chip architecture. While other multiple-processor chips have been created, none exceed about 300 processors, according to an analysis by Baas' team. Most were created for research purposes and few are sold commercially. The KiloCore chip was fabricated by IBM using their 32 nm CMOS technology.

Each processor core can run its own small program independently of the others, which is a fundamentally more flexible approach than so-called Single-Instruction-Multiple-Data approaches utilized by processors such as GPUs; the idea is to break an application up into many small pieces, each of which can run in parallel on different processors, enabling high throughput with lower energy use, Baas said.

Because each processor is independently clocked, it can shut itself down to further save energy when not needed, said graduate student Brent Bohnenstiehl, who developed the principal architecture. Cores operate at an average maximum clock frequency of 1.78 GHz, and they transfer data directly to each other rather than using a pooled memory area that can become a bottleneck for data.

The chip is the most energy-efficient "many-core" processor ever reported, Baas said. For example, the 1,000 processors can execute 115 billion instructions per second while dissipating only 0.7 Watts, low enough to be powered by a single AA battery. The KiloCore chip executes instructions more than 100 times more efficiently than a modern laptop processor.

Applications already developed for the chip include wireless coding/decoding, video processing, encryption, and others involving large amounts of parallel data such as scientific data applications and datacenter record processing.

The team has completed a compiler and automatic program mapping tools for use in programming the chip.

Rice University researchers have just the thing for the age of information overload: an app that sees all and remembers only what it should.

RedEye, new generation from Rice's efficient Computing institution that turned into unveiled nowadays at the global Symposium on computer structure (ISCA 2016) convention in Seoul, South Korea, may want to offer computers with continuous imaginative and prescient -- a primary step closer to allowing the gadgets to peer what their proprietors see and preserve tune of what they need to consider.

"The concept is to allow our computers to help us by using displaying them what we see all through the day," said institution chief Lin Zhong, professor of electrical and pc engineering at Rice and the co-creator of a new observe about RedEye. "it might be like having a personal assistant who can keep in mind someone you met, in which you met them, what they instructed you and different particular records like costs, dates and instances."

Zhong stated RedEye is an example of the sort of generation the computing enterprise is developing for use with wearable, fingers-loose, constantly-on devices which might be designed to assist humans in their day by day lives. The fashion, that's every now and then known as "pervasive computing" or "ambient intelligence," centers on technology which can understand or even count on what a person desires and provide it right away.

"The pervasive-computing movement foresees gadgets which might be non-public assistants, which assist us in huge and small methods at almost each second of our lives," Zhong said. "however a key enabler of this era is equipping our gadgets to look what we see and hear what we hear. Scent, flavor and touch might also come later, however vision and sound might be the initial sensory inputs."

Zhong said the bottleneck for non-stop vision is power intake due to the fact modern-day best telephone cameras, although particularly cheaper, are battery killers, in particular when they're processing actual-time video.

Zhong and former Rice graduate scholar Robert LiKamWa started reading the problem inside the summer of 2012 once they worked at Microsoft studies's Mobility and Networking studies institution in Redmond, Wash., in collaboration with institution director and Microsoft prominent Scientist Victor Bahl. LiKamWa stated the crew measured the strength profiles of commercially to be had, off-the-shelf photograph sensors and determined that current generation would need to be approximately 100 instances greater power-efficient for continuous vision to grow to be commercially possible. This became the incentive behind LiKamWa's doctoral thesis, which pursues software program and hardware aid for green laptop imaginative and prescient.

In an award-triumphing paper a year later, LiKamWa, Zhong, Bahl and colleagues showed they may enhance the power consumption of off-the-shelf picture sensors tenfold really thru software optimization.

"RedEye grew from that because we nevertheless wished another tenfold development in electricity performance, and we knew we would need to redesign both the hardware and software to acquire that," LiKamWa stated.

He stated the power bottleneck changed into the conversion of snap shots from analog to digital layout.

"actual-world alerts are analog, and converting them to digital alerts is luxurious in terms of strength," he said. "there's a physical restriction to how a good deal energy financial savings you could obtain for that conversion. We decided a better alternative might be to research the alerts whilst they have been nevertheless analog."

the main drawback of processing analog alerts -- and the purpose virtual conversion is the standard first step for most photo-processing systems today -- is that analog signals are inherently noisy, LiKamWa said. To make RedEye appealing to tool makers, the team had to reveal that it could reliably interpret analog indicators.

"We wanted to show that we should inform a cat from a canine, as an instance, or a table from a chair," he stated.

Rice graduate pupil Yunhui Hou and undergraduates Mia Polansky and Yuan Gao have been also individuals of the group, which decided to assault the hassle using a combination of the modern techniques from gadget gaining knowledge of, machine architecture and circuit layout. In the case of device mastering, RedEye makes use of a way called a "convolutional neural community," an algorithmic structure inspired by way of the company of the animal visible cortex.

LiKamWa said Hou added new ideas related to gadget structure circuit layout primarily based on preceding enjoy operating with specialized processors referred to as analog-to-virtual converters at Hong Kong university of technology and generation.

"We bounced thoughts off one another concerning architecture and circuit design, and we commenced to recognize the possibilities for doing early processing a good way to accumulate key facts in the analog area," LiKamWa stated.

"traditional structures extract a whole image thru the analog-to-digital converter and conduct image processing at the virtual file," he said. "If you can shift that processing into the analog domain, then you will have a much smaller facts bandwidth that you need to ship through that ADC bottleneck."

LiKamWa stated convolutional neural networks are the cutting-edge way to perform item recognition, and the mixture of these techniques with analog-area processing offers a few unique privateness blessings for RedEye.

"The upshot is that we will recognize objects -- like cats, puppies, keys, telephones, computer systems, faces, and so on. -- without clearly searching at the photograph itself," he stated. "we are simply looking on the analog output from the imaginative and prescient sensor. We have an know-how of what is there while not having an real picture. This will increase power efficiency due to the fact we are able to select to digitize most effective the images which can be well worth expending power to create. It also can also help with privateness implications due to the fact we can define a set of policies wherein the system will mechanically discard the uncooked image after it has completed processing. That picture could by no means be recoverable. So, if there are instances, locations or particular items a person doesn't want to file -- and doesn't need the gadget to don't forget -- we have to layout mechanisms to make sure that photographs of those matters are in no way created inside the first area."

Zhong stated studies on RedEye is ongoing. He said the crew is running on a circuit format for the RedEye structure that can be used to test for layout troubles, factor mismatch, signal crosstalk and different hardware troubles. Work is likewise ongoing to enhance performance in low-mild environments and other settings with low signal-to-noise ratios, he said.

Tuesday, 14 June 2016

Test Smarter, Not Harder

Creation: Complexity leads to Futility

consider we are growing a web page for customizing a pc buy.

In case you've by no means configured a pc on-line earlier than, test Dell's "customize it" web page for an entry degree laptop. The internet page offers 11 inquiries to the consumer which have from two to seven responses each. The person has to pick out from two alternatives in the first control,  within the second, and so on. The person has seven feasible picks for the last manage.

When we observe all of the controls combined, the consumer has to make (2,2,2,2,2,3,2,2,three,4,7) choices. That is a easy configuration hassle. The number of possible laptop configurations that would be asked with the aid of the user is the product of all the choices. On this quite simple web page, there are 32,256 possibilities. On the time of this writing, the web page for customizing Dell's excessive-give up pc has a not multiple set of controls, with more choices in each manage: (three,3,three,2,four,2,4,2,2,three,7,four,four). The person of this page can request any of two,322,432 specific computer configurations! If Dell have been to feature one extra manage supplying five one of a kind picks, there might be over ten million possible combos!

Growing a test suite that tries all  million mixtures for a excessive end computer can be automatic, however despite the fact that each check took one tenth of 2d to run, the suite could take over sixty four hours! Dell adjustments their product offerings in less time than that.

However, if we use a server farm to distribute the test suite across ten machines we may want to run it in approximately 6 hours. Ignoring the truth that we would be running this form of take a look at for every customization page Dell has, 6 hours isn't always unreasonable.

Validating the two million outcomes is where the truly massive trouble is awaiting us. We can not rely upon people to manually validate all of the outputs–it's miles just too costly. We may want to write some other application, which inspects the ones outputs and evaluates them the usage of a policies-primarily based machine ("If the user selects 1GB of RAM, then the configuration should encompass 1GB of RAM" and "The rate for the final gadget must be adjusted with the aid of the charge-effect of 1GB of RAM relative to the base gadget price for this model.")

There are some properly rules-based validation gear accessible, however they are either custom software, or so standard as to require a large funding to make them applicable to a particular purchaser. With a policies-based totally inspection system, we've got the cost of retaining the regulations. The validation guidelines are going to must be up to date often, as Dell changes the manner they role, configure, and charge their laptops.

Due to the fact we are not Dell, we do not have the size (billions of bucks of sales) to justify this stage of investment. The lowest line for us is that we can not have the funds for to exhaustively take a look at each mixture. Dell's shareholders require them to develop their commercial enterprise, and these configuration pages are the vehicle by using which Dell generates billions of greenbacks in sales. They've to test it. The cost of mistakes (crashes, misplaced income, mis-priced objects, invalid combinations of functions) is simply too high. With this degree of risk, the price of no longer checking out (the fee of bad nice) is extremely high.


We cannot find the money for to test It

i was capable of attend a education consultation with Kent Beck some years ago. I used to be additionally venerated a good way to enjoy a big steak and some cold beer with him that night after the training. Whilst requested how he responds to people who complain about the cost of pleasant, Kent informed us he has a totally easy answer: "If testing costs extra than no longer trying out then don't do it."

I agree. There are few situations where the fee of first-class exceeds the value of poor nice. These are situations in which the wanted infrastructure, take a look at-development time, and protection costs outweigh the predicted fee of getting a trojan horse. (The "anticipated cost" is the probability (as a percent) of the worm manifesting inside the area, increased by way of the cost of managing the bug.)

The strategies described in this newsletter are designed to reduce the cost of high-quality, to make it even less possibly that "now not trying out" is the satisfactory answer.


Just check the whole thing, it is computerized!

Two "solutions" that we ought to consider are to test not anything and to check the whole thing. We would don't forget trying out not anything if we cannot have the funds for to check the software program. While humans do not appreciate the complexities of trying out or the restrictions of computerized trying out, they may be inclined to want to "test the entirety." testing the entirety is tons simpler stated than completed.

Have you ever been on a assignment wherein the manager stated some thing like, "I call for complete testing coverage of the software program. Our policy is 0 tolerance. We may not have awful excellent on my watch."?

What we conflict with right here is the lack of appreciation for what it means to have "full insurance" or another guarantee of a particular defect rate.

There are no absolutes in a sufficiently complex gadget–but this is ok. There are records, self assurance tiers, and risk-management plans. As engineers and software developers, our brains are wired to address the predicted, likely, and in all likelihood futures. We need to help our less-technical brethren recognize those standards–or as a minimum placed them in attitude.

We may additionally get requested, "Why can't we simply take a look at each combination of inputs to make certain we get the proper outputs? We have an automated take a look at suite–simply fill it up and run it!"

We want to face up to the urge to respond through saying, "Monkeys with typewriters can have completed the works of Shakespeare before we end a unmarried run of our take a look at suite!"

Solving the problem

There are a lot of programs that have hundreds of thousands or billons of combos of inputs. They've automated trying out. They've solutions to this trouble. We just finished discussing how impractical it is to check exhaustively, so how do corporations take a look at their complex software?

Within the relaxation of the object, we are able to explore the following methods to fixing the trouble.

Random sampling
Pairwise testing
N-wise checking out
we will also discover the effect that converting the order of operations has on our testing method, and the techniques for testing while the series topics.


Sunday, 12 June 2016

10 Articles Every Programmer Must Read

What every Programmer need to recognize approximately memory

that is one of the traditional article, if you need to take you through can also lanes of memory, a few vintage, some new, some seemed and a few unknown. Notwithstanding being so conman and omnipresent, not every programmer have enough knowledge of memory. Expertise of reminiscence in modern gadget turns into even extra essential if you are in space of writing high normal overall performance application. Hardware designers have provide you with ever greater present day reminiscence dealing with and acceleration strategies–together with CPU caches–but those can't art work optimally with out some help from the programmer. I am though studying this text, and that i can not inform you how plenty i have determined out from this approximately RAM, CPU Caches e.G. L1 and L2 cache, extremely good types of reminiscence, direct reminiscence get right of entry to, memory controller designs and reminiscence in general. In quick, a have to study for programmers of all level of enjoy.

What every laptop Scientist must know approximately Floating-point mathematics

Floating point arithmetic is a tricky topic, and it’s no longer clean to grasp. Even many Java programmer would not know what can go wrong whilst evaluating glide/double cost with == operator. Many of us frequently makes mistake of doing economic calculation in float and double. This article is every other gem of this series and must read for all software builders and programmers. As your experience grows, you're expected to realize subtle info of common matters, and floating point mathematics is one in all them. As as senior Java developer, you should realize how do perform economic calculation, whilst to apply glide, double or BigDecimal lessons, a way to spherical floating point numbers and so forth. Even if you recognize basics of floating point arithmetic, you may research some thing new about floating factor calculation with the aid of studying this text.


What each Developer need to realize approximately Unicode

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

Picasa 3 By Usama

https://drive.google.com/file/d/0B-fYmfmT9oXlTXJWXzNOTTRycUk/view?usp=sharing

Dev cpp latest version by Usama

https://drive.google.com/drive/my-drive

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 
//****************************************************************
#include<iostream.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 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();
}
void draw_line(int n,char 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;
}
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;
}
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;
}
}
//***************************************************************
// 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
//***************************************************************