将程序从cpp转换为C. [英] Convert the program from cpp to C

查看:184
本文介绍了将程序从cpp转换为C.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 / ** 
*奖学金计算器 - 计算器换新手.c
*
* Sanjay Gidwani
*
*已实施计划根据LPU的奖学金政策2016年
*计算学生奖学金,并将信息存储在一个文件中。
*
** /
#include< iostream>
#include< stdio.h>
#include< conio.h>
#include< string.h>
#include< fstream>
#include< stdlib.h>
using namespace std;

班级学者
{
私人:
字符串名称,父亲;
int lpunest;
浮板;
static long id_no;
int y;
static int j,k;

public:

void in()
{
cout<< endl<< endl<<输入学生详细信息( << j ++<<): - ;
cout<< endl<< endl<<名称: - ;
fflush(stdin);
getline(cin,name);
cout<< endl<<父亲的名字: - ;
getline(cin,father);

cout<< endl<<LPUNEST MARKS(Out of 360): - ;
cin>> lpunest;

if(lpunest> 360 || lpunest< 0)// lpunest的无效条件
{
cout<< endl<<你的商标无效他们赢了不计算;
cout<< endl<<你想继续吗?<< endl<<(按1或2);
cout<< endl<<< endl<<1.YES<< endl<<2.NO<< endl<< endl;
int x2;
cin>> x2;
if(x2!= 1&& x2!= 2)
{
cout<< endl<<无效选择;
cout<< endl<<请按1或2<< endl;
int x100;
cin>> x100;
if(x100 == 1)
x2 = 1;
else if(x100 == 2)
x2 = 2;
else退出(0);
}
if(x2 == 2)
{
cout<< endl<<谢谢!;
退出(0);
}
else if(x2 == 1)
{
cout<< endl<<你的LPUNEST标记不计算<< endl;
}
}

cout<< endl<<第12个标记(百分比): - ;
cin>> board;

if(board> 100 || board< 0)//第12块板的无效条件
{
cout<< endl<< endl<<你的第12块董事会标记无效;
cout<< endl<<抱歉!你不能再进一步;
退出(0);
}

cout<< endl<< endl<<你在任何运动中都打过国家并获得过任何奖章吗?; //体育奖学金详情
cout<< endl<<(按1或2);
cout<< endl<< endl<<1。YES<< endl<<2。NO<< endl<< endl;
int x5;
cin>> x5;
if(x5!= 1&& x5!= 2)
{
cout<< endl<<无效选择;
cout<< endl<<请按1或2<< endl;
int x300;
cin>> x300;
if(x300 == 1)
x5 = 1;
else if(x300 == 2)
x5 = 2;
else退出(0);
}
if(x5 == 1)
{
cout<< endl<<你的运动名称;
cout<< endl<<(请输入运动的有效名称,否则将无法计算): - ;
char a [30];
cin>> a;
cout<< endl<<你收到了哪枚奖章?<< endl<< endl;
cout<<1。GOLD<< endl<<2. SILVER<< endl<<3。BRONZE<< endl<< endl;
cin>> y;
if(y!= 1&& y!= 2&& y!= 3)
cout<< endl<<Invalid Choice;
}
否则if(x5 == 2)
{
y = 20;
}

cout<< endl<< endl<<您的信息被记录下来。请等待!;

if(board< 40)//失败条件
{
cout<< endl<< endl<<你的第12个标准失败了;
cout<< endl<<抱歉!你今年不能参加LPU的录取;
cout<< endl<<尝试下一年;
退出(0);
}

if(board< 65)//不符合b-tech条件
{
cout<< endl<< endl<<你在第12个标准中被传递;
cout<< endl<<但你的百分比不足以在B.Tech获得录取;
cout<< endl<<抱歉!你今年不能参加LPU的录取;
cout<< endl<<尝试下一年;
退出(0);
}
}

void out()
{
cout<< endl<< endl<<你的奖学金详情: - << ENDL<< ENDL;

int x7; //测试条件为lpunest
if(lpunest> -1&& lpunest< 361)
{
if(lpunest> 99&& lpunest< 201)
{
x7 = 30000;
cout<<恭喜!你是最优秀的20%-30%候选人之一。
cout<< endl<<基于LPUNEST的奖学金: - << x7<</ - Per Sem;
}
else if(lpunest> 200&& lpunest< 301)
{
x7 = 40000;
cout<<恭喜!你们是排名前10%-20%的候选人之一;
cout<< endl<<基于LPUNEST的奖学金: - << x7<</ - Per Sem;
}
else if(lpunest> 300&& lpunest< 361)
{
x7 = 50000;
cout<<祝贺你们!你们是排名前10%的候选人之一;
cout<< endl<<基于LPUNEST的奖学金: - << x7<</ - Per Sem;
}
else if(lpunest> -1&& lpunest< 100)
{
x7 = 0;
cout<< endl<<基于LPUNEST的奖学金: - N.A<< endl<<(对于少于100的商标没有奖学金);
}
}其他x7 = 0;

int x8; //第12块板的测试条件
if(板> 64&& board< 101)
{
if(x7 == 50000)
{
x8 = 0;
cout<< endl<<奖学金基于第12届董事会成绩: - N.A;
cout<< endl<<(你已经获得最高奖学金);
}
否则if(x7 == 40000)
{
if(board> 89)
{
x8 = 10000;
cout<< endl<<基于第12个委员会标记的奖学金: - << x8<</ - Per Sem;
}
else if(board> 69&& board< 90)
{
x8 = 5000;
cout<< endl<<基于第12个委员会标记的奖学金: - << x8<</ - Per Sem;
}
else if(board> 64&& board< 70)
{
x8 = 0;
cout<< endl<<基于第12个委员会标记的奖学金: - N.A<< endl<<(没有奖学金的百分比小于70);
}
}
否则if(x7 == 30000)
{
if(board> 89)
{
x8 = 10000;
cout<< endl<<基于第12个委员会标记的奖学金: - << x8<</ - Per Sem;
}
else if(board> 69&& board< 90)
{
x8 = 5000;
cout<< endl<<基于第12个委员会标记的奖学金: - << x8<</ - Per Sem;
}
else if(board> 64&& board< 70)
{
x8 = 0;
cout<< endl<<基于第12个委员会标记的奖学金: - N.A<< endl<<(没有奖学金的百分比小于70);
}
}
否则if(x7 == 0)
{
if(board> 89)
{
x8 = 30000;
cout<< endl<<基于第12个委员会标记的奖学金: - << x8<</ - Per Sem;
}
else if(board> 79&& board< 90)
{
x8 = 25000;
cout<< endl<<基于第12个委员会标记的奖学金: - << x8<</ - Per Sem;
}
else if(board> 69&& board< 80)
{
x8 = 20000;
cout<< endl<<基于第12个委员会标记的奖学金: - << x8<</ - Per Sem;
}
else if(board> 64&& board< 70)
{
x8 = 0;
cout<< endl<<基于第12个委员会标记的奖学金: - N.A<< endl<<(没有奖学金的百分比小于70);
}
}
}

int x9; //体育奖学金的测试条件
if(y == 1 || y == 2 || y == 3)
{
if(y == 1)
{
x9 = 84500;
cout<< endl<< endl<<祝贺你们!你们将获得100%的学费奖学金;
cout<< endl<<以体育奖学金为基础,因为你是金牌得主;
}
否则if(y == 2)
{
x9 = 42250;
cout<< endl<< endl<<祝贺你!你将获得50%的学费奖学金;
cout<< endl<<以体育奖学金为基础,因为你是银牌得主;
}
否则if(y == 3)
{
x9 = 21125;
cout<< endl<< endl<<祝贺你!你将获得25%的学费奖学金;
cout<< endl<<基于体育奖学金,因为你是铜奖得主;
}
}
其他x9 = 0;

int x55; //总奖学金计算
if(y == 1 || y == 2 || y == 3)
{
cout<< endl<< endl<< 1.学术奖学金总数: - << x7 + x8<</ - Per Sem;
cout<< endl<<2.总体育奖学金: - << x9<</ - Per Sem<< endl<< endl;

if((x7 + x8)> x9)
{
cout<<你将获得学术奖学金: - <<(x55 = x7 + x8)<</ - Per Sem;
}
其他cout<<你将获得体育奖学金: - <<(x55 = x9)<</ Per Sem;
}
其他cout<< endl<< endl<<总奖学金: - <<(x55 = x7 + x8)<</ - Per Sem;

cout<< endl<< endl<<请等待!您将收到一份文件,其中您将获得有关费用的所有信息;
cout<< endl<<谢谢!;

fstream f10; //文件中的奖学金详情
f10.open(Scholarship Details.cpp,ios :: out | ios :: app);
f10<<学生奖学金详情(<< k ++<<): - ;
f10<<< endl<<名称: - << name;
f10<< endl<<父亲的名字: - << father;
f10<<< endl<<ID号: - << id_no ++;
f10<< endl<<LPUNEST MARKS: - <<< lpunest<</ 360;
f10<< endl<<12th Board Marks: - << board<<%;
f10<< endl<< endl<<学术总奖学金: - << x7 + x8<</ - Per Sem;
f10<< endl<<体育奖学金: - << x9<</ - Per Sem;
f10<< endl<< endl<<(条款: - 将考虑学术或体育的最高奖学金);
f10<< endl<< endl<<您的B.Tech(CSE)的费用结构是: - ;
f10<< endl<<学费: - 84,500 / - 每学期;
f10<< endl<<考试费用: - 3,000 / - 每年;
f10<< endl<<洗衣费: - 2,950 / - 每年;
f10<< endl<<Mess Fee: - 26,000 / - Yearly;
f10<< endl<<旅馆费用(每年): - <<< endl<< endl;
f10<<4 Seater: - 43,500 / - << endl<<3 Seater: - 53,500 / - << endl<<2 Seater: - 63,500 / - <<< endl<<1座位: - 73,500 / - ;
f10<< endl<< endl<<总奖学金: - << x55<</ - Per Sem;
f10<< endl<< endl<<剩余学费: - <<< 84500-x55<</ - Per Sem<<< endl<< endl<< ; ENDL;
f10.close();
}
};

