Skip to content

Commit

Permalink
String and structure
Browse files Browse the repository at this point in the history
  • Loading branch information
rakeshlinux committed Jul 16, 2018
1 parent c615000 commit e82997a
Show file tree
Hide file tree
Showing 24 changed files with 466 additions and 0 deletions.
Binary file added Notes_Assignment/Structure.pptx
Binary file not shown.
17 changes: 17 additions & 0 deletions string/array_string.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include<iostream>
#include<string.h>
using namespace std;
int main(){
char name[5][30]={
"rakesh",
"amitABCD","sumitRSTV",
"anujIKLH",
"UditPPPSSah"

};

for(int i=0;i<5;i++)
cout<<name[i][4]<<endl;
return 0;
}

Binary file added string/array_string.exe
Binary file not shown.
55 changes: 55 additions & 0 deletions structure/array_structure.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include<iostream>
using namespace std;
struct student{
int roll; //10
char name[30]; // anupam gulati
int marks[3]; // 90,78,56
int total;
char grade;
};

int main(){
student s[5];
int i;
for(i=0;i<5;i++)
{
cout<<"\n Enter roll no :";
cin>>s[i].roll;
cout<<"\n Enter name :";
fflush(stdin);
cin.getline(s[i].name,30);
cout<<"\n Enter marks obtained in first subject (100) :";
cin>>s[i].marks[0];

cout<<"\n Enter marks obtained in Second subject (100) :";
cin>>s[i].marks[1];

cout<<"\n Enter marks obtained in Third Subject (100) :";
cin>>s[i].marks[2];
}
//processing area
for(i=0;i<5;i++)
{

s[i].total = s[i].marks[0]+s[i].marks[1]+s[i].marks[2];

float per = s[i].total/3;

if(per>=90)
s[i].grade = 'A';
if(per<90 && per>=80)
s[i].grade='B';
if(per<80)
s[i].grade ='C';
}

// // output phase
for(i=0;i<5;i++){

cout<<"\n Roll No :"<<s[i].roll;
cout<<"\n Name :"<<s[i].name;
cout<<"\n Grade :"<<s[i].grade;
cout<<endl;
}
return 0;
}
34 changes: 34 additions & 0 deletions structure/call_by_ref.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// call by reference method


#include<iostream>
#include<string.h>
using namespace std;
struct student{
int roll;
char name[30];
char fname[30];
};

void change_data(student &r){
r.roll= 10;
strcpy(r.name,"rakesh");
strcpy(r.fname,"sudarshan Sharma");
}

int main(){

student s={10,"Swapnil","R.K. Sharma"};

cout<<"\n Roll :"<<s.roll;
cout<<"\n Name :"<<s.name;
cout<<"\n Father Name" <<s.fname;

change_data(s);


cout<<"\n Roll :"<<s.roll;
cout<<"\n Name :"<<s.name;
cout<<"\n Father Name" <<s.fname;
return 0;
}
Binary file added structure/call_by_ref.exe
Binary file not shown.
34 changes: 34 additions & 0 deletions structure/call_by_value.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// structure as a function parameter


#include<iostream>
#include<string.h>
using namespace std;
struct student{
int roll;
char name[30];
char fname[30];
};

void change_data(student r){
r.roll= 20;
strcpy(r.name,"rakesh");
strcpy(r.fname,"sudarshan Sharma");
}

int main(){

student s={10,"Swapnil","R.K. Sharma"};

cout<<"\n Roll :"<<s.roll;
cout<<"\n Name :"<<s.name;
cout<<"\n Father Name" <<s.fname;

change_data(s);


cout<<"\n Roll :"<<s.roll;
cout<<"\n Name :"<<s.name;
cout<<"\n Father Name" <<s.fname;
return 0;
}
Binary file added structure/call_by_value.exe
Binary file not shown.
7 changes: 7 additions & 0 deletions structure/default_assignment.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include<iostream>
using namespace std;
int main(){
int x;
cout<<x;
return 0;
}
25 changes: 25 additions & 0 deletions structure/init-3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include<iostream>
#include<string.h>
using namespace std;
struct student{
int roll;
char name[30];
float fees;
char grade;
char std[10];
};

