0% found this document useful (0 votes)
25 views

Itp Assignment 4

The document contains code for 3 C++ programs written as answers to assignment questions. Question 1 defines functions to input a student's name, address, and degree using character arrays and getline. Question 2 defines a function to count the number of vowels in a given string. Question 3 defines a function to calculate a student's GPA based on an array of marks, by assigning grade points based on marks ranges.

Uploaded by

Hassan Shabbir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Itp Assignment 4

The document contains code for 3 C++ programs written as answers to assignment questions. Question 1 defines functions to input a student's name, address, and degree using character arrays and getline. Question 2 defines a function to count the number of vowels in a given string. Question 3 defines a function to calculate a student's GPA based on an array of marks, by assigning grade points based on marks ranges.

Uploaded by

Hassan Shabbir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Name: Hassan Shabbir

REG# BSE183137

ASSIGNMENT#4

Question#2
#include<iostream>

using namespace std;

void swap(int&x,int&y)

int temp;

temp=x;

x=y;

y=temp;

int main()

int a,b;

cout<<"enter marks of a=";

cin>>a;

cout<<"enter marks of b=";

cin>>b;

swap(a,b);

cout<<"After swapping"<<endl;

cout<<"a="<<a;

cout<<"b="<<b;
system("pause");

return 0;

Question1
#include<iostream>

using namespace std;

void intro()

char name[10],address[20],degree[10],sto;

cout<<"enter your name";

cin.getline(name,10,'*');

cout<<"enter your address";

cin.getline(address,20,'@');

cout<<"enter your degree";

cin.getline(degree,10,'£');

cout<<"name of student"<<name<<endl;

cout<<"address of student"<<address<<endl;

cout<<"degree of student"<<degree<<endl;

int main()

intro();

system("pause");

Question 3
#include<iostream>

using namespace std;


float displayGPA(int marks[],int size);

int main()

int a[5]={56,67,78,89,99};

cout<<"your GPA is="<<displayGPA(a,5);

system("pause");

float displayGPA(int marks[],int size=5)

float q=0.0;

for(int s=0; s<size; s++)

if(marks[s]>90)

q=q+(3*4.0);

else if(marks[s]<=90 && marks[s]>85)

q=q+(3*3.7);

else if(marks[s]<=85 && marks[s]>80)

q=q+(3*3.3);

else if(marks[s]<=80 && marks[s]>75)

q=q+(3*3.0);
}

else if(marks[s]<=75 && marks[s]>70)

q=q+(3*2.7);

else if(marks[s]<=70 && marks[s]>65)

q=q+(3*2.3);

else if(marks[s]<=65 && marks[s]>60)

q=q+(3*2.0);

else if(marks[s]<=60 && marks[s]>55)

q=q+(3*1.7);

else if(marks[s]<=55 && marks[s]>50)

q=q+(3*1.3);

else if(marks[s]<=50 && marks[s]>45)

q=q+(3*1.0);

else if(marks[s]<=45 && marks[s]>40)

{
q=q+(3*0.7);

else

q=q+0.0;

q=q/15;

return q;

system("pause");

Question2
#include<iostream>

using namespace std;

int vowels(char array[],int size);

int main()

int size=20;

char arr[20];

cout<<"enter a string vowels:";

cin.getline(arr,20,'#');

cout<<endl;

cout<<"vowels in the array are:"<<vowels(arr,size)<<endl;

system("pause");

return 0;

int vowels(char array[],int size)

int count=0;
for (int i=0;i<size;i++)

char ch=(array[i]);

if (ch=='A' ||ch=='E' ||ch=='I' ||ch=='O'


||ch=='U'||ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')

count++;

return count;

You might also like