long scholar :: id_no = 2016001;
int scholar :: j = 1;
int scholar :: k = 1;

int main()
{
cout<<\\\\\\\\\\\\\\\\\\\\ //欢迎屏幕
cout<< endl<< endl<< endl;
cout<<\t \\\\\\\
cout<< endl<< endl<< endl;

cout<<你可以得到以下信息: - ; //操作
cout<< endl<< endl<<1。费用结构<< endl<<2。FreshMen的奖学金计算<< endl<< endl ;

int x;
cout<<请输入您的选择(按1或2): - ;
cin>> x;

if(x == 1 || x == 2)
{
if(x == 1)//文件中的费用结构详细信息
{
fstream f1;
f1.open(Fee Structure.cpp,ios :: out);

f1<<您的B.Tech(CSE)费用结构是: - ;
f1<< endl<<学费: - 84,500 / - 每学期;
f1<< endl<<考试费用: - 3,000 / - 每年;
f1<< endl<<洗衣费: - 2,950 / - 每年;
f1<< endl<<Mess Fee: - 26,000 / - Yearly;
f1<< endl<<旅馆费用(每年): - <<< endl<< endl;
f1<<4 Seater: - 43,500 / - << endl<<3 Seater: - 53,500 / - << endl<<2 Seater: - 63,500 / - <<< endl<<1座位: - 73,500 / - ;
f1.close();

cout<< endl<< endl<<您的B.Tech(CSE)的费用结构是: - ; //控制台上的详细信息
cout<< endl<<学费: - 84,500 / - 每学期;
cout<< endl<<考试费用: - 3,000 / - 每年;
cout<< endl<<洗衣费: - 2,950 / - 每年;
cout<< endl<<Mess Fee: - 26,000 / - Yearly;
cout<< endl<<旅馆费用(每年): - <<< endl<< endl;
cout<<4 Seater: - 43,500 / - << endl<<3 Seater: - 53,500 / - << endl<<2 Seater: - 63,500 / - <<< endl<<1座位: - 73,500 / - ;
cout<< endl<< endl<<您将收到有关您的参考费用的文件<< endl<< endl<<谢谢!;
}

否则如果(x == 2)
{
cout<< endl<< endl<<欢迎来到FreshMen的奖学金计算 ;
cout<< endl<< endl<<计算有多少学生的奖学金?<< endl<<(请输入学生人数)\t;

int n,i;
cin>> n;
scholar * s1;
s1 =新学者[n]; //类的对象
for(i = 0; i< n; i ++)
{
(s1 + i) - > in();
(s1 + i) - > out();
}
}
}
其他cout<< endl<< endl<<无效选择;
getch();
返回0;
}





