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   

Sunday, May 8, 2011

IPE Lab 11A

//lab 11a1.cpp

#include <iostream>
#include<cstring>
using namespace std;
void inputscores(int array[], int size);
int total(int array[], int size);

int main()
{
      char name[20];
      int scores[5];
      int max;

      cout << "Enter your name : ";
      cin >> name;

      cout << "Enter the numbers of scores : ";
      cin >> max;
     
      inputscores(scores,max);

      cout << name << "'s Total runs is " << total(scores,max) << endl;

      return 0;
}

void inputscores(int array[], int size)
{
      int r;
      for (r=0; r<size; r++)
      {
            cout << "Enter score " << r+1 << " : ";
            cin >> array [r];
      }
}

int total(int array[], int size)
{
      int total=0;
      for (int i=0; i<size; i++)
      {
            total = total + array[i];
      }
      return total;
}
 
//lab 11a2.cpp
#include <iostream>
#include<cstring>
using namespace std;
void inputscores(int array[], int size);
int total(int array[], int size);

int main()
{
      char name[20];
      int scores[5];
      int max;

      cout << "Enter your name : ";
      cin >> name;

      cout << "Enter the numbers of scores : ";
      cin >> max;

      if (max>5)
      {
            int *data = new int[10];
     
            inputscores(data,max);

            cout << name << "'s Total runs is " << total(data,max) << endl;
            delete []data;
      }

      else
      {
            inputscores(scores,max);

            cout << name << "'s Total runs is " << total(scores,max) << endl;
      }

      return 0;
}

void inputscores(int array[], int size)
{
      int r;
      for (r=0; r<size; r++)
      {
            cout << "Enter score " << r+1 << " : ";
            cin >> array [r];
      }
}

int total(int array[], int size)
{
      int total=0;
      for (int i=0; i<size; i++)
      {
            total = total + array[i];
      }
      return total;
}
 
//lab 11a3.cpp
#include <iostream>
#include<cstring>
using namespace std;
void inputscores(int *array, int size);
int total(int array[], int size);

int main()
{
      char name[20];
      int scores[5];
      int max;

      cout << "Enter your name : ";
      cin >> name;

      cout << "Enter the numbers of scores : ";
      cin >> max;

      if (max>5)
      {
            int *data = new int[10];
     
            inputscores(data,max);

            cout << name << "'s Total runs is " << total(data,max) << endl;
            delete []data;
      }

      else
      {
            inputscores(scores,max);

            cout << name << "'s Total runs is " << total(scores,max) << endl;
      }

      return 0;
}

void inputscores(int *array, int size)
{
      int r;
      for (r=0; r<size; r++)
      {
            cout << "Enter score " << r+1 << " : ";
            cin >> array [r];
      }
}

int total(int array[], int size)
{
      int total=0;
      for (int i=0; i<size; i++)
      {
            total = total + array[i];
      }
      return total;
}
 

0 comments:

Related Posts Plugin for WordPress, Blogger...

your comments