Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторная работа №15 / 1 / 1
.cpp// 1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#define INFO_BUFFER_SIZE 32768
using namespace std;
void printError(TCHAR* msg);
void summary(void);
void disks(void);
void disktype(void);
void diskinfo(void);
int _tmain(int argc, _TCHAR* argv[])
{
unsigned int a=0,b=0,c=0;
system("cls");
cout<<" The first Laboratory work\n ";
cout<<" Taking information about computer system\n ";
getch();
do
{
system("cls");
cout<<"\n Menu\n\n\n";
cout<<" 1.Computer summary\n\n";
cout<<" 2.List of disks in the system\n\n";
cout<<" 3.Information about separate disk\n\n";
cout<<" 4.Exit\n\n";
cout<<" Vibirite punkt menu: ";
cin>>a;
if(a<0||a>4)
{
cout<<"\n Vi dopustili oshibku!!!(1-4)";
cout<<"\n Nagmite lubuu klavishu\n";
getch();
}
switch(a)
{
case 1:
{
summary();break;
}
case 2:
{
disks();
getch();
break;
}
case 3:
{
system("cls");
cout<<"\n\n1.Disk type\n\n";
cout<<"2.Disk space\n\n";
cout<<"3.Exit\n\n";
cout<<" Vibirite punkt menu: ";
cin>>c;
if(c<0||c>3)
{
cout<<"\n Vi dopustili oshibku!!!(1-3)";
cout<<"\n Nagmite lubuu klavishu\n";
getch();
}
switch(c)
{
case 1:
{
disktype();break;
}
case 2:
{
diskinfo();break;
}
}
}
}
}
while(a!=4);
return 0;
}
void printError(TCHAR* msg )
{
DWORD eNum;
TCHAR sysMsg[256];
TCHAR* p;
eNum = GetLastError();
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,NULL,eNum,MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),sysMsg,256,NULL);
p=sysMsg;
while((*p>31)||(*p==9))
++p;
do
{
*p--=0;
}
while((p>=sysMsg)&&((*p=='.')||(*p<33)));
cout<< "\n WARNING: %s failed with error %d (%s)", msg, eNum, sysMsg ;
getch();
}
void summary(void)
{
system("cls");
TCHAR infoBuf[INFO_BUFFER_SIZE];
DWORD bufCharCount = INFO_BUFFER_SIZE;
SYSTEM_INFO siSysInfo;
GetSystemInfo(&siSysInfo);
cout<<"\nHardware information:\n\n";
cout<<"\nProcessor Architecture:";
switch(siSysInfo.wProcessorArchitecture)
{
case PROCESSOR_ARCHITECTURE_INTEL:cout<<"Intel Processor Architecture";break;
case PROCESSOR_ARCHITECTURE_UNKNOWN:cout<<"Unknown Processor Architecture";break;
}
cout<<"\nNumber of processors:"<<siSysInfo.dwNumberOfProcessors;
cout<<"\nPage size:"<<siSysInfo.dwPageSize;
cout<<"\nProcessor type:";
switch(siSysInfo.dwProcessorType)
{
case 586:cout<<"Intel Pentium Pro";break;
//case PROCESSOR_ARCHITECTURE_UNKNOWN:cout<<"Unknown Processor Architecture";break;
}
cout<<"\nMinimum application address:"<<siSysInfo.lpMinimumApplicationAddress;
cout<<"\nMaximum application address:"<<siSysInfo.lpMaximumApplicationAddress;
cout<<"\nGranularity:"<<siSysInfo.dwAllocationGranularity;
cout<<"\nActive processor mask:"<<siSysInfo.dwActiveProcessorMask;
cout<<"\nProcessor level:";
switch(siSysInfo.wProcessorLevel)
{
case 3:cout<<"Intel 80386";break;
case 4:cout<<"Intel 80486";break;
case 5:cout<<"Pentium";break;
default:cout<<"Other type of processor";
}
cout<<"\nProcessor revision:"<<siSysInfo.wProcessorRevision;
if(!GetComputerName(infoBuf,&bufCharCount))
printError("GetComputerName");
cout<<"\nComputer name:"<<infoBuf;
getch();
}
void disks(void)
{
DWORD DISKS=0;
system("cls");
DISKS=GetLogicalDrives();
cout<<"\nDisks on the system:\n\n";
unsigned long mask=1;
int k=1;
for(int i=0;i<32;i++)
{
if(DISKS&mask)
{
printf("%d)%c\n",k,i+65);
k++;
}
mask<<=1;
}
}
void disktype(void)
{
UINT DISKTYPE=0;
char str[5],q;
do
{
disks();
cout<<"\nChoose the disk to return information about\n";
cout<<"Format of input: C:\\,A:\\,etc. ";
fflush(stdin);
gets(str);
DISKTYPE=GetDriveType(str);
switch(DISKTYPE)
{
case DRIVE_UNKNOWN:cout<<"The drive type cannot be determined.";break;
case DRIVE_NO_ROOT_DIR:cout<<"The root path is invalid. For example, no volume is mounted at the path.";break;
case DRIVE_REMOVABLE:cout<<"The disk can be removed from the drive.";break;
case DRIVE_FIXED:cout<<"The disk cannot be removed from the drive.";break;
case DRIVE_REMOTE:cout<<"The drive is a remote (network) drive.";break;
case DRIVE_CDROM:cout<<"The drive is a CD-ROM drive.";break;
case DRIVE_RAMDISK:cout<<"The drive is a RAM disk.";break;
}
getch();
do
{
cout<<"\nDo yo want to repeat?(y/n)";
cin>>q;
if(q!='y'&&q!='Y'&&q!='N'&&q!='n')
{
cout<<"You make a mistake!!!";
getch();
}
}
while(q!='y'&&q!='Y'&&q!='N'&&q!='n');
}
while(q!='n'&&q!='N');
}
void diskinfo(void)
{
char q;
system("cls");
BOOL fResult1;
char pszDrive[100];
DWORD dwSectPerClust,dwBytesPerSect,dwFreeClusters,dwTotalClusters;
do
{
disks();
cout<<"\nSpecify a directory on the disk of interest\n";
cout<<"Format of input: \\MyServer\\MyShare\\,etc. ";
fflush(stdin);
gets(pszDrive);
fResult1=GetDiskFreeSpace(pszDrive,&dwSectPerClust,&dwBytesPerSect,&dwFreeClusters, &dwTotalClusters);
if(fResult1)
{
cout<<"\nAttantion:this information considers per-user quotas(if they are in use)";
cout<<"\nSectors per cluster:"<<dwSectPerClust;
cout<<"\nBytes per sector:"<<dwBytesPerSect;
cout<<"\nTotal number of free clusters on the disk:"<<dwFreeClusters;
cout<<"\nTotal number of clusters on the disk:"<<dwTotalClusters;
}
else
{
cout<<"Error!!!";
cout<<"Verify format of input";
getch();
}
do
{
cout<<"\nDo yo want to repeat?(y/n)";
cin>>q;
if(q!='y'&&q!='Y'&&q!='N'&&q!='n')
{
cout<<"You make a mistake!!!";
getch();
}
}
while(q!='y'&&q!='Y'&&q!='N'&&q!='n');
}
while(q!='n'&&q!='N');
}