我的尝试:



i尝试了很多将这个程序从cpp转换为c它没有运行ic

解决方案

基本上,不要。

你发现C ++代码几乎可以完成你的家庭作业所需要的东西,你认为只需要一个简单的翻译就可以获得一些东西。

它不会:C ++是(如顾名思义)C的超集,该代码使用的功能根本不在C中。试图将该代码转换为C将最终得到真正非常糟糕的代码!这有点像购买法拉利并削减车身工作,焊接一系列巨大的箱子,更换车轮并将其用作货车。



坐下下来,考虑一下这个问题,编写自己的代码进行提交。您甚至可以学习如何生成代码...


这是丑陋的 C ++ 代码。将它翻译成难看的 C 代码应该相对容易:将 cvariables放在 struct 然后用接受指向这样的 struct 的指针的函数替换公共方法。

使用字符数组而不是std :: string实例和 CI / O 函数而不是 C ++ 流。还有什么?



当然还有另一种方法:了解写一个更好的 C 实现的逻辑。

/**
 * scholarship-calculator-for-freshmen.cpp                                                     
 *                                                              
 * Sanjay Gidwani
 *                                                              
 * Implemented a program that calculates the scholarship of a student according 
 * to the LPU's scholarship policy 2016, and stores the information in a file.
 *
 **/
