You are on page 1of 5

PROGRAMMING FUNDAMENTALS

LAB
FINAL EXAMINATION
FATEH HAIDER
19-SE-40
QUESTION:01
Write output of following codes?
a)
int main() {
string line= "p2'ro@gram84iz./";
for(int i = 0; i < line.size(); ++i)
{
if (!((line[i] >= 'a' && line[i]<='z') ||
(line[i] >= 'A' && line[i]<='Z')))
{ PROGRAM OUTPUT:
line[i] = '\0'; Output String: p ro gram
} iz
}
cout << "Output String: " << line;
return 0;
}
b)
int main() {
int a=2;
int b=1; PROGRAM OUTPUT:
int foo[5]; 2
foo[0] = a; 75
cout<<foo[0]<<endl; -272632400
foo[a] = 75; 80
cout<<foo[a]<<endl;
b = foo [a+2];
cout<<b<<endl;
foo[foo[a]] = foo[2] + 5;
cout<<foo[foo[a]]<<endl;
}
c) int main()
{
int firstvalue = 5, secondvalue = 15;
int * p1, * p2;
p1 = &firstvalue; // p1 = address of
firstvalue PROGRAM OUTPUT:
p2 = &secondvalue; // p2 = address of
secondvalue p1 = 5 p2=15
cout<<" p1 = "<<*p1<<" " <<" p2=
"<<*p2<<endl<<endl; *p1 = 10firstvalue=10
*p1 = 10;
cout<<"*p1 = " <<*p1<<" *p2 = *p1sonow p2 = 10 and secondvalue=10
"<<"firstvalue="<<firstvalue<<endl<<endl;
*p2 = *p1;
cout<<"*p2 = *p1 so now p2 = "<< *p2
<<" and secondvalue
="<<secondvalue<<endl<<endl;
return 0;
}

QUESTION:02
Create a C++ program that make use of both concepts i.e. Array of
structure and array within structure by using following guidelines:
1. Create an Array of 5 Structures of Student Records
2. Each structure must contain:
a. An array of Full Name of Student
b. Registration Number in proper Format i.e 18-SE-24
c. Array of Marks of 3 subjects
d. Display that information of all students in Ascending order using
Name
e. Search a particular student and update its Marks of any particular
subject.
CODE:
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
struct student
{
char name[100];
char Reg_No[10];
float marks[3];
}
s[5];
void Alphabatically(student s[5])
{
for(int i=0;i<4;i++)
for(int j=i+1;j<5;j++)
if(strcmp(s[i].name,s[j].name)>0)
swap(s[i],s[j]);
}
int main()
{
A:
int i,j,a;
do
{
cout<<"\t\t\t=============================";
cout<<"\n\t\t\t MAIN MENU";
cout<<"\n\t\t\t=============================";
cout<<"\n\n\t\t\t1. Enter Students Record"<<endl;
cout<<"\n\t\t\t2. Display Students Record"<<endl;
cout<<"\n\t\t\t3. Modify Student Record"<<endl;
cout<<"\n\t\t\t4. Exit"<<endl;
cin>>a;
switch(a)
{
case 1:
for(i=0;i<5;i++)
{
cout<<endl;
cout<<"\n Enter Record of Student No : "<<i+1;
fflush(stdin);
cout<<"\n Enter Student Name : ";
cin.get(s[i].name,100);
fflush(stdin);
cout<<" Enter Registration No : ";
cin.get(s[i].Reg_No,10);
for(j=0;j<3;j++)
{
cout<<" Enter Marks "<<j+1<<" Subject : ";
cin>>s[i].marks[j];
}
}
Alphabatically(s);
system("pause");
goto A;
case 2:
cout<<"\n\n Display Students Records";
cout<<"\n\n Names "<<"\t"<<" Reg_NO "<<"\t"<<" Marks of
subjects ";
for(i=0;i<5;i++)
{
cout << "\n\n"<< s[i].name<<"\t"<< s[i].Reg_No;
for(j=0;j<3;j++)
cout<<"\t\t"<< s[i].marks[j];
}
cout<<endl;
goto A;
case 3:
char name[100];
int n = 0;
fflush(stdin);
cout << "\n\nEnter Name of student to Modify the record: ";
cin.get( name,100);
for (int i = 0; i < 5; i++)
{
if (strcmp(s[i].name, name )==0)
{
cout<<"\n\nSelect the Subject you want to Modify(1/2/3): ";
cin>>n;
cout<<"\n\nEnter the New Marks : ";
cin>>s[i].marks[n-1];
goto A;
}
}
}
}
while(a<4);
cout<<"\n\n Exit";
}

You might also like