Banner Ad

    A    L    W    A    Y    S           D    E    S    I    R    E           T    O           L    E    A    R    N           S    O    M    E    T    H    I    N    G           U    S    E    F    U    L   

Technology and business

technology and business are becoming inextricably interwoven. I don't think anybody can talk meaningfully about one without the talking about the other

Arthur C. Clarke

Any sufficiently advanced technology is indistinguishable from magic.

Bill Gates is a very rich man today... and do you want to know why? The answer is one word: versions.

Softwares

Defect-free software does not exist.

Technology is like a fish. The longer it stays on the shelf, the less desirable it becomes.

Monday, May 9, 2011

2009 IPE-1a question 3

#include <iostream>
using namespace std;
void input(double &BasicSalery, double &overtimeHours);
double calcSal(double BasicSalery,double overtimeAmount);
double calcOT(double overtimeHours);

int main()
{
double BasicSalery, overtimeHours, TotalSalery, overtimeAmount, PayRate, highest=0;
char ch = 'y';
while(ch=='y' || ch=='Y')
{
input(BasicSalery,overtimeHours);
overtimeAmount = calcOT(overtimeHours);
TotalSalery = calcSal(BasicSalery,overtimeAmount);

if(highest<TotalSalery)
highest = TotalSalery;

cout << "Do you have more data ? (y/n) : ";
        cin >> ch;
        while (ch != 'Y' && ch != 'N' && ch != 'y' && ch != 'n')
        {
             cout << "Please Type 'y' or 'n'\nDo you have more data ? (y/n) : ";
               cin >> ch;
        }

}
cout << "Highest Total Salery is " << highest << endl;
return 0;
}

void input (double &BasicSalery, double &overtimeHours)
{
cout << "Enter your basic salery : ";
cin >> BasicSalery;
cout << "Enter OT Hours : ";
cin >> overtimeHours;
while (overtimeHours<0 || overtimeHours>100)
{
cout << "Invalid OT Hours\nEnter OT Hours : ";
cin >> overtimeHours;
}
}
double calcSal(double BasicSalery,double overtimeAmount)
{
cout << "Your Total Salery is " << BasicSalery + overtimeAmount << " Rs." << endl;
return (BasicSalery + overtimeAmount);
}

double calcOT(double overtimeHours)
{
double PayRate;
if(overtimeHours<=20)
                PayRate = 100.0;
        else if(overtimeHours<=40 && overtimeHours>20)
                PayRate = 150.0;
        else if(overtimeHours<=60 && overtimeHours>40)
                PayRate = 200.0;
        else if (overtimeHours<=80 && overtimeHours>60)
                PayRate = 250.0;
        else
                PayRate = 300.0;
return overtimeHours*PayRate;
}

2009 IPE-1a question 4

#include <iostream>
#include <iomanip>
using namespace std;
void inputData(float A[][3],int numberOfRows);
void calcRowTotal(float A[][3], float B[][3], float C[][1], int numberOfRows);
void copyMatrix(float A[][3], float B[][3], int numberOfRows);
void print(float A[][3],float B[][3],float C[][3], int numberOfRows);
int main()
{
float A[3][3], B[3][3],C[3][1],C1[3][3];
inputData(A,3);
copyMatrix(A,B,3);
calcRowTotal(A,B,C,3);
print(A,B,C1,3);

return 0;
}

void inputData(float A[][3],int numberOfRows)
{
for(int i=0; i<numberOfRows; i++)
for(int j=0; j<3; j++)
{
cout << "Enter Data " << i+1 << "," << j+1 << " : ";
cin >> A[i][j];
}
}

void copyMatrix(float A[][3], float B[][3], int numberOfRows)
{
for (int i=0; i<numberOfRows; i++)
for(int j=0; j<3; j++)
B[i][j] = A[i][j];
}

void calcRowTotal(float A[][3], float B[][3], float C[][1], int numberOfRows)
{
for (int i=0; i<numberOfRows; i++)
C[i][1] = A[i][0]+A[i][1]+A[i][2]+B[i][0]+B[i][1]+B[i][2];

cout << setw(9) << "Matrix1" << setw(20) << "Matrix2" << setw(20) << "Result\n";
for (int i=0; i<numberOfRows; i++)
{
for (int j=0; j<3; j++)
cout << setw(3) << A[i][j];
cout << setw(11) << " ";
for(int j=0; j<3; j++)
cout << setw(3) << B[i][j];
cout << setw(17) << C[i][1] << endl;
}

}