#include<iostream>
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<fstream>
#include<stdlib.h>
using namespace std;

class scholar
{
	private:	
	string name,father;
        int lpunest;
	float board;
	static long id_no;
	int y;
	static int j,k;
	
	public:
		
		void in()
		{
			cout<<endl<<endl<<"Enter Details For Student("<<j++<<") :-";
			cout<<endl<<endl<<"NAME:-";
			fflush(stdin);
			getline(cin,name);
			cout<<endl<<"FATHER'S NAME:-";
			getline(cin,father);
			
		        cout<<endl<<"LPUNEST MARKS (Out Of 360):-";
			cin>>lpunest;
			
			if(lpunest>360||lpunest<0)  // invalid condition for lpunest
			{
				cout<<endl<<"Your Marks Are Not Valid They Won't Be Counted";
				cout<<endl<<"Do You Want To Proceed?"<<endl<<"(Press 1 Or 2)";
				cout<<endl<<endl<<"1.YES"<<endl<<"2.NO"<<endl<<endl;
				int x2;
				cin>>x2;
				if(x2!=1&&x2!=2)
				{
					cout<<endl<<"Invalid Choice";
					cout<<endl<<"Please Press 1 Or 2"<<endl;
					int x100;
					cin>>x100;
					if(x100==1)
					x2=1;
					else if(x100==2)
					x2=2;
					else exit(0);
				}
				if(x2==2)
				{
				cout<<endl<<"Thank You!";
				exit(0);
				}
				else if(x2==1)
				{
					cout<<endl<<"Your LPUNEST Marks Are not Going To Count"<<endl;
				}
			}
			
			cout<<endl<<"12th BOARD MARKS (In Percentage):-";
			cin>>board;
			
			if(board>100||board<0)  // invalid condition for 12th board
			{
				cout<<endl<<endl<<"Your 12th Board Marks Are Invalid";
				cout<<endl<<"SORRY! You Can't Procceed Further";
				exit(0);
			}
			
			cout<<endl<<endl<<"Have You Played National In Any Sport And Received Any Medal?"; // sports scholarship details
			cout<<endl<<"(Press 1 Or 2)";
			cout<<endl<<endl<<"1. YES"<<endl<<"2. NO"<<endl<<endl;
			int x5;
			cin>>x5;
				if(x5!=1&&x5!=2)
				{
					cout<<endl<<"Invalid Choice";
					cout<<endl<<"Please Press 1 Or 2"<<endl;
					int x300;
					cin>>x300;
					if(x300==1)
					x5=1;
					else if(x300==2)
					x5=2;
					else exit(0);
				}
			if(x5==1)
			{
				cout<<endl<<"Name Of Your Sport";
				cout<<endl<<"(Please Enter Valid Name Of The Sport Otherwise It Won't Be Counted):-";
				char a[30];
				cin>>a;
				cout<<endl<<"Which Medal Have You Received?"<<endl<<endl;
				cout<<"1. GOLD"<<endl<<"2. SILVER"<<endl<<"3. BRONZE"<<endl<<endl;
				cin>>y;
				if(y!=1&&y!=2&&y!=3)
				cout<<endl<<"Invalid Choice";
			}
			else if(x5==2)
			{
				y=20;
			}
			
			cout<<endl<<endl<<"Your Information Is Recorded. Please Wait!";
			
			if(board<40)  // fail condition
			{
				cout<<endl<<endl<<"You Are Failed In Your 12th Standard";
				cout<<endl<<"SORRY! You Can't Take Admission In LPU This Year";
				cout<<endl<<"Try Next Year";
				exit(0);
			}
			
			if(board<65)  // not eligible for b-tech condition
			{
				cout<<endl<<endl<<"You Are Passed In Your 12th Standard";
				cout<<endl<<"But Your Percentage Are Not Sufficient To Take Admission In B.Tech";
				cout<<endl<<"SORRY! You Can't Take Admission In LPU This Year";
				cout<<endl<<"Try Next Year";
				exit(0);
			}
		}
		
