Может ли кто-нибудь помочь мне преобразовать этот C cpde в C++
#include <stdio.h> struct college { int roll,year; char name[50],depart[50],crs[50]; }c[4]; //Number of student int main() { int i,no,year1,roll_no; printf("===========Enter Student's Details==========\n"); for(i=0;i<=3;i++) { printf("\nEnter Roll no %d : ",i+1); scanf("%d",&c[i].roll); printf("\nEnter Name %d : ",i+1); fflush(stdin); scanf("%s",&c[i].name); printf("\nEnter Department %d : ",i+1); fflush(stdin); scanf("%s",&c[i].depart); printf("\nEnter Course %d : ",i+1); fflush(stdin); scanf("%s",&c[i].crs); printf("\nEnter Joining Year %d : ",i+1); scanf("%d",&c[i].year); printf("\n"); } printf("================================================"); printf("\n\n"); printf("\n==============Student Info==============\n"); printf("\n1.Names of all students who joined in a particular year :\n"); printf("\n2.Find data of student by its roll number :\n"); printf("\n\nEnter your choice : "); scanf("%d",&no); switch(no) { case 1: printf("Enter joining year : "); scanf("%d",&year1); printf("\n\n===============List of student who join in %d year=============\n\n",year1); for(i=0;i<=3;i++) { if(c[i].year==year1) { printf("\nRoll no : %d ||Name : %s ||Department : %s ||Course : %s ||Year : %d",c[i].roll,c[i].name,c[i].depart,c[i].crs,c[i].year); } } break; case 2: printf("\nEnter Roll number of student :"); scanf("%d",&roll_no); printf("\n\n===============Student Number : %d =============\n\n",roll_no); for(i=0;i<=3;i++) { if(c[i].roll==roll_no) { printf("\nRoll no : \t%d\nName : \t%s\nDepartment: \t%s\nCourse : \t%s\nYear :\t%d",c[i].roll,c[i].name,c[i].depart,c[i].crs,c[i].year); } } break; default: printf("\nInvalid choice "); } return 0; }
Что я уже пробовал:
#include<iostream> using namespace std; struct student{ char name [15]; int rollno; char department [15]; char course [10]; int year; }; student s; int main(){ int *ptr , p; int year_u, rollno_u; int i; for(i=0;i<4;i++){ cout<<"\nEnter Name: "; cin.getline(name, 15); cout<<"\nEnter Roll no: "; cin>>rollno; cout<<"\nEnter Department: "; cin.getline(department, 15); cout<<"\nEnter Course: "; cin.getline(course, 10); cout<<"\nEnter year: "; cin>>s.year; system("cls"); } int choice; cout<<"\nEnter your choice: "; cin>>choice; switch(choice){ case 1: cout<<"\nEnter year: "; cin>>year_u; system("cls"); for(i=0;i<3;i++){ cout<<"\nStudents in : "<<year_u; cout<<"\n\n Name: "<<name[i]; cout<<"\nRoll No: "<<rollno[i]; cout<<"\nDepartment and Course: "<<department[i]<<" "<<course[i]; } case 2: cout<<"\nEnter a roll no: "; cin>>rollno_u; system("cls"); for(i=0;i<3;i++){ } } }
и меняется, но все равно получает ошибки.....
Mohibur Rashid
Какая ошибка?