void print(float A[][3],float B[][3],float C[][3], int numberOfRows)
{
for (int i=0; i<numberOfRows; i++)
for (int j=0; j<3; j++)
C[i][j] = A[i][j]+B[i][j];
cout << endl << setw(9) << "Matrix1" << setw(20) << "Matrix2" << setw(20) << "Result\n";
        for (int i=0; i<numberOfRows; i++)
        {
                for (int j=0; j<3; j++)
                        cout << setw(3) << A[i][j];
                cout << setw(11) << " ";
                for(int j=0; j<3; j++)
                        cout << setw(3) << B[i][j];
cout << setw(11) << " ";
for(int j=0; j<3; j++)
cout << setw(3) << C[i][j];
cout << endl;
}
}

2009 IPE-1a question 1

#include <ncurses.h>
void printrow(int r, int c, int colour);
void printcol(int r, int c, int colour);
int main()
{
initscr();
int rr,rc,cr,cc,ch,colour;
keypad(stdscr, TRUE);
noecho();
ch = getch();
while(ch!='q' && ch!='Q')
{
while(ch!=KEY_RIGHT && ch!=KEY_UP && ch!=KEY_LEFT && ch!=KEY_DOWN)
{
move(5,20);
printw("Wrong key: press Arrow Keys");
ch=getch();
clear();
}

if (ch==KEY_RIGHT)
{
colour=1;
rr=5;
cr=3;
rc=20;
cc=28;
}

else if (ch==KEY_UP)
{
colour=2;
rr=5;
                        cr=5;
                        rc=20;
                        cc=24;
}
else if(ch==KEY_LEFT)
{
colour=3;
rr=7;
                        cr=5;
                        rc=20;
                        cc=20;
}
else if(ch==KEY_DOWN)
{
colour=4;
rr=9;
                        cr=5;
                        rc=16;
                        cc=20;
}
printrow(rr,rc,colour);
printcol(cr,cc,colour);
ch=getch();
clear();
}
endwin();
return 0;

}

void printrow(int r, int c, int colour)
{
start_color();
         init_pair(1,COLOR_RED,COLOR_BLUE);
         init_pair(2,COLOR_YELLOW, COLOR_GREEN);
         init_pair(3,COLOR_WHITE,COLOR_MAGENTA);
         init_pair(4,COLOR_YELLOW,COLOR_BLACK);
for(int i=0; i<10; i++)
{
attrset(COLOR_PAIR(colour));
move(r,c+i);
printw("*");
move(r+1,c+i);
printw("*");
}
}

void printcol(int r, int c,int colour)
{
start_color();
         init_pair(1,COLOR_RED,COLOR_BLUE);
         init_pair(2,COLOR_YELLOW, COLOR_GREEN);
         init_pair(3,COLOR_WHITE,COLOR_MAGENTA);
         init_pair(4,COLOR_YELLOW,COLOR_BLACK);
for (int i=0; i<6; i++)
{
attrset(COLOR_PAIR(colour));
move(r+i,c);
printw("*");
move(r+i,c+1);
printw("*");
}
}

2010 Final IPE_UNIXC_-1152b question 3

#include <iostream>
using namespace std;
void rotatebackward(int array[],int size);
int main()
{
int value[6]={250,100,150,350,500,400};

rotatebackward(value,6);
cout<<"position             "<<"value"<<endl;
for(int i=6;i<12;i++)
{cout<<i-5<<"                  "<<value[i]<<endl;




}



return 0;
}
void rotatebackward(int array[],int size)
{
for(int i=2;i<6;i++)
{
array[i+6]=array[i-2];
}
array[6]=array[4];
array[7]=array[5];




}

2010 Final IPE_UNIXC_-1152b question 2

#include <ncurses.h>
int main()
{
int y,x,c=0;
initscr();
start_color();
init_pair(1,0,2);
init_pair(2,1,3);
init_pair(3,7,5);
init_pair(4,0,1);
init_pair(5,7,4);

attrset(COLOR_PAIR(1));
for(y=10;y<=18;y++)
{
c++;
for(x=20-c;x==20-c;x--)
{
move(y,x);
printw("*");
}
for(int a=0;a<=30000000;a++)
{}
refresh();
}
attrset(COLOR_PAIR(2));
                     
                for(x=12;x<20;x++)
                {
                move(18,x);
                printw("*");
             
                for(int a=0;a<=30000000;a++)
                {}
                refresh();
        }
attrset(COLOR_PAIR(3));
        for(y=18;y>=10;y--)
        {
                move(y,19);
                printw("*");
             
                for(int a=0;a<=30000000;a++)
                {}
                refresh();
        }
attrset(COLOR_PAIR(3));
        for(y=10;y>=3;y--)
        {
                move(y,19);
                printw("*");

                for(int a=0;a<=30000000;a++)
                {}
                refresh();
        }
attrset(COLOR_PAIR(4));

                for(x=19;x<=27;x++)
                {
                move(3,x);
                printw("*");

                for(int a=0;a<=30000000;a++)
                {}
                refresh();
                }
attrset(COLOR_PAIR(5));
c=0;
        for(y=3;y<=10;y++)
        {

                c++;
                for(x=28-c;x==28-c;x--)
                {
                move(y,x);
                printw("*");
                }
                for(int a=0;a<=30000000;a++)
                {}
                refresh();
        }






getch();
endwin();

return 0;
}