		void out()
		{
			cout<<endl<<endl<<"Your SCHOLARSHIP Details:-"<<endl<<endl;
			
			int x7; // test condition for lpunest
			if(lpunest>-1&&lpunest<361)
			{ 
				if(lpunest>99&&lpunest<201)
				{
					x7=30000;
					cout<<"CONGRATULATIONS! You Are Among Top 20%-30% Candidates Who Gave LPUNEST";
					cout<<endl<<"Scholarship Based On LPUNEST:-"<<x7<<"/- Per Sem";
				}
				else if(lpunest>200&&lpunest<301)
				{
					x7=40000;
					cout<<"CONGRATULUTIONS! You Are Among Top 10%-20% Candidates Who Gave LPUNEST";
					cout<<endl<<"Scholarship Based On LPUNEST:-"<<x7<<"/- Per Sem";
				}
				else if(lpunest>300&&lpunest<361)
				{
					x7=50000;
					cout<<"CONGRATULATIONS! You Are Among Top 10% Candidates Who Gave LPUNEST";
					cout<<endl<<"Scholarship Based On LPUNEST:-"<<x7<<"/- Per Sem";
				}
				else if(lpunest>-1&&lpunest<100)
				{
					x7=0;
				        cout<<endl<<"Scholarship Based On LPUNEST:- N.A"<<endl<<"(No Scholarship For Marks Less Than 100)";
		  	        }
			} else x7=0;
			
			  int x8; // test condition for 12th board
			  if(board>64&&board<101)
			  {
			  	if(x7==50000)
			  	{
			  		x8=0;
			  		cout<<endl<<"Scholarship Based On 12th Board Marks:- N.A";
			  		cout<<endl<<"(You Have Maximum Scholarship Already)";
				}
				else if(x7==40000)
			        {
					if(board>89)
					{
                                           x8=10000;
				           cout<<endl<<"Scholarship Based On 12th Board Marks:-"<<x8<<"/- Per Sem";
					}
					else if(board>69&&board<90)
					{
					   x8=5000;
					   cout<<endl<<"Scholarship Based On 12th Board Marks:-"<<x8<<"/- Per Sem";
				        }
					else if(board>64&&board<70) 
				        {
					   x8=0;
				           cout<<endl<<"Scholarship Based On 12th Board Marks:- N.A"<<endl<<"(No Scholarship For Percentage Less Than 70)";
					}
				}
				else if(x7==30000)
				{
					if(board>89)
					{
                                           x8=10000;
					   cout<<endl<<"Scholarship Based On 12th Board Marks:-"<<x8<<"/- Per Sem";
					}
					else if(board>69&&board<90)
					{
					   x8=5000;
					   cout<<endl<<"Scholarship Based On 12th Board Marks:-"<<x8<<"/- Per Sem";
				        }
					else if(board>64&&board<70) 
					{
					   x8=0;
				           cout<<endl<<"Scholarship Based On 12th Board Marks:- N.A"<<endl<<"(No Scholarship For Percentage Less Than 70)";
					}
				}
				else if(x7==0)
				{
				        if(board>89)
				        {
                                           x8=30000;
					   cout<<endl<<"Scholarship Based On 12th Board Marks:-"<<x8<<"/- Per Sem";
					}
					else if(board>79&&board<90)
					{
					   x8=25000;
					   cout<<endl<<"Scholarship Based On 12th Board Marks:-"<<x8<<"/- Per Sem";
				        }
				        else if(board>69&&board<80)
					{
					   x8=20000;
					   cout<<endl<<"Scholarship Based On 12th Board Marks:-"<<x8<<"/- Per Sem";
					}
					else if(board>64&&board<70) 
					{
					   x8=0;
				           cout<<endl<<"Scholarship Based On 12th Board Marks:- N.A"<<endl<<"(No Scholarship For Percentage Less Than 70)";
					}
				}
				}
				
				int x9; // test condition for sports scholarship
				if (y==1||y==2||y==3)
				{
					if(y==1)
					{
						x9=84500;
						cout<<endl<<endl<<"CONGRATULATION! You Are Going To Get 100% Scholarship On Tuition Fee"; 
						cout<<endl<<"On The Basis Of Sports Scholarship As You Are Gold Medalist";
					}
					else if(y==2)
					{
						x9=42250;
						cout<<endl<<endl<<"CONGRATULATION! You Are Going To Get 50% Scholarship On Tuition Fee";
						cout<<endl<<"On The Basis Of Sports Scholarship As You Are Silver Medalist";
					}
					else if(y==3)
					{
						x9=21125;
						cout<<endl<<endl<<"CONGRATULATION! You Are Going To Get 25% Scholarship On Tuition Fee";
						cout<<endl<<"On The Basis Of Sports Scholarship As You Are Bronze Medalist";
					}
				}
				else x9=0;
				
				int x55; // total scholarship calculation
				if(y==1||y==2||y==3)
				{
					cout<<endl<<endl<<"1. Total Academic Scholarship:-"<<x7+x8<<"/- Per Sem";
					cout<<endl<<"2. Total Sports Scholarship:-"<<x9<<"/- Per Sem"<<endl<<endl;
					
					if((x7+x8)>x9)
					{
						cout<<"You Will Get Academic Scholarship:-"<<(x55=x7+x8)<<"/- Per Sem";
					}	
					else cout<<"You Will Get Sports Scholarship:-"<<(x55=x9)<<"/- Per Sem";
				}
				else cout<<endl<<endl<<"Total Scholarship:-"<<(x55=x7+x8)<<"/- Per Sem";
				
				cout<<endl<<endl<<"Please Wait! You Will Receive A File In Which You Will Get All Information About Your Fee";
				cout<<endl<<"Thank You!";
				
			fstream f10; // scholarship details in a file
			f10.open("Scholarship Details.cpp",ios::out|ios::app);
			f10<<"Scholarship Details For Student("<<k++<<") :-";
			f10<<endl<<"Name:-"<<name;
			f10<<endl<<"Father's Name:-"<<father;
			f10<<endl<<"ID Number:-"<<id_no++;
			f10<<endl<<"LPUNEST MARKS:-"<<lpunest<<"/360";
			f10<<endl<<"12th Board Marks:-"<<board<<"%";
			f10<<endl<<endl<<"Total Academic Scholarship:-"<<x7+x8<<"/- Per Sem";
		        f10<<endl<<"Sports Scholarship:-"<<x9<<"/- Per Sem";
			f10<<endl<<endl<<"(TERMS:- Maximum Scholarship Among Academic Or Sports Will Be Considered)";
			f10<<endl<<endl<<"Your Fee Structure For B.Tech (CSE) is:-";
			f10<<endl<<"Tuition Fee:- 84,500/- Per Semester";
			f10<<endl<<"Exam Fee:- 3,000/- Yearly";
			f10<<endl<<"Laundry Fee:- 2,950/- Yearly";
			f10<<endl<<"Mess Fee:- 26,000/- Yearly";
			f10<<endl<<"Hostal Fee (Yearly):-"<<endl<<endl;
			f10<<"4 Seater:- 43,500/-"<<endl<<"3 Seater:- 53,500/-"<<endl<<"2 Seater:- 63,500/-"<<endl<<"1 Seater:- 73,500/-";
			f10<<endl<<endl<<"Total Scholarship:- "<<x55<<"/- Per Sem";
			f10<<endl<<endl<<"Remaining Tuition Fee:- "<<84500-x55<<"/- Per Sem"<<endl<<endl<<endl;
			f10.close();
		}
};

