Cs609 Assignment No. 1 fall 2011 solution

No Comments
CS609 solution

change the names of variables if you can.
You can change color strips easily by just swapping ColorsArray elements.
you can also use a loop to show all 25 color strips and also this would be a good coding practice.its just and idea solution and work of 30 minutes. i recommend you to use loop like below
int i;
for(i = 0;i<25;i++){
//color strip code here
}
========

#include <stdio.h>
#include <windows.h>
char ColorsArray[] = {BACKGROUND_RED,BACKGROUND_GREEN,BACKGROUND_BLUE };
int main ( void )
{
HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
WORD wOldColorAttrs;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
GetConsoleScreenBufferInfo(h, &csbiInfo);
wOldColorAttrs = csbiInfo.wAttributes;
SetConsoleTextAttribute ( h, ColorsArray[0] | BACKGROUND_INTENSITY );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[0] );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[1] | BACKGROUND_INTENSITY );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[1] );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[2] | BACKGROUND_INTENSITY );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[2] );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[0] | ColorsArray[1]| BACKGROUND_INTENSITY );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[0] | ColorsArray[1] );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[0] | ColorsArray[1]| ColorsArray[2] |
BACKGROUND_INTENSITY );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[0] | ColorsArray[1]| ColorsArray[2] );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[0] | ColorsArray[2] | BACKGROUND_INTENSITY );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[0] | ColorsArray[2] );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[1] | ColorsArray[2] | BACKGROUND_INTENSITY );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[1] | ColorsArray[2] );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[1] | BACKGROUND_INTENSITY );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[1] );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[2] | BACKGROUND_INTENSITY );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[2] );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[0] | ColorsArray[1]| BACKGROUND_INTENSITY );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[0] | ColorsArray[1]| ColorsArray[2] );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[0] | ColorsArray[2] | BACKGROUND_INTENSITY );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[0] | ColorsArray[2] );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[1] | ColorsArray[2] | BACKGROUND_INTENSITY );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[1] | ColorsArray[2] );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[1] | ColorsArray[0] );
printf ( " " );
SetConsoleTextAttribute ( h, wOldColorAttrs);
system("pause");
return 0;
}
:::::::::::::::::::::::::::::::



#include <stdio.h>
#include <windows.h>
char ColorsArray[] = {BACKGROUND_RED,BACKGROUND_GREEN,BACKGROUND_BLUE };
int main ( void )
{
HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
WORD wOldColorAttrs;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
GetConsoleScreenBufferInfo(h, &csbiInfo);
wOldColorAttrs = csbiInfo.wAttributes;
SetConsoleTextAttribute ( h, ColorsArray[0] | BACKGROUND_INTENSITY );
printf ( "
" );
SetConsoleTextAttribute ( h, ColorsArray[0] );
printf ( "
" );
SetConsoleTextAttribute ( h, ColorsArray[1] | BACKGROUND_INTENSITY );
printf ( "
" );
SetConsoleTextAttribute ( h, ColorsArray[1] );
printf ( "
" );
SetConsoleTextAttribute ( h, ColorsArray[2] | BACKGROUND_INTENSITY );
printf ( "
" );
SetConsoleTextAttribute ( h, ColorsArray[2] );
printf ( "
" );
SetConsoleTextAttribute ( h, ColorsArray[0] | ColorsArray[1]| BACKGROUND_INTENSITY
);
printf ( "
" );
SetConsoleTextAttribute ( h, ColorsArray[0] | ColorsArray[1] );
printf ( "
" );
SetConsoleTextAttribute ( h, ColorsArray[0] | ColorsArray[1]| ColorsArray[2] |
BACKGROUND_INTENSITY );
printf ( "
" );
SetConsoleTextAttribute ( h, ColorsArray[0] | ColorsArray[1]| ColorsArray[2] );
printf ( "
" );
SetConsoleTextAttribute ( h, ColorsArray[0] | ColorsArray[2] |
BACKGROUND_INTENSITY );
printf ( "
" );
SetConsoleTextAttribute ( h, ColorsArray[0] | ColorsArray[2] );
printf ( "
" );
SetConsoleTextAttribute ( h, ColorsArray[1] | ColorsArray[2] |
BACKGROUND_INTENSITY );
printf ( "
" );
SetConsoleTextAttribute ( h, ColorsArray[1] | ColorsArray[2] );
printf ( "
" );
SetConsoleTextAttribute ( h, ColorsArray[1] | BACKGROUND_INTENSITY );


printf ( "
" );
SetConsoleTextAttribute ( h, ColorsArray[1] );
printf ( "
" );
SetConsoleTextAttribute ( h, ColorsArray[2] | BACKGROUND_INTENSITY );
printf ( "
" );
SetConsoleTextAttribute ( h, ColorsArray[2] );
printf ( "
" );
SetConsoleTextAttribute ( h, ColorsArray[0] | ColorsArray[1]| BACKGROUND_INTENSITY
);
printf ( "
" );
SetConsoleTextAttribute ( h, ColorsArray[0] | ColorsArray[1]| ColorsArray[2] );
printf ( "
" );
SetConsoleTextAttribute ( h, ColorsArray[0] | ColorsArray[2] |
BACKGROUND_INTENSITY );
printf ( "
" );
SetConsoleTextAttribute ( h, ColorsArray[0] | ColorsArray[2] );
printf ( "
" );
SetConsoleTextAttribute ( h, ColorsArray[1] | ColorsArray[2] |
BACKGROUND_INTENSITY );
printf ( "
" );
SetConsoleTextAttribute ( h, ColorsArray[1] | ColorsArray[2] );
printf ( "
" );
SetConsoleTextAttribute ( h, ColorsArray[1] | ColorsArray[0] );
printf ( "
" );
SetConsoleTextAttribute ( h, wOldColorAttrs);
system("pause");
return 0;
}
Next PostNewer Post Previous PostOlder Post Home

0 comments

Post a Comment