mohityadavx
Youngling
add a condition to check if y!=0 to avoid runtime error.
thanx there would be many more such error and bug once i am able to get through password problem
add a condition to check if y!=0 to avoid runtime error.
So If I learn those basic algorithms and data structures in say- in the month of May. My basics about arrays,pointers etc are perfect. Can I expect something good that I will be able to attempt it well at ZCO?look, there will be 2 questions. one will be easy and you will be easily able to create an algo for it.
the other one is usually tough and you will need to apply some popular algo. it will seem difficult as we r not taught these algos in schools. it usually gives a problem where knapsack and dynamic programming is applicable.
only those who solve both problems are selected(as i wasnt selected in two ZCOs where i had solved only one problem as i wasnt aware of knapsack algo).
the MIT OCW has a good lecture on knapsack problems and application of dynamic programming on such probs.
also there are many tutorials for it.
i also suggest you to learn "dijkstra algorithm"(for shortest path problems) from somewhere(i cant find the page from which i learnt it, so google it)
@mohityadavx : Dude sorry to say but your program contain plenty of errors,like you are redefining the library functions like sin ,cos etc.It appears like you are low on the basics.Start learning from a good text book.I'd recommend C++ ,The Complete Reference by Herbert Schildt.It contains everything you need to know.Either buy one or search your school/college library.Good Luck
Like arpanmukherjee1 said you will have to add the pass='\0' statement and it should work perfectly.
It must, because that block of code is faultless and is running perfectly on my compiler.like i said before its still not working
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<math.h>
void main()
{
char pass[10];
int i=0;
cout<<"Enter password"<<endl;
while((pass[i]=getch())!='\r')
{
cout<<"*";
i++;
}
pass[i]='\0';
cout<<endl;
if(strcmp(pass,"mohit")==0)
cout<<"Password Comparison Successfull"<<endl;
else
cout<<"Failed Password is "<<pass<<endl;
getch();
}
Run this and post your output.
Code:#include<iostream.h> #include<conio.h> #include<string.h> #include<math.h> void main() { char pass[10]; int i=0; cout<<"Enter password"<<endl; while((pass[i]=getch())!='\r') { cout<<"*"; i++; } pass[i]='\0'; cout<<endl; if(strcmp(pass,"mohit")==0) cout<<"Password Comparison Successfull"<<endl; else cout<<"Failed Password is "<<pass<<endl; getch(); }
@mohityadavx : Dude sorry to say but your program contain plenty of errors,like you are redefining the library functions like sin ,cos etc.It appears like you are low on the basics.Start learning from a good text book.I'd recommend C++ ,The Complete Reference by Herbert Schildt.It contains everything you need to know.Either buy one or search your school/college library.Good Luck
Thanx for the advice never knew sumita arora was that bad that most of you are simply rejecting the code !!!! I will use Dev C++ as i like its layout more then GCC!!!
scanf() is a C input function, which is considered unsafe except for formatted data. .
Things to Avoid in C/C++ -- scanf, Part 5 - GIDNetworkProve this yaar
//TYPING TEST
#include <stdio.h>
#include <time.h>
#include <iostream>
#include <conio.h>
#include <ctype.h>
#include <stdlib.h>
#include <fstream.h>
#include <string.h>
using namespace std;
void fileChk(char filename[10])
{
ifstream fin(filename);
if(!fin.is_open())
{
ofstream fout("scores.dat");
fout<<0<<endl;
fout.close();
}
fin.close();
}
void writeScores(double score)
{
fileChk("scores.dat");
ifstream fin("scores.dat");
int n,i;
char names[10][20];
double scores[10];
fin>>n;
for(i=0;i<n;i++)
{
fin>>names[i];
fin>>scores[i];
}
if(n==0)
{
n=1;
fin.close();
remove("scores.dat");
ofstream fout("scores.dat");
fout<<1;
cout<<"\nCongratulations!!!, You made it to the HALL OF FAME\n\n";
char name[20];
cout<<"Enter you name - ";
cin>>name;
fout<<name<<" "<<score<<endl;
}else{
if(n<10)
n++;
fin.close();
remove("scores.dat");
ofstream fout("scores.dat");
fout<<n<<endl;
int flag=1;
for(i=0;i<n;i++)
{
if((scores[i]>score || (i==n-1 && scores[n-1]>score)) && flag==1)
{
flag=0;
n=n-1;
cout<<"\nCongratulations!!!, You made it to the HALL OF FAME\n\n";
char name[20];
cout<<"Enter you name - ";
cin>>name;
fout<<name<<" "<<score<<endl;
}
fout<<names[i]<<" "<<scores[i]<<endl;
}
fout.close();
}
}
void dispScores()
{
system("cls");
ifstream fin("scores.dat");
int n,i;
fin>>n;
cout<<"name \ttime\n\n";
for(i=0;i<n;i++)
{
char name[20];
fin>>name;
double score;
fin>>score;
cout<<name<<"\t"<<score<<endl;
}
}
int main()
{
cout<<"TYPING SPEED TESTER BY NIMS13\nPress any key to continue....";
getch();
system("cls");
char c;
clock_t start, end;
char str[100]="the quick brown fox jumps over the lazy dog";
int len=strlen(str),i,errors=0;
cout<<"Hello!! ,Type the following as fast as you can\n(The time will start when you type the first letter and will automatically end when you complete the sentence.\nDON'T PRESS ENTER WHEN YOU FINISH WRITING) -\n\nthe quick brown fox jumps over the lazy dog\n\n";
int flag=1;
while(flag)
{
c=getch();
if(tolower(c)==str[0])
{
cout<<c;
flag=0;
start = clock();
}else
errors++;
}
for(i=1;i<len;i++)
{
int flag=1;
while(flag)
{
c=getch();
if(tolower(c)==str[i])
{
cout<<c;
flag=0;
}else
errors++;
}
}
end = clock();
double duration=(double(end-start))/((double)CLOCKS_PER_SEC);
system("cls");
for(i=0;i<10;i++)
{
cout<<"Processing Data";
cout<<"/";
for(int j=0;j<10000000;j++);
system("cls");
cout<<"Processing Data";
cout<<"-";
for(int j=0;j<10000000;j++);
system("cls");
cout<<"Processing Data";
cout<<"\\";
for(int j=0;j<10000000;j++);
system("cls");
cout<<"Processing Data";
cout<<"|";
for(int j=0;j<10000000;j++);
system("cls");
}
cout<<"\nTotal Time - "<<duration<<" secs!!\n";
cout<<"\nMistakes made- "<<errors;
for(long j=0;j<100000000;j++);
cout<<"\nPress Any Key to See the Hall of Fame....";
getch();
system("cls");
writeScores(duration);
dispScores();
cin>>i;
return 0;
}
#include<windows.h>
#include<string>
#include<vector>
using namespace std;
HWND hwnd;
MSG msg;
WNDCLASSEX wndclass;
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM );
PAINTSTRUCT ps;
HDC hdc;
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
LOGBRUSH lb;
lb.lbStyle=BS_SOLID;
lb.lbColor=RGB(125,123,123);
HBRUSH BlueBrush=CreateBrushIndirect(&lb);
wndclass.cbClsExtra=0;
wndclass.cbSize=sizeof(wndclass);
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)BlueBrush;
wndclass.hCursor=LoadCursor(0,IDC_ARROW);
wndclass.hIcon=LoadIcon(0,IDI_APPLICATION);
wndclass.hIconSm=LoadIcon(0,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WndProc;
wndclass.lpszClassName="Wind";
wndclass.lpszMenuName=0;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
RegisterClassEx(&wndclass);
hwnd=CreateWindow("Wind","Windo",WS_HSCROLL|WS_VSCROLL,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,nShowCmd);
UpdateWindow(hwnd);
ZeroMemory(&msg,sizeof(msg));
while(GetMessage(&msg,0,0,0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
struct tLine {
POINT P0;
POINT P1;
};
vector<tLine> aLines;
tLine tLines;
bool mousedown=true;
LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM Wparam,LPARAM Lparam)
{
switch(msg) {
case WM_LBUTTONDOWN:
tLines.P0.x=LOWORD(Lparam);
tLines.P0.y=HIWORD(Lparam);
SetCapture(hwnd);
mousedown = true;
return 0;
case WM_LBUTTONUP:
ReleaseCapture();
mousedown=false;
tLines.P1.x=LOWORD(Lparam);
tLines.P1.y=HIWORD(Lparam);
aLines.push_back(tLines);
return 0;
case WM_MOUSEMOVE:
if(mousedown) {
InvalidateRect(hwnd, 0, true);
hdc=BeginPaint(hwnd,&ps);
MoveToEx(hdc,tLines.P0.x,tLines.P0.y,0);
LineTo(hdc,LOWORD(Lparam),HIWORD(Lparam));
EndPaint(hwnd,&ps);
}
for(int i=0;i<aLines.size();i++) {
InvalidateRect(hwnd, 0, false);
hdc=BeginPaint(hwnd,&ps);
MoveToEx(hdc,aLines[i].P0.x,aLines[i].P0.y,0);
LineTo(hdc,aLines[i].P1.x,aLines[i].P1.y);
EndPaint(hwnd,&ps);
}
return 0;
case WM_RBUTTONDOWN:
hdc=BeginPaint(hwnd,&ps);
InvalidateRect(hwnd,0,true);
aLines.clear();
EndPaint(hwnd,&ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_KEYDOWN:
if(Wparam==VK_ESCAPE) {
if(MessageBox(0,"Are you sure you want to exit?","Message",MB_YESNO)==IDYES){
PostQuitMessage(0);
return 0;
}
}
break;
}
return DefWindowProc(hwnd,msg,Wparam,Lparam);
}