2010 Final IPE_UNIXC_-1152b question 1

//employee.h

#include <iostream>
using namespace std;
#include <cstring>


class employee
{
private:
int empno;
char name[50];
char address[50];
int monthlyothours[3];
double monthlyotpayments[3];
double averageotpayment;

public:
employee(int pempno,char pname[],char paddress[]);
void inputmonthlyhours();
void claculatemonthlyotpayments();
void calculateaverageotpayment();
void displayemployeedetails();


};

//employee.cpp
#include "employee.h"
#include <iostream>
using namespace std;
#include <cstring>

employee :: employee(int pempno,char pname[],char paddress[])
{
empno=pempno;
strcpy(name,pname);
strcpy(address,paddress);
}

void employee::inputmonthlyhours()
{
for(int i=0;i<3;i++)
{
cout<<"Enter monthly ot hours for month  "<<i+1<<"   ";
cin>>monthlyothours[i];
}
}
void employee::claculatemonthlyotpayments()
{
for(int i=0;i<3;i++)
{
int ot=monthlyothours[i];
if(ot>=0&&ot<=15)
{
monthlyotpayments[i]=ot*100;

}
else if(ot>=16&&ot<=40)
{
monthlyotpayments[i]=ot*150;
}
else if(ot>40)
{
monthlyotpayments[i]=ot*250;
}
}

}

void employee::calculateaverageotpayment()
{ double sum=0;
for(int i=0;i<3;i++)
{
sum=sum+monthlyotpayments[i];

}
averageotpayment=sum/2.0;

}
void employee::displayemployeedetails()
{

cout<<"Employee No  "<<empno<<endl;
cout<<"Name         "<<name<<endl;
cout<<"Address      "<<address<<endl<<endl;

cout<<"\t\t\t"<<"month 1   "<<"month 2   "<<"month 3   "<<endl;
cout<<"Monthly ot hours        "<<monthlyothours[0]<<"         "<<monthlyothours[1]<<"          "<<monthlyothours[2]<<endl;
cout<<"Monthly ot payments     "<<monthlyotpayments[0]<<"        "<<monthlyotpayments[1]<<"       "<<monthlyotpayments[2]<<endl;
cout<<"Monthly average payments   "<<averageotpayment<<endl;
}

//paper2b _l.cpp
#include "employee.h"
#include <iostream>
using namespace std;
int main()
{
employee emp1(3789,"Ranjith Perera","51,Galle Road,Dehiwala.");
emp1.inputmonthlyhours();
emp1.claculatemonthlyotpayments();
emp1.calculateaverageotpayment();
emp1.displayemployeedetails();




return 0;
}

2010 Final IPE_UNIXC_-1151b question 4

#include <iostream>
using namespace std;
float findmin(float array[],int size);
int main()
{
      int citycodes[5];
      float avgtemp[5];
      float mk1,mk2;
      for(int i=0;i<5;i++)
      {
      cout<<"Enter city code  : ";
      cin>>citycodes[i];
      cout<<"Enter tempreature reading 1  = " ;
      cin>>mk1;
      cout<<"Enter tempreature reading 2  = " ;
        cin>>mk2;
      avgtemp[i]=(mk1+mk2)/2.0;
      }

      float min=findmin(avgtemp,5);
      cout<<"Minimum average tempreature is  =  "<<min<<endl;
      for(int a=0;a<5;a++)
      {
      if(min==avgtemp[a])
      cout<<"Minimum tempreature city code is =  "<<citycodes[a]<<endl;
     
      }


      return 0;
}
float findmin(float array[],int size)
{    
      float min=10000;
      for(int c=0;c<size;c++)
      {
      if(array[c]<=min)
      {
      min=array[c];
     
      }
      else
      {
      min=min;
      }
      }
      return min;


}




 

Related Posts Plugin for WordPress, Blogger...

your comments