int main()
{

student s;
// initialise structure variable
cin>>s.roll;
cin>>s.name;
cin>>s.fees;
cin>>s.grade;

cout<<s.roll<<endl;
cout<<s.name<<endl;
return 0;
}
27 changes: 27 additions & 0 deletions structure/initial-5.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include<iostream>
#include<string.h>
using namespace std;
struct student{
int roll;
char name[30];
float fees;
char grade;
char std[10];
};

int main()
{
student s={10,"saurabh sethi",2350.50,'B'};
student r;

//requirement - Initial R using S only
//method -1
r.roll = s.roll;
strcpy(r.name , s.name);
r.fees = s.fees;
r.grade = s.grade;

cout<<r.roll<<endl;
cout<<r.name<<endl;
return 0;
}
25 changes: 25 additions & 0 deletions structure/initial-6.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include<iostream>
#include<string.h>
using namespace std;
struct student{
int roll;
char name[30];
float fees;
char grade;
char std[10];
};

int main()
{
student s={10,"saurabh sethi",2350.50,'B'};
student r;

//requirement - Initial R using S only
//method -1

r=s;

cout<<"copied Roll :"<<r.roll<<endl;
cout<<"copied name : "<<r.name<<endl;
return 0;
}
25 changes: 25 additions & 0 deletions structure/initialize-2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include<iostream>
#include<string.h>
using namespace std;
struct student{
int roll;
char name[30];
float fees;
char grade;
char std[10];
};

int main()
{

student s;
// initialise structure variable
s.roll=10;
strcpy(s.name,"saurabh");
s.fees = 1234.56;
s.grade='A';

cout<<s.roll<<endl;
cout<<s.name<<endl;
return 0;
}
28 changes: 28 additions & 0 deletions structure/nested_structure-1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include<iostream>
using namespace std;
struct address{
char houseNo[10];
char society[20];
char area[20];
char locality[30];
char city[20];
char state[20];
char country[100];
};

struct date{
int day;
int month;
int year;
};
struct student{
int roll;
char name[30];
address add;
date dob;
};
int main(){
student s;

return 0;
}
28 changes: 28 additions & 0 deletions structure/nested_structyre.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include<iostream>
using namespace std;
struct address{
char houseNo[10];
char society[20];
char area[20];
char locality[30];
char city[20];
char state[20];
char country[100];
};

struct date{
int day;
int month;
int year;
};
struct student{
int roll;
char name[30];
address add;
date dob;
};
int main(){
student s;

return 0;
}
Binary file added structure/nested_structyre.exe
Binary file not shown.
21 changes: 21 additions & 0 deletions structure/pass_structure-valid_method.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// structure as a function parameter


#include<iostream>
using namespace std;
struct student{
int roll;
char name[30];
char fname[30];
};
void print_data(student r){
cout<<"\n Roll :"<<r.roll;
cout<<"\n Name :"<<r.name;
cout<<"\n Father Name" <<r.fname;
}

int main(){
student s={10,"Swapnil","R.K. Sharma"};
print_data(s);
return 0;
}
Binary file added structure/pass_structure-valid_method.exe
Binary file not shown.
27 changes: 27 additions & 0 deletions structure/pass_structure.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include<iostream>
using namespace std;
struct student{
int roll;
char name[30];
char fname[30];
char address[100];
char phone[15];
char email[80];
char website[100];
int mark[3];
int total;
char grade;
char std[10];
char session[20];

};
void print_data(int x, char y[],char add[],char ph[]){
cout<<"\n Roll :"<<x;
cout<<"\n Name :"<<y;
}

int main(){
student s={10,"Swapnil"};
print_data(s.roll,s.name);
return 0;
}
Binary file added structure/pass_structure.exe
Binary file not shown.
29 changes: 29 additions & 0 deletions structure/simple_input_output.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include<iostream>
using namespace std;
struct student{
int roll; //10
char name[30]; // anupam gulati
int marks; // 90
char grade; // A
};
int main(){
student s;
cout<<"\n Enter roll no :";
cin>>s.roll;
cout<<"\n Enter name :";
fflush(stdin);
cin.getline(s.name,30);
cout<<"\n Enter marks (100) :";
cin>>s.marks;
cout<<"\n Enter grade :";
cin>>s.grade;

// output phase

cout<<"\n Roll No :"<<s.roll;
cout<<"\n Name :"<<s.name;
cout<<"\n Marks :"<<s.marks;
cout<<"\n Grade :"<<s.grade;

return 0;
}
Loading

0 comments on commit e82997a

Please sign in to comment.