0% found this document useful (0 votes)
29 views3 pages

Computer Programming Theory: Task 1: Array As A Part of Structure. Code

The document discusses two tasks involving arrays and structures in C++. Task 1 defines a structure called Student containing name, enrollment, number of courses, and department. It then declares an array of Students and inputs data for multiple students, outputting the stored data. Task 2 defines a User structure containing user ID and password, declares an array of Users, passes it to a function, and uses it to check user login credentials by comparing entered values to stored values in the array.

Uploaded by

waleed info
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)
29 views3 pages

Computer Programming Theory: Task 1: Array As A Part of Structure. Code

The document discusses two tasks involving arrays and structures in C++. Task 1 defines a structure called Student containing name, enrollment, number of courses, and department. It then declares an array of Students and inputs data for multiple students, outputting the stored data. Task 2 defines a User structure containing user ID and password, declares an array of Users, passes it to a function, and uses it to check user login credentials by comparing entered values to stored values in the array.

Uploaded by

waleed info
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/ 3

Abdullah Abdul Wahid Computer Programming 02-134192-015

Computer Programming Theory

Task 1: Array as a part of Structure.


CODE:
struct Student
{
string Name;
string Enrollment;
int NoOfCourses;
string Dept;

};

int main()
{
Student BahriaUni[100];
int Delimit = 100;
cout << "Note: Enter quit in place of name at any point to stop inputting data.
\n\n";
for (int i = 0; i < 100; i++)
{

cout << "Enter Name of Student Number " << i + 1 << " : ";
cin >> BahriaUni[i].Name;
if (BahriaUni[i].Name != "quit")
{
cout << "Enter Enrollment of Student Number " << i + 1 << " : ";
cin >> BahriaUni[i].Enrollment;
cout << "Enter Number of Courses of Student Number " << i + 1 <<
" : ";
cin >> BahriaUni[i].NoOfCourses;
cout << "Enter Department of Student Number " << i + 1 << " : ";
cin >> BahriaUni[i].Dept;
}
else
{
Delimit = i;
break;
}
}
cout << "\n\n\nName\tEnrollment\tNo. Of Course\tDepartment\n";
for (int i = 0; i < Delimit; i++)
{
cout << BahriaUni[i].Name << "\t" << BahriaUni[i].Enrollment << "\t\t"
<< BahriaUni[i].NoOfCourses << "\t" << BahriaUni[i].Dept;
cout << "\n";
}

}
Abdullah Abdul Wahid Computer Programming 02-134192-015

OUTPUT:

Task 2: Structure as a function argument.


CODE:
#include <iostream>
#include <string>
using namespace std;
struct User
{
string UserID;
string Pass;
};
void FbLogin(User FbLogin[2]);
int main()
{
User FbLoginDetails[2];

FbLoginDetails[0].UserID = "Abdullah";
FbLoginDetails[0].Pass = "123456789";
FbLoginDetails[1].UserID = "Ahmed";
FbLoginDetails[1].Pass = "12345678";

FbLogin(FbLoginDetails);
}

void FbLogin(User FbLogin[2])


{
string User, Pass;
bool Flag=false;
cout << "Enter your username: ";
cin >> User;
cout << "Enter your password: ";
cin >> Pass;
for (int i = 0; i < 2; i++)
{
if (FbLogin[i].UserID == User && FbLogin[i].Pass == Pass)
{
Flag = true;
Abdullah Abdul Wahid Computer Programming 02-134192-015

break;
}
}
if (Flag == true)
cout << "Logged in! \n";
else
cout << "Invalid credentials! \n";
}

OUTPUT:

You might also like