A non-standard C header file that contained functions specific to accessing functions of MS-DOS. There is no need to use this header file, as there are standard libraries included in all major compilers that replace the functions in DOS.H.
According to the documentation on MSDN, the following code should create an uncompressed volume texture DDS file that's 32x32x32 in size. Re-scale as you see fit. Note: a 128x128x128 RGBA texture will take up 8 MB of VRAM! #include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> #define DDSD_CAPS 0x00000001 #define DDSD_HEIGHT 0x00000002 #define DDSD_WIDTH 0x00000004 #define DDSD_PITCH 0x00000008 #define DDSD_PIXELFORMAT 0x00001000 #define DDSD_MIPMAPCOUNT 0x00020000 #define DDSD_LINEARSIZE 0x00080000 #define DDSD_DEPTH 0x00800000 #define DDPF_ALPHAPIXELS 0x00000001 #define DDPF_FOURCC 0x00000004 #define DDPF_RGB 0x00000040 #define DDSCAPS_COMPLEX 0x00000008 #define DDSCAPS_TEXTURE 0x00001000 #define DDSCAPS_MIPMAP 0x00400000 #define DDSCAPS2_CUBEMAP 0x00000200 #define DDSCAPS2_CUBEMAP_POSITIVEX 0x00000400 #define DDSCAPS2_CUBEMAP_NEGATIVEX 0x00000800 #define DDSCAPS2_CUBEMAP_POSITIVEY 0x00001000 #define DDSCAPS2_CUBEMAP_NEGATIVEY 0x00002000 #define DDSCAPS2_CUBEMAP_POSITIVEZ 0x00004000 #define DDSCAPS2_CUBEMAP_NEGATIVEZ 0x00008000 #define DDSCAPS2_VOLUME 0x00200000 int depth = 32; int width = 32; int height = 32; unsigned int header[32]; int main( int argc, char * argv[] ) { if( !argv[1] !strstr( argv[1], ".dds" ) ) { fprintf( stderr, "Usage: noise output.dds\n" ); return 1; } unsigned int cnt = width*height*depth*4; unsigned char * buf = new unsigned char[ cnt ]; while( cnt-- ) { buf[cnt] = rand()>>7; } memset( header, 0, sizeof( header ) ); header[0] = ' SDD'; header[1] = 124; header[2] = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_DEPTH | DDSD_PITCH; header[3] = height; header[4] = width; header[5] = width*4; header[6] = depth; header[19] = 32; header[20] = DDPF_RGB|DDPF_ALPHAPIXELS; header[22] = 8; header[23] = 0xff0000; header[24] = 0xff00; header[25] = 0xff; header[26] = 0xff000000; header[27] = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX; header[28] = DDSCAPS2_VOLUME; FILE * f = fopen( argv[1], "wb" ); if( !f ) { fprintf( stderr, "can't create: %s\n", argv[1] ); return 1; } fwrite( header, 4, 32, f ); fwrite( buf, 1, width*height*depth, f ); fclose( f ); fprintf( stderr, "wrote %s\n", argv[1] ); return 0; }
What to do if it says Missing before statement line 2 file Code?
If it says Missing before statement line 2 file Code you just need to include ; before the statement.
// ASSIGNMENT 3.cpp : Defines the entry point for the console application.
//
#include
"stdafx.h"
#include
"conio.h"
#include
<iostream>
using
std::fixed;
using
namespace std;
class
Account
{
public: Account( double ); // constructor initializes balance
void
credit( double ); // add an amount to the account balance bool debit( double ); // subtract an amount from the account balance
void setBalance( double ); // sets the account balance
double getBalance(); // return the account balance
private: double balance;
// data member that stores the balance
// Account constructor initializes data member balance
Account::Account(
double initialBalance )
{
// if initialBalance is greater than or equal to 0.0, set this value
// as the balance of the Account
if ( initialBalance >= 0.0 )
balance = initialBalance;
else // otherwise, output message and set balance to 0.0
{
cout <<
"Error: Initial balance cannot be negative." << endl;
balance = 0.0;
}
// end if...else
}
// end Account constructor
// credit (add) an amount to the account balance
void Account::credit( double amount )
{
balance = balance + amount;
// add amount to balance
}
// end function credit
// debit (subtract) an amount from the account balance
// return bool indicating whether money was debited
bool Account::debit( double amount )
{
if ( amount > balance ) // debit amount exceeds balance
{
cout <<
"Debit amount exceeded account balance." << endl;
return
false;
}
// end if
else // debit amount does not exceed balance
{
balance = balance - amount;
return true;
}
// end else
}
// end function debit
// set the account balance
void Account::setBalance( double newBalance )
{ balance = newBalance;
}
// end function setBalance
// return the account balance
double Account::getBalance()
{
return balance;
}
// end function getBalance
};
// end class Account
class
SavingsAccount : public Account
{
public:
// constructor initializes balance and interest rate
SavingsAccount(
double, double );
double calculateInterest(); // determine interest owed
private:
double interestRate;
SavingsAccount::SavingsAccount(
double initialBalance, double rate ) : Account( initialBalance ) // initialize base class
{
interestRate = ( rate < 0.0 ) ? 0.0 : rate;
// set interestRate
}
// end SavingsAccount constructor
// return the amount of interest earned
double SavingsAccount::calculateInterest()
{
return getBalance() * interestRate;
}
// end function calculateInterest // interest rate (percentage) earned by account
};
// end class SavingsAccount
class
CheckingAccount : public Account
{
public:
// constructor initializes balance and transaction fee
CheckingAccount(
double, double );
void
credit( double ); // redefined credit function
bool debit( double ); // redefined debit function
private:
double transactionFee; // fee charged per transaction
// utility function to charge fee
void
chargeFee();
CheckingAccount::CheckingAccount(
double initialBalance, double fee )
: Account( initialBalance )
// initialize base class
{
transactionFee = ( fee < 0.0 ) ? 0.0 : fee;
// set transaction fee
}
// end CheckingAccount constructor
// credit (add) an amount to the account balance and charge fee
void CheckingAccount::credit( double amount )
{
Account::credit( amount );
// always succeeds
chargeFee();
}
// end function credit
// debit (subtract) an amount from the account balance and charge fee
bool CheckingAccount::debit( double amount )
{
bool success = Account::debit( amount ); // attempt to debit
if
( success ) // if money was debited, charge fee and return true
{
chargeFee();
return
true;
}
// end if
else // otherwise, do not charge fee and return false
return false;
}
// end function debit
// subtract transaction fee
void CheckingAccount::chargeFee()
{
Account::setBalance( getBalance() - transactionFee );
cout <<
"$" << transactionFee << " transaction fee charged." << endl;
}
// end function chargeFee
};
// end class CheckingAccount
int
_tmain(int argc, _TCHAR* argv[])
{
Account account1( 50.0 );
// create Account object
SavingsAccount account2( 25.0, .03 );
// create SavingsAccount object
CheckingAccount account3( 80.0, 1.0 );
// create CheckingAccount object
cout << fixed << setprecision ( 2 );
// display initial balance of each object
cout <<
"account1 balance: $" << account1.getBalance() << endl;
cout <<
"account2 balance: $" << account2.getBalance() << endl;
cout <<
"account3 balance: $" << account3.getBalance() << endl;
cout <<
"\nAttempting to debit $25.00 from account1." << endl;
account1.debit( 25.0 );
// try to debit $25.00 from account1
cout <<
"\nAttempting to debit $30.00 from account2." << endl;
account2.debit( 30.0 );
// try to debit $30.00 from account2
cout <<
"\nAttempting to debit $40.00 from account3." << endl;
account3.debit( 40.0 );
// try to debit $40.00 from account3
// display balances
cout <<
"\naccount1 balance: $" << account1.getBalance() << endl;
cout <<
"account2 balance: $" << account2.getBalance() << endl;
cout <<
"account3 balance: $" << account3.getBalance() << endl;
cout <<
"\nCrediting $40.00 to account1." << endl;
account1.credit( 40.0 );
// credit $40.00 to account1
cout <<
"\nCrediting $65.00 to account2." << endl;
account2.credit( 65.0 );
// credit $65.00 to account2
cout <<
"\nCrediting $20.00 to account3." << endl;
account3.credit( 20.0 );
// credit $20.00 to account3
// display balances
cout <<
"\naccount1 balance: $" << account1.getBalance() << endl;
cout <<
"account2 balance: $" << account2.getBalance() << endl;
cout <<
"account3 balance: $" << account3.getBalance() << endl;
// add interest to SavingsAccount object account2
double interestEarned = account2.calculateInterest();
cout <<
"\nAdding $" << interestEarned << " interest to account2."<<endl;
account2.credit( interestEarned );
cout <<
"\nNew account2 balance: $" << account2.getBalance() << endl;
return 0;
}
// end main
Can a parent class access the functions of child class?
no, Parent class can not access the members of child class ,but child class can access members of parent class
When a value is read from a memory in c language and preserved this process is called?
Saving. Values can be saved by writing them to non-volatile memory such as a hard-disk file.
#include
using std::cin;
using std::cout;
using std::endl;
int main()
{
int sizeOfArray = 5;
int myArray[] = {0};
cout << "Enter elements of array" << endl;
for (int i = 0; i < sizeOfArray; i++)
{
cin >> myArray[i];
}
int sum = 0;
for (int j = 0; j < sizeOfArray; j++)
{
sum += myArray[j];
}
cout << endl << "Sum of " << sizeOfArray << " is: " << sum;
cin.get();
return 0;
}
programmer c is no more do not question or...nighty night
Write a conditional that tests for the letter the user entered, if it is Y it continues, if it's not it exits.
How do you repair the black screen on turbo c?
With conio.h you can change the background color (function textbackground).
What are the problems of low level language programming?
Low level programming language is a language that is not very abstracted from hardware layer.
Programming in low level languages usually requires manual memory management, use of pointers, and in case of assembler - CPU instructions themselves. This makes the programming much more difficult than using a high level language where these issues are taken care of for you.
However in general it is possible to write much 'tighter' code in low level languages. Where tighter means:-
smaller number of instructions
Better use of memory
Faster in execution.
Which function call Does not consume stack space?
Calling an in-line function, which is not actually a function-call.
Where system header files are stored in c?
This depends on what compiler you are using. For the most common compilers (including gcc) on a *nix system, most standard header files will be either in /usr/include or /usr/local/include. Check your compiler's documentation for how to check and/or modify the search paths.
What does printf function return?
Two possibilities: on success, it'll return the amount of characters printed. On failure, a negative number is returned.
What statement is used to skip a part of loop?
The continue statement is used to skip the balance of a loop.
What if the elements are repeated in binary search?
You will find one of them (not necessarily the first or the last).
a regular and imposing arrangement; disposition in regular lines
Difference between message oriented middleware and remote procedure call?
Feature MOM RPC
Metaphor post office like Telephone like
Cilent server
time relationships ASynchronous Synchronous
Client server
sequence No sequence server must first comes up
before the client talks to it.
Partner needed No Yes
Message filtering yes No
Load
balancing Single queue is needed Require TP monitor
implement FIFO policy
Performance Slow Fast
Style queued call return
What are the uses of sentinel value?
A sentinel value is a value that is not supposed to change. It can be allocated along with, and used before the beginning and after the ending of a region of memory to detect if the program logic modified memory outside of the intended region. Most compilers and run-time libraries will do this automatically when you do a debug compile/link.
Why does LIFO order follows in stack and why does FIFO order follows in queue?
LIFO and stack are synonyms, so are FIFO and queue.
How do you draw a cycle in a c program?
/*PROGRAM TO IMPLEMENT GAUSS-jordan method.
#include
#define MX 20
main()
{
float a[MX] [MX+1],m,p;
int i,j,k,n;
puts("\n how many equations?:");
scanf("%d",&n);
for(i=0;i<=n-1;i++)
{
printf("Give the coefficients of the equation no%d:\n",i+1);
for(j=0;j<=n;j++)
scanf("%f",&a[i][j]);
}
for(k=0;k<=n-1;k++)
{
for(i=0;i<=n-1;i++)
{
m=a[i][k]/a[k][k];
p=a[k][k];
for(j=k;j<=n;j++)
{
if(i==k)
a[i][j]=a[i][j]/p;
else
a[i][j]=a[i][j]-m*a[k][j];
}
}
}
for(i=0;i<=n-1;i++)
printf("\n X[%2d]=%5.2f",i,a[i][n]);
}