long scholar::id_no=2016001;
int scholar::j=1;
int scholar::k=1;

int main()
{
	cout<<"\t\t\tLOVELY PROFESSIONAL UNIVERSITY";  // welcome screen
	cout<<endl<<endl<<endl;
	cout<<"\t\t\t\tWELCOMES YOU";
	cout<<endl<<endl<<endl;
	
	cout<<"You Can Get The Following Information:-";  // operations
	cout<<endl<<endl<<"1. Fee Structure"<<endl<<"2. Scholarship Calculation For FreshMen"<<endl<<endl;
	
	int x;
	cout<<"Please Enter Your Choice (Press 1 Or 2):-";
	cin>>x;
	
	if(x==1||x==2)
	{
		if(x==1)  // fee structure details in a file
		{ 
		        fstream f1; 
		        f1.open("Fee Structure.cpp",ios::out);
			
			f1<<"Your Fee Structure For B.Tech (CSE) is:-";
			f1<<endl<<"Tuition Fee:- 84,500/- Per Semester";
			f1<<endl<<"Exam Fee:- 3,000/- Yearly";
			f1<<endl<<"Laundry Fee:- 2,950/- Yearly";
			f1<<endl<<"Mess Fee:- 26,000/- Yearly";
			f1<<endl<<"Hostal Fee (Yearly):-"<<endl<<endl;
			f1<<"4 Seater:- 43,500/-"<<endl<<"3 Seater:- 53,500/-"<<endl<<"2 Seater:- 63,500/-"<<endl<<"1 Seater:- 73,500/-";
			f1.close();
			
			cout<<endl<<endl<<"Your Fee Structure For B.Tech (CSE) is:-"; // details on console
			cout<<endl<<"Tuition Fee:- 84,500/- Per Semester";
			cout<<endl<<"Exam Fee:- 3,000/- Yearly";
			cout<<endl<<"Laundry Fee:- 2,950/- Yearly";
			cout<<endl<<"Mess Fee:- 26,000/- Yearly";
			cout<<endl<<"Hostal Fee (Yearly):-"<<endl<<endl;
			cout<<"4 Seater:- 43,500/-"<<endl<<"3 Seater:- 53,500/-"<<endl<<"2 Seater:- 63,500/-"<<endl<<"1 Seater:- 73,500/-";
			cout<<endl<<endl<<"You Will Receive A FILE Regarding Your Fees For Your Reference"<<endl<<endl<<"THANK YOU!";
		}
		
		else if(x==2)
		{
			cout<<endl<<endl<<"Welcome To Scholarship Calculation For FreshMen";
			cout<<endl<<endl<<"Calculate Scholarship For How Many Students ?"<<endl<<"(Please Enter Number Of Students)\t";
			
			int n,i;
			cin>>n;
			scholar *s1;
			s1=new scholar[n];  // object of a class
			for(i=0;i<n;i++)
			{
				(s1+i)->in();
				(s1+i)->out();
			}
		}
}
else cout<<endl<<endl<<"Invalid Choice";
getch();
return 0;
}



What I have tried:

i tried a lot to convert this program from cpp to c it is not running i c

解决方案

Basically, don't.
You have found C++ code which does pretty much what your homework wants, and you think that just a simple translation will get you something to hand in.
It won't: C++ is (as the name suggests) a super-set of C, and that code uses features which aren't in C at all. Trying to convert that code to C will end up with really, really bad code! It's a bit like buying a Ferrari and cutting the body work off, welding on a series of huge boxes, changing the wheels and using it as a goods train.

Sit down, think about the question, and write your own code to submit. You might even learn something about how to produce code...


That is ugly C++ code. It should be relatively easy to translate it to ugly C code: Put the class cvariables in a struct and then replace the public methods with functions accepting a pointer to such a struct.
Use array of characters instead of std::string instance and C I/O function instead of C++ streams. What else?

There is an alternative, of course: understand the logic an write a better C implementation.


这篇关于将程序从cpp转换为C.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