Pages

Saturday, July 7, 2012

2011.paper 1(a)

Question 1



#include<ncurses.h>
void triangle(int startrow,int startcol,int height);
void rectangle(int startrow,int startcol,int height,int width);
int main()
{
initscr();
start_color();

init_pair(1,COLOR_GREEN,COLOR_YELLOW);
init_pair(2,COLOR_BLACK,COLOR_WHITE);
init_pair(3,COLOR_WHITE,COLOR_MAGENTA);
init_pair(4,COLOR_YELLOW,COLOR_BLUE);

attrset(COLOR_PAIR(1));
rectangle(5,20,4,11);

attrset(COLOR_PAIR(2));
rectangle(9,11,4,27);

attrset(COLOR_PAIR(3));
triangle(5,31,4);




attrset(COLOR_PAIR(4));
triangle(14,13,3);
triangle(12,17,2);
triangle(26,13,3);
triangle(12,29,2);

getch();
endwin();
return 0;
}
void triangle(int startrow,int startcol,int height)
{
if(height==4)
{
int a=0;
for(int i=startrow;i<startrow+height;i++)
{
for(int j=startcol;j<=startcol+a;j++)
{
move(i,j);
printw("*");
}
a++;
}
}
else if(height==3)
{
int b=0;
for(int i=startrow;i<startrow+height;i++)
{
for(int j=startcol;j<=startcol+b;j++)
{
move(j,i);
printw("*");
}
b++;
}
}
else
{
int c=0;
for(int i=startrow+height;i>startrow;i--)
{
for(int j=startcol;j<=startcol+c;j++)
{
move(i,j);
printw("*");
}
c++;
}

}
}

void rectangle(int startrow,int startcol,int height,int width)
{
for(int i=startrow;i<startrow+height;i++)
{
for(int j=startcol;j<startcol+width;j++)
{
move(i,j);
printw("*");
}
}
}




Question 2

// Header File

#include<iostream>
#include<cstring>

using namespace std;

class book
{
private :
int bookNo;
char type[30];
float UnitPrice;
int ReOrderLevel=10;
int StockInHand;

public:

book(int pbookNo,const char ptype[],double pUnitPrice,int pStockInHand);
void placeOrder(int pbookNo ,int Quantity);
void print();
};


---------------------------------------------------------------------------------------------------------------
//cpp File



#include "book.h"
book::book(int pbookNo,const char ptype[],double pUnitPrice,int pStockInHand)
{

bookNo= pbookNo;
strcpy(type,ptype);
UnitPrice=pUnitPrice;
StockInHand=pStockInHand;

}

void book::placeOrder(int pbookNo ,int Quantity)
{
int ReOrderLevel=10;

if(StockInHand<Quantity)
{
cout<<"Stock not available.Order cannot be pleced"<<endl;
}
else if(StockInHand>Quantity)
{
cout<<"order placed"<<endl;
double total=UnitPrice*Quantity;
cout<<"Total :"<<total<<endl;
}
else if (StockInHand<ReOrderLevel)
{
cout<<"Stock not enought,plece order"<<endl;
}
}

void book::print()
{

cout<<"Book no :"<<bookNo<<endl;
cout<<"Type :"<<type<<endl;
cout<<"Unit price :"<<UnitPrice<<endl;
cout<<"Stock in hand : "<<StockInHand<<endl;

cout<<"*********************************************************************************************************"<<endl;
cout<<endl;
cout<<endl;

}

----------------------------------------------------------------------------------------------------------------------------

//Main programe

#include "book.h"

int main()
{
book b1(1001,"Singular rule",58.50,50);
b1.placeOrder(1001,25);
b1.print();

book b2(1002,"Blank page",32.50,5);
b2.placeOrder(1002,10);
b2.print();

book b3(1003,"Square rule",48.00,15);
b3.placeOrder(1003,7);
b3.print();

return 0;
}

-----------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------



Question 4



#include<iostream>
#include<cstring>
using namespace std;
void input(char arr[][10],int marks[],int size);
int findtop(const char arr[][10],int size);
int main()
{

char myarray[5][10];
int mymarks[5],top;

input(myarray, mymarks, 5);
top = findtop(myarray,5);
cout <<"Top name :"<< myarray[top] << " Marks : " << mymarks[top] <<"\n";
return 0;
}
void input(char arr[][10],int marks[],int size)
{
for(int i=0;i<size;i++)
{
cout<<"Enter Name :";
cin>>arr[i];
cout<<"Enter Marks :";
cin>>marks[i];

}
}
int findtop(const char arr[][10],int size)
{
int mark=0;
for(int i=0; i<size; i++)
{
if(strcmp(arr[mark],arr[i])> 0)
mark = i;

}
return mark;
}








No comments:

Post a Comment